{"id":7063,"date":"2026-09-11T13:41:40","date_gmt":"2026-09-11T18:41:40","guid":{"rendered":"https:\/\/ykim.synology.me\/wordpress\/weighted-soft-voting-7063\/"},"modified":"2026-09-11T15:37:08","modified_gmt":"2026-09-11T20:37:08","slug":"weighted-soft-voting","status":"publish","type":"post","link":"https:\/\/ykim.synology.me\/wordpress\/weighted-soft-voting-7063\/","title":{"rendered":"Single Predicted Value From Two Models"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/github.com\/yBarn1\/Images\/blob\/main\/beverages\/smartwater-1l-bottles-shelf-brightened.jpg?raw=true\" alt=\"\" style=\"width:auto;height:500px\"\/><\/figure>\n\n\n<style>.kt-tabs-id7063_eeec18-00 > .kt-tabs-content-wrap > .wp-block-kadence-tab{border-top:3px solid #0a6689;border-right:0px solid #0a6689;border-bottom:0px solid #0a6689;border-left:0px solid #0a6689;border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:0px;padding-top:var(--global-kb-spacing-sm, 1.5rem);padding-right:var(--global-kb-spacing-sm, 1.5rem);padding-bottom:var(--global-kb-spacing-sm, 1.5rem);padding-left:var(--global-kb-spacing-sm, 1.5rem);background:var(--global-palette9, #ffffff);}.wp-block-kadence-tabs .kt-tabs-id7063_eeec18-00 > .kt-tabs-title-list li{margin-top:0px;margin-right:8px;margin-bottom:0px;margin-left:0px;}.wp-block-kadence-tabs .kt-tabs-id7063_eeec18-00 > .kt-tabs-title-list li:last-child{margin-right:0px;}.wp-block-kadence-tabs .kt-tabs-id7063_eeec18-00 > .kt-tabs-title-list li .kt-tab-title, .wp-block-kadence-tabs .kt-tabs-id7063_eeec18-00 > .kt-tabs-content-wrap > .kt-tabs-accordion-title .kt-tab-title{line-height:1.4em;font-weight:regular;font-style:normal;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;border-left-width:0px;border-top-left-radius:4px;border-top-right-radius:4px;border-bottom-right-radius:0px;border-bottom-left-radius:0px;padding-top:8px;padding-right:20px;padding-bottom:8px;padding-left:20px;border-color:var(--global-palette7, #eeeeee);color:var(--global-palette4, #2D3748);background:var(--global-palette7, #eeeeee);}.wp-block-kadence-tabs .kt-tabs-id7063_eeec18-00 > .kt-tabs-content-wrap > .kt-tabs-accordion-title .kt-tab-title{margin-top:0px;margin-right:8px;margin-bottom:0px;margin-left:0px;}.wp-block-kadence-tabs .kt-tabs-id7063_eeec18-00 > .kt-tabs-title-list li .kt-tab-title:hover, .wp-block-kadence-tabs .kt-tabs-id7063_eeec18-00 > .kt-tabs-content-wrap > .kt-tabs-accordion-title .kt-tab-title:hover{border-color:var(--global-palette7, #eeeeee);color:var(--global-palette3, #1A202C);background:var(--global-palette8, #F7FAFC);}.wp-block-kadence-tabs .kt-tabs-id7063_eeec18-00 > .kt-tabs-title-list li.kt-tab-title-active .kt-tab-title, .wp-block-kadence-tabs .kt-tabs-id7063_eeec18-00 > .kt-tabs-content-wrap > .kt-tabs-accordion-title.kt-tab-title-active .kt-tab-title{border-color:var(--global-palette7, #eeeeee);color:#ffffff;background:#0a6689;}@media all and (max-width: 1024px){.kt-tabs-id7063_eeec18-00 > .kt-tabs-content-wrap > .wp-block-kadence-tab{border-top:3px solid #0a6689;border-right:0px solid #0a6689;border-bottom:0px solid #0a6689;border-left:0px solid #0a6689;}}@media all and (max-width: 767px){.kt-tabs-id7063_eeec18-00 > .kt-tabs-content-wrap > .wp-block-kadence-tab{border-top:3px solid #0a6689;border-right:0px solid #0a6689;border-bottom:0px solid #0a6689;border-left:0px solid #0a6689;}}<\/style>\n<div class=\"wp-block-kadence-tabs alignnone\"><div class=\"kt-tabs-wrap kt-tabs-id7063_eeec18-00 kt-tabs-has-2-tabs kt-active-tab-2 kt-tabs-layout-tabs kt-tabs-tablet-layout-inherit kt-tabs-mobile-layout-inherit kt-tab-alignment-left \"><ul class=\"kt-tabs-title-list\"><li id=\"tab-english\" class=\"kt-title-item kt-title-item-1 kt-tabs-svg-show-always kt-tabs-icon-side-right kt-tab-title-inactive\"><a href=\"#tab-english\" data-tab=\"1\" class=\"kt-tab-title kt-tab-title-1 \"><span class=\"kt-title-text\">English<\/span><\/a><\/li><li id=\"tab-korean\" class=\"kt-title-item kt-title-item-2 kt-tabs-svg-show-always kt-tabs-icon-side-right kt-tab-title-active\"><a href=\"#tab-korean\" data-tab=\"2\" class=\"kt-tab-title kt-tab-title-2 \"><span class=\"kt-title-text\">Korean<\/span><\/a><\/li><\/ul><div class=\"kt-tabs-content-wrap\">\n<div class=\"wp-block-kadence-tab kt-tab-inner-content kt-inner-tab-1 kt-inner-tab7063_b4dc3a-2d\"><div class=\"kt-tab-inner-content-inner\"><p><div class=\"github-readme-container markdown-body\"><div id=\"file\" class=\"md\" data-path=\"Models\/Hybrid\/Single-Predicted-Value\/single-predicted-value.md\"><article class=\"markdown-body entry-content container-lg\" itemprop=\"text\"><div class=\"markdown-heading\" dir=\"auto\"><h1 class=\"heading-element\" dir=\"auto\">Single Predicted Value From Two Models<\/h1><a id=\"user-content-single-predicted-value-from-two-models\" class=\"anchor\" aria-label=\"Permalink: Single Predicted Value From Two Models\" href=\"#single-predicted-value-from-two-models\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">Version 31 | Created: 2026-09-11 | Updated: 2026-11-07 13:46 UTC<\/p>\n<ul dir=\"auto\">\n<li><a href=\"#1-purpose\">1. Purpose<\/a><\/li>\n<li><a href=\"#2-summary\">2. Summary<\/a><\/li>\n<li><a href=\"#3-principle\">3. Principle<\/a>\n<ul dir=\"auto\">\n<li><a href=\"#31-weighted-soft-voting\">3.1 Weighted Soft Voting<\/a><\/li>\n<li><a href=\"#32-multi-class-extension\">3.2 Multi-Class Extension<\/a><\/li>\n<li><a href=\"#33-single-predicted-value\">3.3 Single Predicted Value<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#4-optimal-weight-search\">4. Optimal Weight Search<\/a>\n<ul dir=\"auto\">\n<li><a href=\"#41-grid-search\">4.1 Grid Search<\/a><\/li>\n<li><a href=\"#42-metric-selection\">4.2 Metric Selection<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#5-cautions\">5. Cautions<\/a><\/li>\n<li><a href=\"#6-further-work\">6. Further Work<\/a><\/li>\n<li><a href=\"#references\">References<\/a><\/li>\n<li><a href=\"#appendix-a-terminology\">Appendix A. Terminology<\/a><\/li>\n<li><a href=\"#appendix-b-python-implementation\">Appendix B. Python Implementation<\/a>\n<ul dir=\"auto\">\n<li><a href=\"#b1-single-predicted-value\">B.1 Single Predicted Value<\/a><\/li>\n<li><a href=\"#b2-optimal-weight-search\">B.2 Optimal Weight Search<\/a><\/li>\n<li><a href=\"#b3-execution-example\">B.3 Execution Example<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">1. Purpose<\/h2><a id=\"user-content-1-purpose\" class=\"anchor\" aria-label=\"Permalink: 1. Purpose\" href=\"#1-purpose\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<ul dir=\"auto\">\n<li><strong>Problem Statement<\/strong>: No simple way to combine the predictions computed by several models into one.<\/li>\n<li><strong>Goal<\/strong>: A single prediction that accounts for both probabilities, where two models each emit a prediction and a probability.<\/li>\n<li><strong>Non-Goal<\/strong>: Fitting and improving the models themselves.<\/li>\n<\/ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">2. Summary<\/h2><a id=\"user-content-2-summary\" class=\"anchor\" aria-label=\"Permalink: 2. Summary\" href=\"#2-summary\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">The single prediction comes from the two probabilities: <code>y_pred<\/code> is read off their weighted average, and a predicted value of any other kind is the two values averaged with those same probabilities as weights. Where both models T and S provide predicted probabilities (<math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"2cf19ae0c1184267acaf37f172ddcf71\">$p_T$<\/math-renderer>, <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"2cf19ae0c1184267acaf37f172ddcf71\">$p_S$<\/math-renderer>), soft voting, a weighted average of the probabilities that reflects the confidence of each model precisely, is the most effective method. The weight w comes from a grid search on a validation dataset (section 4.1) rather than from a guess, and the value found is carried unchanged into the weighted sum on the test dataset.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">3. Principle<\/h2><a id=\"user-content-3-principle\" class=\"anchor\" aria-label=\"Permalink: 3. Principle\" href=\"#3-principle\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">3.1 Weighted Soft Voting<\/h3><a id=\"user-content-31-weighted-soft-voting\" class=\"anchor\" aria-label=\"Permalink: 3.1 Weighted Soft Voting\" href=\"#31-weighted-soft-voting\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">A weight w (<math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"2cf19ae0c1184267acaf37f172ddcf71\">$0 \\le w \\le 1$<\/math-renderer>) applied to the probabilities <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"2cf19ae0c1184267acaf37f172ddcf71\">$p_T$<\/math-renderer> and <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"2cf19ae0c1184267acaf37f172ddcf71\">$p_S$<\/math-renderer> of the two models gives the hybrid probability <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"2cf19ae0c1184267acaf37f172ddcf71\">$p_{\\mathrm{hybrid}}$<\/math-renderer>.<\/p>\n<math-renderer class=\"js-display-math\" style=\"display: block\" data-run-id=\"2cf19ae0c1184267acaf37f172ddcf71\">$$p_{\\mathrm{hybrid}} = w \\cdot p_T + (1 - w) \\cdot p_S \\hspace{19em} (1)$$<\/math-renderer>\n<p dir=\"auto\">The prediction <code>y_pred<\/code> of a binary classification is decided at the threshold 0.5.<\/p>\n<math-renderer class=\"js-display-math\" style=\"display: block\" data-run-id=\"2cf19ae0c1184267acaf37f172ddcf71\">$$y_{\\mathrm{pred}} =\n\\begin{cases}\n1 &amp; \\mathrm{if}\\ p_{\\mathrm{hybrid}} \\ge 0.5 \\\\\\\n0 &amp; \\mathrm{otherwise}\n\\end{cases}\n\\hspace{15em} (2)$$<\/math-renderer>\n<p dir=\"auto\">Each model's own predicted value takes no part in this: <code>y_pred<\/code> is read off <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"2cf19ae0c1184267acaf37f172ddcf71\">$p_{\\mathrm{hybrid}}$<\/math-renderer>, and the share a model holds in it is what the weight w sets. Section 3.3 is the rule for the predicted values themselves.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">3.2 Multi-Class Extension<\/h3><a id=\"user-content-32-multi-class-extension\" class=\"anchor\" aria-label=\"Permalink: 3.2 Multi-Class Extension\" href=\"#32-multi-class-extension\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">In a multi-class classification with three or more classes, the per-class probability vectors <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"2cf19ae0c1184267acaf37f172ddcf71\">$p_T$<\/math-renderer> and <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"2cf19ae0c1184267acaf37f172ddcf71\">$p_S$<\/math-renderer> are summed with the weight, and <code>y_pred<\/code> is the class holding the highest probability.<\/p>\n<math-renderer class=\"js-display-math\" style=\"display: block\" data-run-id=\"2cf19ae0c1184267acaf37f172ddcf71\">$$\\mathbf{p}_{\\mathrm{hybrid}} = w \\cdot \\mathbf{p}_T + (1 - w) \\cdot \\mathbf{p}_S \\hspace{19em} (3)$$<\/math-renderer>\n<math-renderer class=\"js-display-math\" style=\"display: block\" data-run-id=\"2cf19ae0c1184267acaf37f172ddcf71\">$$y_{\\mathrm{pred}} = \\arg\\max \\left( \\mathbf{p}_{\\mathrm{hybrid}} \\right) \\hspace{19em} (4)$$<\/math-renderer>\n<p dir=\"auto\">Both inputs are arrays of shape (<code>N_samples<\/code>, <code>N_classes<\/code>).<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">3.3 Single Predicted Value<\/h3><a id=\"user-content-33-single-predicted-value\" class=\"anchor\" aria-label=\"Permalink: 3.3 Single Predicted Value\" href=\"#33-single-predicted-value\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">Where each model emits a predicted value of its own, the single value is the two values averaged with the probabilities as weights, so the model surer of its answer pulls the result toward it.<\/p>\n<math-renderer class=\"js-display-math\" style=\"display: block\" data-run-id=\"2cf19ae0c1184267acaf37f172ddcf71\">$$v_{\\mathrm{hybrid}} = \\frac{w \\cdot p_T \\cdot v_T + (1 - w) \\cdot p_S \\cdot v_S}{w \\cdot p_T + (1 - w) \\cdot p_S} \\hspace{15em} (5)$$<\/math-renderer>\n<p dir=\"auto\">The denominator is the hybrid probability of equation (1), so the weighted soft voting of section 3.1 is what carries the two values here as well. The implementation is <a href=\"#b1-single-predicted-value\">Appendix B.1<\/a>. It checks that both probabilities lie within 0~1 before weighing them, and it raises on a row where both are zero instead of returning a number.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">4. Optimal Weight Search<\/h2><a id=\"user-content-4-optimal-weight-search\" class=\"anchor\" aria-label=\"Permalink: 4. Optimal Weight Search\" href=\"#4-optimal-weight-search\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">Rather than fixing w arbitrarily, a search (grid search) for the w that raises a performance metric (R-squared, ROC-AUC, F1-score and the like) the most on the validation dataset is recommended.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">4.1 Grid Search<\/h3><a id=\"user-content-41-grid-search\" class=\"anchor\" aria-label=\"Permalink: 4.1 Grid Search\" href=\"#41-grid-search\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">A grid search finds the optimal weight w on the validation dataset against a metric the user defines, such as R-squared, MAPE, F1-score, ROC-AUC or log loss. The metric is a callable taking (<code>y_true<\/code>, <code>y_score<\/code>), so <code>roc_auc_score<\/code> and the like are passed as they are, while <code>f1_score<\/code> and <code>accuracy_score<\/code> need the threshold first and arrive wrapped in <code>ThresholdMetric<\/code>. <code>higher_is_better<\/code> gives the direction, and passing the predicted value of each model, <code>v_T<\/code> and <code>v_S<\/code>, makes the metric score the single predicted value instead of the probability. The search runs from 0.0 to 1.0, at a step whose default of 0.01 covers 100 intervals. The return is the optimal weight <code>best_w<\/code> to give model T and the metric score at that weight, the weight of model S being <code>1 - best_w<\/code>. The search function is <a href=\"#b2-optimal-weight-search\">Appendix B.2<\/a>, and the run on synthetic data is <a href=\"#b3-execution-example\">Appendix B.3<\/a>.<\/p>\n<p dir=\"auto\">The optimal <code>best_w<\/code> found on the validation data is carried unchanged into the weighted sum on the test dataset for the final evaluation.<\/p>\n<math-renderer class=\"js-display-math\" style=\"display: block\" data-run-id=\"2cf19ae0c1184267acaf37f172ddcf71\">$$p_{\\mathrm{hybrid,test}} = w_{\\mathrm{best}} \\cdot p_{T,\\mathrm{test}} + (1 - w_{\\mathrm{best}}) \\cdot p_{S,\\mathrm{test}} \\hspace{19em} (6)$$<\/math-renderer>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">4.2 Metric Selection<\/h3><a id=\"user-content-42-metric-selection\" class=\"anchor\" aria-label=\"Permalink: 4.2 Metric Selection\" href=\"#42-metric-selection\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">Metrics divide on what they hold against <code>y_true<\/code>. R-squared and MAPE score the single predicted value of equation (5) and are the ones that aim at the deliverable directly; <code>F1-Score<\/code> and <code>Accuracy<\/code> score <code>y_pred<\/code>, the class the <code>threshold<\/code> produces, so the weight they choose moves <code>y_pred<\/code>; <code>ROC-AUC<\/code> and <code>Log Loss<\/code> score the hybrid probability itself and leave the chosen value alone.<\/p>\n<p dir=\"auto\">Table 1. Metrics for the weight search<\/p>\n<markdown-accessiblity-table><table>\n<thead>\n<tr>\n<th>#<\/th>\n<th>Metric<\/th>\n<th>Direction<\/th>\n<th>Threshold<\/th>\n<th>Compared with y_true<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td><code>r2_score<\/code><\/td>\n<td>Higher is better<\/td>\n<td>Not used<\/td>\n<td><code>v_hybrid<\/code> of equation (5)<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td><code>mean_absolute_percentage_error<\/code><\/td>\n<td>Lower is better<\/td>\n<td>Not used<\/td>\n<td><code>v_hybrid<\/code> of equation (5)<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td><code>ThresholdMetric(f1_score)<\/code><\/td>\n<td>Higher is better<\/td>\n<td>Used<\/td>\n<td><code>y_pred<\/code>, the class from the threshold<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td><code>ThresholdMetric(accuracy_score)<\/code><\/td>\n<td>Higher is better<\/td>\n<td>Used<\/td>\n<td><code>y_pred<\/code>, the class from the threshold<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td><code>roc_auc_score<\/code><\/td>\n<td>Higher is better<\/td>\n<td>Not used<\/td>\n<td><code>p_hybrid<\/code> of equation (1)<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td><code>log_loss<\/code><\/td>\n<td>Lower is better<\/td>\n<td>Not used<\/td>\n<td><code>p_hybrid<\/code> of equation (1)<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/markdown-accessiblity-table>\n<div class=\"markdown-heading\" dir=\"auto\"><h4 class=\"heading-element\" dir=\"auto\"><code>r2_score<\/code><\/h4><a id=\"user-content-r2_score\" class=\"anchor\" aria-label=\"Permalink: r2_score\" href=\"#r2_score\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">Scores <code>v_hybrid<\/code> of equation (5) against <code>y_true<\/code>, which is the deliverable of this document.<\/p>\n<ul dir=\"auto\">\n<li>Strength: aims at the value the reader takes away; no threshold to fix; the same rule serves a continuous value and a class.<\/li>\n<li>Weakness: needs <code>v_T<\/code> and <code>v_S<\/code>; undefined on a row where both probabilities are zero, since that is the denominator of equation (5); squares its errors, so one wild row can decide w.<\/li>\n<\/ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h4 class=\"heading-element\" dir=\"auto\"><code>mean_absolute_percentage_error<\/code><\/h4><a id=\"user-content-mean_absolute_percentage_error\" class=\"anchor\" aria-label=\"Permalink: mean_absolute_percentage_error\" href=\"#mean_absolute_percentage_error\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">Scores <code>v_hybrid<\/code> of equation (5) against <code>y_true<\/code>, as the mean of the absolute errors divided by the true value.<\/p>\n<ul dir=\"auto\">\n<li>Strength: reads as a percentage, so a result stays comparable across targets of different units and sizes; a row with a large true value cannot dominate it.<\/li>\n<li>Weakness: a true value at or near zero sends it to infinity; it punishes an overshoot harder than an undershoot of the same size.<\/li>\n<\/ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h4 class=\"heading-element\" dir=\"auto\"><code>ThresholdMetric(f1_score)<\/code><\/h4><a id=\"user-content-thresholdmetricf1_score\" class=\"anchor\" aria-label=\"Permalink: ThresholdMetric(f1_score)\" href=\"#thresholdmetricf1_score\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">Scores <code>y_pred<\/code>, the class the <code>threshold<\/code> produces, as the harmonic mean of precision and recall on the positive class.<\/p>\n<ul dir=\"auto\">\n<li>Strength: shows the positive class under an imbalanced label, where a majority guess cannot hide; reads as one number at the operating point actually shipped.<\/li>\n<li>Weakness: tied to the threshold held by <code>ThresholdMetric<\/code>, so a new threshold makes the chosen w stale; the negative class enters only through the errors it causes.<\/li>\n<\/ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h4 class=\"heading-element\" dir=\"auto\"><code>ThresholdMetric(accuracy_score)<\/code><\/h4><a id=\"user-content-thresholdmetricaccuracy_score\" class=\"anchor\" aria-label=\"Permalink: ThresholdMetric(accuracy_score)\" href=\"#thresholdmetricaccuracy_score\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">Scores <code>y_pred<\/code>, the class the <code>threshold<\/code> produces, as the fraction of rows it gets right.<\/p>\n<ul dir=\"auto\">\n<li>Strength: the plainest reading of the result, and it counts both classes on the same footing.<\/li>\n<li>Weakness: an imbalanced label lifts it on the majority class alone; tied to the threshold in the same way <code>f1_score<\/code> is.<\/li>\n<\/ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h4 class=\"heading-element\" dir=\"auto\"><code>roc_auc_score<\/code><\/h4><a id=\"user-content-roc_auc_score\" class=\"anchor\" aria-label=\"Permalink: roc_auc_score\" href=\"#roc_auc_score\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">Scores <code>p_hybrid<\/code> of equation (1) as the ranking it induces, over every threshold at once.<\/p>\n<ul dir=\"auto\">\n<li>Strength: no threshold to fix, so it serves a search run before the operating point is chosen; steady under an imbalanced label.<\/li>\n<li>Weakness: unchanged by any monotone rescaling of the probability, so a badly calibrated model passes it; the single predicted value is not what it measures.<\/li>\n<\/ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h4 class=\"heading-element\" dir=\"auto\"><code>log_loss<\/code><\/h4><a id=\"user-content-log_loss\" class=\"anchor\" aria-label=\"Permalink: log_loss\" href=\"#log_loss\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">Scores <code>p_hybrid<\/code> of equation (1) against <code>y_true<\/code>, penalizing the probability by how far it sits from the label.<\/p>\n<ul dir=\"auto\">\n<li>Strength: the only metric here that grades the scale of the probability, so it exposes the calibration section 5 warns about.<\/li>\n<li>Weakness: a confident mistake costs it enormously, so one row can decide w; a probability at 0 or 1 sends it to infinity unless it is clipped.<\/li>\n<\/ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">5. Cautions<\/h2><a id=\"user-content-5-cautions\" class=\"anchor\" aria-label=\"Permalink: 5. Cautions\" href=\"#5-cautions\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">The probability distributions of the two models have to be checked for a fine match. Where one model is too confident (for example, mostly near 0.05 or 0.95) and the other is cautious (for example, between 0.4 and 0.6), a plain weighted combination can give the confident model too much influence.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">6. Further Work<\/h2><a id=\"user-content-6-further-work\" class=\"anchor\" aria-label=\"Permalink: 6. Further Work\" href=\"#6-further-work\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<ul dir=\"auto\">\n<li><strong>Applying probability calibration<\/strong>\n<ul dir=\"auto\">\n<li>What: calibration through <code>IsotonicRegression<\/code> or <code>Platt Scaling<\/code>, applied to both probabilities before the weighted sum.<\/li>\n<li>Why now: under the condition of section 5, one model confident and the other cautious, a weight alone does not correct the imbalance in influence.<\/li>\n<li>What is needed: data for the calibration, and a comparison of the optimal w and the metric scores before and after it.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">References<\/h2><a id=\"user-content-references\" class=\"anchor\" aria-label=\"Permalink: References\" href=\"#references\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">N\/A \u2014 no external source is cited.<\/p>\n<hr>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">Appendix A. Terminology<\/h2><a id=\"user-content-appendix-a-terminology\" class=\"anchor\" aria-label=\"Permalink: Appendix A. Terminology\" href=\"#appendix-a-terminology\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<ul dir=\"auto\">\n<li><strong>Grid Search<\/strong>: A search that sweeps a fixed interval at a fixed step to find the optimal value.<\/li>\n<li><strong>Isotonic Regression<\/strong>: A calibration method fitting predicted probabilities to the observed frequency under a monotone increasing constraint.<\/li>\n<li><strong>Log Loss<\/strong>: A metric of the disagreement between the predicted probability and the label. Lower is better.<\/li>\n<li><strong>MAPE<\/strong>: Mean absolute percentage error, the mean of the absolute errors divided by the true value. Lower is better.<\/li>\n<li><strong>Platt Scaling<\/strong>: A calibration method passing a model output through a logistic function to put it on a probability scale.<\/li>\n<li><strong>Probability Calibration<\/strong>: The procedure of matching the probabilities a model emits to the observed frequency.<\/li>\n<li><strong>R-squared<\/strong>: A metric of how much of the variance of the true value the prediction accounts for. Higher is better.<\/li>\n<li><strong>ROC-AUC<\/strong>: A metric summarizing classification performance over every threshold.<\/li>\n<li><strong>Soft Voting<\/strong>: A combination that averages the predicted probabilities of the models with weights to decide the final class.<\/li>\n<li><strong>Threshold<\/strong>: The classification threshold that turns a probability into a final class.<\/li>\n<li><strong>ThresholdMetric<\/strong>: A callable holding a class metric and the threshold it needs, so that it scores a probability like the metrics that take one directly.<\/li>\n<\/ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">Appendix B. Python Implementation<\/h2><a id=\"user-content-appendix-b-python-implementation\" class=\"anchor\" aria-label=\"Permalink: Appendix B. Python Implementation\" href=\"#appendix-b-python-implementation\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">B.1 Single Predicted Value<\/h3><a id=\"user-content-b1-single-predicted-value\" class=\"anchor\" aria-label=\"Permalink: B.1 Single Predicted Value\" href=\"#b1-single-predicted-value\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<div class=\"highlight highlight-source-python notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"from typing import Union\n\nimport numpy as np\n\nProbability = Union[float, np.ndarray]\n\n\ndef check_probability(p: Probability) -&gt; np.ndarray:\n    &quot;&quot;&quot;Check that the probability lies within 0~1.\n\n    p: predicted probability of a model\n\n    &gt;&gt;&gt; check_probability(np.array([0.9, 0.5, 0.2]))\n    array([0.9, 0.5, 0.2])\n    &gt;&gt;&gt; check_probability(np.array([0.9, 1.4]))\n    Traceback (most recent call last):\n    ValueError: probability outside 0~1: min=0.9, max=1.4\n    &quot;&quot;&quot;\n    p = np.asarray(p, dtype=float)\n    if p.min() &lt; 0 or p.max() &gt; 1:\n        raise ValueError(f&quot;probability outside 0~1: min={p.min()}, max={p.max()}&quot;)\n    return p\n\n\ndef hybrid_predict_value(v_T: np.ndarray, v_S: np.ndarray, p_T: Probability, p_S: Probability,\n                         w: float = 0.5) -&gt; np.ndarray:\n    &quot;&quot;&quot;\n    v_T: predicted value of model T\n    v_S: predicted value of model S\n    p_T: predicted probability of model T (0~1)\n    p_S: predicted probability of model S (0~1)\n    w: weight given to model T (0~1)\n\n    &gt;&gt;&gt; y_pred_by_t = np.array([10.0, 20.0, 30.0])\n    &gt;&gt;&gt; y_pred_by_s = np.array([12.0, 22.0, 36.0])\n    &gt;&gt;&gt; y_prob_by_t = np.array([0.9, 0.5, 0.2])\n    &gt;&gt;&gt; y_prob_by_s = np.array([0.3, 0.6, 0.9])\n    &gt;&gt;&gt; np.round(hybrid_predict_value(y_pred_by_t, y_pred_by_s, y_prob_by_t, y_prob_by_s, w=0.5), 4)\n    array([10.5   , 21.0909, 34.9091])\n    &gt;&gt;&gt; hybrid_predict_value(y_pred_by_t, y_pred_by_s, np.array([0.0, 0.5, 0.2]), np.array([0.0, 0.6, 0.9]))\n    Traceback (most recent call last):\n    ValueError: both models report zero probability, so the weighted value is undefined.\n    &quot;&quot;&quot;\n    # both probabilities have to be on the 0~1 scale before they are weighed against each other\n    p_T = check_probability(p_T)\n    p_S = check_probability(p_S)\n\n    # confidence each model carries into the combination\n    weight_T = w * p_T\n    weight_S = (1 - w) * p_S\n\n    denominator = weight_T + weight_S\n    if np.any(denominator == 0):\n        raise ValueError(&quot;both models report zero probability, so the weighted value is undefined.&quot;)\n    return (weight_T * v_T + weight_S * v_S) \/ denominator\"><pre><span class=\"pl-k\">from<\/span> <span class=\"pl-s1\">typing<\/span> <span class=\"pl-k\">import<\/span> <span class=\"pl-v\">Union<\/span>\n\n<span class=\"pl-k\">import<\/span> <span class=\"pl-s1\">numpy<\/span> <span class=\"pl-k\">as<\/span> <span class=\"pl-s1\">np<\/span>\n\n<span class=\"pl-v\">Probability<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-v\">Union<\/span>&#91;<span class=\"pl-s1\">float<\/span>, <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>&#93;\n\n\n<span class=\"pl-k\">def<\/span> <span class=\"pl-en\">check_probability<\/span>(<span class=\"pl-s1\">p<\/span>: <span class=\"pl-smi\">Probability<\/span>) <span class=\"pl-c1\">-&gt;<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>:\n    <span class=\"pl-s\">\"\"\"Check that the probability lies within 0~1.<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    p: predicted probability of a model<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; check_probability(np.array(&#91;0.9, 0.5, 0.2&#93;))<\/span>\n<span class=\"pl-s\">    array(&#91;0.9, 0.5, 0.2&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; check_probability(np.array(&#91;0.9, 1.4&#93;))<\/span>\n<span class=\"pl-s\">    Traceback (most recent call last):<\/span>\n<span class=\"pl-s\">    ValueError: probability outside 0~1: min=0.9, max=1.4<\/span>\n<span class=\"pl-s\">    \"\"\"<\/span>\n    <span class=\"pl-s1\">p<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">asarray<\/span>(<span class=\"pl-s1\">p<\/span>, <span class=\"pl-s1\">dtype<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">float<\/span>)\n    <span class=\"pl-k\">if<\/span> <span class=\"pl-s1\">p<\/span>.<span class=\"pl-c1\">min<\/span>() <span class=\"pl-c1\">&lt;<\/span> <span class=\"pl-c1\">0<\/span> <span class=\"pl-c1\">or<\/span> <span class=\"pl-s1\">p<\/span>.<span class=\"pl-c1\">max<\/span>() <span class=\"pl-c1\">&gt;<\/span> <span class=\"pl-c1\">1<\/span>:\n        <span class=\"pl-k\">raise<\/span> <span class=\"pl-en\">ValueError<\/span>(<span class=\"pl-s\">f\"probability outside 0~1: min=<span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">p<\/span>.<span class=\"pl-c1\">min<\/span>()<span class=\"pl-kos\">}<\/span><\/span>, max=<span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">p<\/span>.<span class=\"pl-c1\">max<\/span>()<span class=\"pl-kos\">}<\/span><\/span>\"<\/span>)\n    <span class=\"pl-k\">return<\/span> <span class=\"pl-s1\">p<\/span>\n\n\n<span class=\"pl-k\">def<\/span> <span class=\"pl-en\">hybrid_predict_value<\/span>(<span class=\"pl-s1\">v_T<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>, <span class=\"pl-s1\">v_S<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>, <span class=\"pl-s1\">p_T<\/span>: <span class=\"pl-smi\">Probability<\/span>, <span class=\"pl-s1\">p_S<\/span>: <span class=\"pl-smi\">Probability<\/span>,\n                         <span class=\"pl-s1\">w<\/span>: <span class=\"pl-smi\">float<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">0.5<\/span>) <span class=\"pl-c1\">-&gt;<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>:\n    <span class=\"pl-s\">\"\"\"<\/span>\n<span class=\"pl-s\">    v_T: predicted value of model T<\/span>\n<span class=\"pl-s\">    v_S: predicted value of model S<\/span>\n<span class=\"pl-s\">    p_T: predicted probability of model T (0~1)<\/span>\n<span class=\"pl-s\">    p_S: predicted probability of model S (0~1)<\/span>\n<span class=\"pl-s\">    w: weight given to model T (0~1)<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; y_pred_by_t = np.array(&#91;10.0, 20.0, 30.0&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; y_pred_by_s = np.array(&#91;12.0, 22.0, 36.0&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; y_prob_by_t = np.array(&#91;0.9, 0.5, 0.2&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; y_prob_by_s = np.array(&#91;0.3, 0.6, 0.9&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; np.round(hybrid_predict_value(y_pred_by_t, y_pred_by_s, y_prob_by_t, y_prob_by_s, w=0.5), 4)<\/span>\n<span class=\"pl-s\">    array(&#91;10.5   , 21.0909, 34.9091&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; hybrid_predict_value(y_pred_by_t, y_pred_by_s, np.array(&#91;0.0, 0.5, 0.2&#93;), np.array(&#91;0.0, 0.6, 0.9&#93;))<\/span>\n<span class=\"pl-s\">    Traceback (most recent call last):<\/span>\n<span class=\"pl-s\">    ValueError: both models report zero probability, so the weighted value is undefined.<\/span>\n<span class=\"pl-s\">    \"\"\"<\/span>\n    <span class=\"pl-c\"># both probabilities have to be on the 0~1 scale before they are weighed against each other<\/span>\n    <span class=\"pl-s1\">p_T<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">check_probability<\/span>(<span class=\"pl-s1\">p_T<\/span>)\n    <span class=\"pl-s1\">p_S<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">check_probability<\/span>(<span class=\"pl-s1\">p_S<\/span>)\n\n    <span class=\"pl-c\"># confidence each model carries into the combination<\/span>\n    <span class=\"pl-s1\">weight_T<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">w<\/span> <span class=\"pl-c1\">*<\/span> <span class=\"pl-s1\">p_T<\/span>\n    <span class=\"pl-s1\">weight_S<\/span> <span class=\"pl-c1\">=<\/span> (<span class=\"pl-c1\">1<\/span> <span class=\"pl-c1\">-<\/span> <span class=\"pl-s1\">w<\/span>) <span class=\"pl-c1\">*<\/span> <span class=\"pl-s1\">p_S<\/span>\n\n    <span class=\"pl-s1\">denominator<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">weight_T<\/span> <span class=\"pl-c1\">+<\/span> <span class=\"pl-s1\">weight_S<\/span>\n    <span class=\"pl-k\">if<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">any<\/span>(<span class=\"pl-s1\">denominator<\/span> <span class=\"pl-c1\">==<\/span> <span class=\"pl-c1\">0<\/span>):\n        <span class=\"pl-k\">raise<\/span> <span class=\"pl-en\">ValueError<\/span>(<span class=\"pl-s\">\"both models report zero probability, so the weighted value is undefined.\"<\/span>)\n    <span class=\"pl-k\">return<\/span> (<span class=\"pl-s1\">weight_T<\/span> <span class=\"pl-c1\">*<\/span> <span class=\"pl-s1\">v_T<\/span> <span class=\"pl-c1\">+<\/span> <span class=\"pl-s1\">weight_S<\/span> <span class=\"pl-c1\">*<\/span> <span class=\"pl-s1\">v_S<\/span>) <span class=\"pl-c1\">\/<\/span> <span class=\"pl-s1\">denominator<\/span><\/pre><\/div>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">B.2 Optimal Weight Search<\/h3><a id=\"user-content-b2-optimal-weight-search\" class=\"anchor\" aria-label=\"Permalink: B.2 Optimal Weight Search\" href=\"#b2-optimal-weight-search\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<div class=\"highlight highlight-source-python notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"from typing import Callable\n\nimport numpy as np\nfrom sklearn.metrics import (accuracy_score, f1_score, log_loss, mean_absolute_percentage_error, r2_score,\n                             roc_auc_score)\n\nScore = Callable[[np.ndarray, np.ndarray], float]\n\n\nclass ThresholdMetric:\n    &quot;&quot;&quot;Turn a metric that scores a class into one that scores a probability.\n\n    score_fn: metric taking (y_true, y_pred), such as f1_score or accuracy_score\n    threshold: classification threshold applied before the metric runs\n\n    &gt;&gt;&gt; y_true = np.array([0, 0, 1, 1])\n    &gt;&gt;&gt; p_hybrid = np.array([0.2, 0.6, 0.7, 0.4])\n    &gt;&gt;&gt; metric = ThresholdMetric(f1_score, threshold=0.5)\n    &gt;&gt;&gt; round(float(metric(y_true, p_hybrid)), 4)\n    0.5\n    &quot;&quot;&quot;\n\n    def __init__(self, score_fn: Score, threshold: float = 0.5):\n        self.score_fn = score_fn\n        self.threshold = threshold\n\n    def __call__(self, y_true: np.ndarray, p_hybrid: np.ndarray) -&gt; float:\n        y_pred = (p_hybrid &gt;= self.threshold).astype(int)\n        return self.score_fn(y_true, y_pred)\n\n\ndef find_optimal_weight(y_true: np.ndarray, p_T: np.ndarray, p_S: np.ndarray, metric: Score,\n                        higher_is_better: bool = True, step: float = 0.01,\n                        v_T: np.ndarray = None, v_S: np.ndarray = None) -&gt; tuple[float, float]:\n    &quot;&quot;&quot;Search the weight w of models T and S that suits the validation dataset best, by grid search.\n\n    Parameters:\n    - y_true: true labels (N,)\n    - p_T: predicted probability of model T (N,)\n    - p_S: predicted probability of model S (N,)\n    - metric: callable taking (y_true, y_score), such as roc_auc_score or ThresholdMetric(f1_score)\n    - higher_is_better: direction of the metric, False for log_loss and mean_absolute_percentage_error\n    - step: weight step of the grid search (default: 0.01 -&gt; 100 intervals)\n    - v_T: predicted value of model T (N,), which makes the metric score the single predicted value\n    - v_S: predicted value of model S (N,), given together with v_T\n\n    Returns:\n    - best_w: optimal weight for model T (model S takes 1 - best_w)\n    - best_score: metric score at that weight\n\n    &gt;&gt;&gt; y_true = np.array([0, 0, 1, 1])\n    &gt;&gt;&gt; p_T = np.array([0.2, 0.3, 0.7, 0.8])\n    &gt;&gt;&gt; p_S = np.array([0.6, 0.4, 0.5, 0.3])\n    &gt;&gt;&gt; best_w, best_score = find_optimal_weight(y_true, p_T, p_S, metric=roc_auc_score, step=0.25)\n    &gt;&gt;&gt; float(best_w), round(float(best_score), 4)\n    (0.5, 1.0)\n    &gt;&gt;&gt; best_w, best_score = find_optimal_weight(\n    ...     y_true, p_T, p_S, metric=log_loss, higher_is_better=False, step=0.25\n    ... )\n    &gt;&gt;&gt; float(best_w), round(float(best_score), 4)\n    (1.0, 0.2899)\n    &gt;&gt;&gt; y_value = np.array([10.0, 20.0, 30.0, 40.0])\n    &gt;&gt;&gt; v_T = np.array([11.0, 19.0, 33.0, 37.0])\n    &gt;&gt;&gt; v_S = np.array([14.0, 25.0, 26.0, 44.0])\n    &gt;&gt;&gt; best_w, best_score = find_optimal_weight(\n    ...     y_value, p_T, p_S, metric=r2_score, step=0.25, v_T=v_T, v_S=v_S\n    ... )\n    &gt;&gt;&gt; float(best_w), round(float(best_score), 4)\n    (0.75, 0.9707)\n    &gt;&gt;&gt; best_w, best_score = find_optimal_weight(\n    ...     y_true, p_T, p_S, metric=ThresholdMetric(accuracy_score), step=0.25\n    ... )\n    &gt;&gt;&gt; float(best_w), round(float(best_score), 4)\n    (0.5, 1.0)\n    &quot;&quot;&quot;\n    if not callable(metric):\n        raise TypeError(f&quot;metric must be callable, not {type(metric).__name__}.&quot;)\n    if (v_T is None) != (v_S is None):\n        raise ValueError(&quot;v_T and v_S are given together or not at all.&quot;)\n\n    weights = np.arange(0.0, 1.0 + step, step)\n    best_w = None\n    best_score = -float(&quot;inf&quot;) if higher_is_better else float(&quot;inf&quot;)\n\n    for w in weights:\n        # weighted average probability\n        p_hybrid = w * p_T + (1 - w) * p_S\n\n        # the metric scores the single predicted value where both models report one\n        if v_T is None:\n            score = metric(y_true, p_hybrid)\n        else:\n            score = metric(y_true, hybrid_predict_value(v_T, v_S, p_T, p_S, w))\n\n        # keep the best so far\n        if higher_is_better:\n            if score &gt; best_score:\n                best_score = score\n                best_w = round(w, 4)\n        else:\n            if score &lt; best_score:\n                best_score = score\n                best_w = round(w, 4)\n\n    return best_w, best_score\"><pre><span class=\"pl-k\">from<\/span> <span class=\"pl-s1\">typing<\/span> <span class=\"pl-k\">import<\/span> <span class=\"pl-v\">Callable<\/span>\n\n<span class=\"pl-k\">import<\/span> <span class=\"pl-s1\">numpy<\/span> <span class=\"pl-k\">as<\/span> <span class=\"pl-s1\">np<\/span>\n<span class=\"pl-k\">from<\/span> <span class=\"pl-s1\">sklearn<\/span>.<span class=\"pl-s1\">metrics<\/span> <span class=\"pl-k\">import<\/span> (<span class=\"pl-s1\">accuracy_score<\/span>, <span class=\"pl-s1\">f1_score<\/span>, <span class=\"pl-s1\">log_loss<\/span>, <span class=\"pl-s1\">mean_absolute_percentage_error<\/span>, <span class=\"pl-s1\">r2_score<\/span>,\n                             <span class=\"pl-s1\">roc_auc_score<\/span>)\n\n<span class=\"pl-v\">Score<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-v\">Callable<\/span>&#91;&#91;<span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>, <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>&#93;, <span class=\"pl-s1\">float<\/span>&#93;\n\n\n<span class=\"pl-k\">class<\/span> <span class=\"pl-v\">ThresholdMetric<\/span>:\n    <span class=\"pl-s\">\"\"\"Turn a metric that scores a class into one that scores a probability.<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    score_fn: metric taking (y_true, y_pred), such as f1_score or accuracy_score<\/span>\n<span class=\"pl-s\">    threshold: classification threshold applied before the metric runs<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; y_true = np.array(&#91;0, 0, 1, 1&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; p_hybrid = np.array(&#91;0.2, 0.6, 0.7, 0.4&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; metric = ThresholdMetric(f1_score, threshold=0.5)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; round(float(metric(y_true, p_hybrid)), 4)<\/span>\n<span class=\"pl-s\">    0.5<\/span>\n<span class=\"pl-s\">    \"\"\"<\/span>\n\n    <span class=\"pl-k\">def<\/span> <span class=\"pl-en\">__init__<\/span>(<span class=\"pl-s1\">self<\/span>, <span class=\"pl-s1\">score_fn<\/span>: <span class=\"pl-smi\">Score<\/span>, <span class=\"pl-s1\">threshold<\/span>: <span class=\"pl-smi\">float<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">0.5<\/span>):\n        <span class=\"pl-s1\">self<\/span>.<span class=\"pl-c1\">score_fn<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">score_fn<\/span>\n        <span class=\"pl-s1\">self<\/span>.<span class=\"pl-c1\">threshold<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">threshold<\/span>\n\n    <span class=\"pl-k\">def<\/span> <span class=\"pl-en\">__call__<\/span>(<span class=\"pl-s1\">self<\/span>, <span class=\"pl-s1\">y_true<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>, <span class=\"pl-s1\">p_hybrid<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>) <span class=\"pl-c1\">-&gt;<\/span> <span class=\"pl-smi\">float<\/span>:\n        <span class=\"pl-s1\">y_pred<\/span> <span class=\"pl-c1\">=<\/span> (<span class=\"pl-s1\">p_hybrid<\/span> <span class=\"pl-c1\">&gt;=<\/span> <span class=\"pl-s1\">self<\/span>.<span class=\"pl-c1\">threshold<\/span>).<span class=\"pl-c1\">astype<\/span>(<span class=\"pl-s1\">int<\/span>)\n        <span class=\"pl-k\">return<\/span> <span class=\"pl-s1\">self<\/span>.<span class=\"pl-c1\">score_fn<\/span>(<span class=\"pl-s1\">y_true<\/span>, <span class=\"pl-s1\">y_pred<\/span>)\n\n\n<span class=\"pl-k\">def<\/span> <span class=\"pl-en\">find_optimal_weight<\/span>(<span class=\"pl-s1\">y_true<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>, <span class=\"pl-s1\">p_T<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>, <span class=\"pl-s1\">p_S<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>, <span class=\"pl-s1\">metric<\/span>: <span class=\"pl-smi\">Score<\/span>,\n                        <span class=\"pl-s1\">higher_is_better<\/span>: <span class=\"pl-smi\">bool<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">True<\/span>, <span class=\"pl-s1\">step<\/span>: <span class=\"pl-smi\">float<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">0.01<\/span>,\n                        <span class=\"pl-s1\">v_T<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">None<\/span>, <span class=\"pl-s1\">v_S<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">None<\/span>) <span class=\"pl-c1\">-&gt;<\/span> <span class=\"pl-s1\">tuple<\/span>&#91;<span class=\"pl-smi\">float<\/span>, <span class=\"pl-smi\">float<\/span>&#93;:\n    <span class=\"pl-s\">\"\"\"Search the weight w of models T and S that suits the validation dataset best, by grid search.<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    Parameters:<\/span>\n<span class=\"pl-s\">    - y_true: true labels (N,)<\/span>\n<span class=\"pl-s\">    - p_T: predicted probability of model T (N,)<\/span>\n<span class=\"pl-s\">    - p_S: predicted probability of model S (N,)<\/span>\n<span class=\"pl-s\">    - metric: callable taking (y_true, y_score), such as roc_auc_score or ThresholdMetric(f1_score)<\/span>\n<span class=\"pl-s\">    - higher_is_better: direction of the metric, False for log_loss and mean_absolute_percentage_error<\/span>\n<span class=\"pl-s\">    - step: weight step of the grid search (default: 0.01 -&gt; 100 intervals)<\/span>\n<span class=\"pl-s\">    - v_T: predicted value of model T (N,), which makes the metric score the single predicted value<\/span>\n<span class=\"pl-s\">    - v_S: predicted value of model S (N,), given together with v_T<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    Returns:<\/span>\n<span class=\"pl-s\">    - best_w: optimal weight for model T (model S takes 1 - best_w)<\/span>\n<span class=\"pl-s\">    - best_score: metric score at that weight<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; y_true = np.array(&#91;0, 0, 1, 1&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; p_T = np.array(&#91;0.2, 0.3, 0.7, 0.8&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; p_S = np.array(&#91;0.6, 0.4, 0.5, 0.3&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; best_w, best_score = find_optimal_weight(y_true, p_T, p_S, metric=roc_auc_score, step=0.25)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; float(best_w), round(float(best_score), 4)<\/span>\n<span class=\"pl-s\">    (0.5, 1.0)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; best_w, best_score = find_optimal_weight(<\/span>\n<span class=\"pl-s\">    ...     y_true, p_T, p_S, metric=log_loss, higher_is_better=False, step=0.25<\/span>\n<span class=\"pl-s\">    ... )<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; float(best_w), round(float(best_score), 4)<\/span>\n<span class=\"pl-s\">    (1.0, 0.2899)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; y_value = np.array(&#91;10.0, 20.0, 30.0, 40.0&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; v_T = np.array(&#91;11.0, 19.0, 33.0, 37.0&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; v_S = np.array(&#91;14.0, 25.0, 26.0, 44.0&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; best_w, best_score = find_optimal_weight(<\/span>\n<span class=\"pl-s\">    ...     y_value, p_T, p_S, metric=r2_score, step=0.25, v_T=v_T, v_S=v_S<\/span>\n<span class=\"pl-s\">    ... )<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; float(best_w), round(float(best_score), 4)<\/span>\n<span class=\"pl-s\">    (0.75, 0.9707)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; best_w, best_score = find_optimal_weight(<\/span>\n<span class=\"pl-s\">    ...     y_true, p_T, p_S, metric=ThresholdMetric(accuracy_score), step=0.25<\/span>\n<span class=\"pl-s\">    ... )<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; float(best_w), round(float(best_score), 4)<\/span>\n<span class=\"pl-s\">    (0.5, 1.0)<\/span>\n<span class=\"pl-s\">    \"\"\"<\/span>\n    <span class=\"pl-k\">if<\/span> <span class=\"pl-c1\">not<\/span> <span class=\"pl-en\">callable<\/span>(<span class=\"pl-s1\">metric<\/span>):\n        <span class=\"pl-k\">raise<\/span> <span class=\"pl-en\">TypeError<\/span>(<span class=\"pl-s\">f\"metric must be callable, not <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-en\">type<\/span>(<span class=\"pl-s1\">metric<\/span>).<span class=\"pl-c1\">__name__<\/span><span class=\"pl-kos\">}<\/span><\/span>.\"<\/span>)\n    <span class=\"pl-k\">if<\/span> (<span class=\"pl-s1\">v_T<\/span> <span class=\"pl-c1\">is<\/span> <span class=\"pl-c1\">None<\/span>) <span class=\"pl-c1\">!=<\/span> (<span class=\"pl-s1\">v_S<\/span> <span class=\"pl-c1\">is<\/span> <span class=\"pl-c1\">None<\/span>):\n        <span class=\"pl-k\">raise<\/span> <span class=\"pl-en\">ValueError<\/span>(<span class=\"pl-s\">\"v_T and v_S are given together or not at all.\"<\/span>)\n\n    <span class=\"pl-s1\">weights<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">arange<\/span>(<span class=\"pl-c1\">0.0<\/span>, <span class=\"pl-c1\">1.0<\/span> <span class=\"pl-c1\">+<\/span> <span class=\"pl-s1\">step<\/span>, <span class=\"pl-s1\">step<\/span>)\n    <span class=\"pl-s1\">best_w<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">None<\/span>\n    <span class=\"pl-s1\">best_score<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">-<\/span><span class=\"pl-en\">float<\/span>(<span class=\"pl-s\">\"inf\"<\/span>) <span class=\"pl-k\">if<\/span> <span class=\"pl-s1\">higher_is_better<\/span> <span class=\"pl-k\">else<\/span> <span class=\"pl-en\">float<\/span>(<span class=\"pl-s\">\"inf\"<\/span>)\n\n    <span class=\"pl-k\">for<\/span> <span class=\"pl-s1\">w<\/span> <span class=\"pl-c1\">in<\/span> <span class=\"pl-s1\">weights<\/span>:\n        <span class=\"pl-c\"># weighted average probability<\/span>\n        <span class=\"pl-s1\">p_hybrid<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">w<\/span> <span class=\"pl-c1\">*<\/span> <span class=\"pl-s1\">p_T<\/span> <span class=\"pl-c1\">+<\/span> (<span class=\"pl-c1\">1<\/span> <span class=\"pl-c1\">-<\/span> <span class=\"pl-s1\">w<\/span>) <span class=\"pl-c1\">*<\/span> <span class=\"pl-s1\">p_S<\/span>\n\n        <span class=\"pl-c\"># the metric scores the single predicted value where both models report one<\/span>\n        <span class=\"pl-k\">if<\/span> <span class=\"pl-s1\">v_T<\/span> <span class=\"pl-c1\">is<\/span> <span class=\"pl-c1\">None<\/span>:\n            <span class=\"pl-s1\">score<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">metric<\/span>(<span class=\"pl-s1\">y_true<\/span>, <span class=\"pl-s1\">p_hybrid<\/span>)\n        <span class=\"pl-k\">else<\/span>:\n            <span class=\"pl-s1\">score<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">metric<\/span>(<span class=\"pl-s1\">y_true<\/span>, <span class=\"pl-en\">hybrid_predict_value<\/span>(<span class=\"pl-s1\">v_T<\/span>, <span class=\"pl-s1\">v_S<\/span>, <span class=\"pl-s1\">p_T<\/span>, <span class=\"pl-s1\">p_S<\/span>, <span class=\"pl-s1\">w<\/span>))\n\n        <span class=\"pl-c\"># keep the best so far<\/span>\n        <span class=\"pl-k\">if<\/span> <span class=\"pl-s1\">higher_is_better<\/span>:\n            <span class=\"pl-k\">if<\/span> <span class=\"pl-s1\">score<\/span> <span class=\"pl-c1\">&gt;<\/span> <span class=\"pl-s1\">best_score<\/span>:\n                <span class=\"pl-s1\">best_score<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">score<\/span>\n                <span class=\"pl-s1\">best_w<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">round<\/span>(<span class=\"pl-s1\">w<\/span>, <span class=\"pl-c1\">4<\/span>)\n        <span class=\"pl-k\">else<\/span>:\n            <span class=\"pl-k\">if<\/span> <span class=\"pl-s1\">score<\/span> <span class=\"pl-c1\">&lt;<\/span> <span class=\"pl-s1\">best_score<\/span>:\n                <span class=\"pl-s1\">best_score<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">score<\/span>\n                <span class=\"pl-s1\">best_w<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">round<\/span>(<span class=\"pl-s1\">w<\/span>, <span class=\"pl-c1\">4<\/span>)\n\n    <span class=\"pl-k\">return<\/span> <span class=\"pl-s1\">best_w<\/span>, <span class=\"pl-s1\">best_score<\/span><\/pre><\/div>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">B.3 Execution Example<\/h3><a id=\"user-content-b3-execution-example\" class=\"anchor\" aria-label=\"Permalink: B.3 Execution Example\" href=\"#b3-execution-example\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<div class=\"highlight highlight-source-python notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"# --- synthetic validation data ---\nnp.random.seed(42)\nN_samples = 1000\n\n# ground truth\ny_true = np.random.randint(0, 2, size=N_samples)\n\n# probability from model T, relatively close to the truth\ny_prob_by_t = y_true * 0.7 + np.random.normal(0, 0.2, size=N_samples)\ny_prob_by_t = np.clip(y_prob_by_t, 0.01, 1)\n\n# probability from model S\ny_prob_by_s = y_true * 0.5 + np.random.normal(0, 0.3, size=N_samples)\ny_prob_by_s = np.clip(y_prob_by_s, 0.01, 1)\n\n# the class each model predicts on its own, at the 0.5 threshold\ny_pred_by_t = (y_prob_by_t &gt;= 0.5).astype(int)\ny_pred_by_s = (y_prob_by_s &gt;= 0.5).astype(int)\n\n# --- the first ten rows of the sample ---\nprint(&quot;y_true     :&quot;, y_true[:10])\nprint(&quot;y_pred_by_t:&quot;, y_pred_by_t[:10])\nprint(&quot;y_pred_by_s:&quot;, y_pred_by_s[:10])\nprint(&quot;y_prob_by_t:&quot;, np.round(y_prob_by_t[:10], 4))\nprint(&quot;y_prob_by_s:&quot;, np.round(y_prob_by_s[:10], 4))\n\n# --- run the grid search ---\n# 1. optimize on F1-score, which needs the threshold the class is read at\nbest_w_f1, best_score_f1 = find_optimal_weight(\n    y_true, y_prob_by_t, y_prob_by_s, metric=ThresholdMetric(f1_score, threshold=0.5)\n)\nprint(f&quot;[F1-Score]  best w: {best_w_f1} | score: {best_score_f1:.4f}&quot;)\n\n# 2. optimize on ROC-AUC\nbest_w_auc, best_score_auc = find_optimal_weight(\n    y_true, y_prob_by_t, y_prob_by_s, metric=roc_auc_score\n)\nprint(f&quot;[ROC-AUC]   best w: {best_w_auc} | score: {best_score_auc:.4f}&quot;)\n\n# 3. optimize on log loss, lower is better\nbest_w_loss, best_score_loss = find_optimal_weight(\n    y_true, y_prob_by_t, y_prob_by_s, metric=log_loss, higher_is_better=False\n)\nprint(f&quot;[Log Loss]  best w: {best_w_loss} | score: {best_score_loss:.4f}&quot;)\n\n# 4. optimize on R-squared, which scores the single predicted value itself\nbest_w_r2, best_score_r2 = find_optimal_weight(\n    y_true, y_prob_by_t, y_prob_by_s, metric=r2_score,\n    v_T=y_pred_by_t, v_S=y_pred_by_s\n)\nprint(f&quot;[R-squared] best w: {best_w_r2} | score: {best_score_r2:.4f}&quot;)\n\n# 5. optimize on MAPE, which scores the same value on a percentage scale\nbest_w_mape, best_score_mape = find_optimal_weight(\n    y_true, y_prob_by_t, y_prob_by_s, metric=mean_absolute_percentage_error,\n    higher_is_better=False, v_T=y_pred_by_t, v_S=y_pred_by_s\n)\nprint(f&quot;[MAPE]      best w: {best_w_mape} | score: {best_score_mape:.4f}&quot;)\n\n# --- the single predicted value at the weight R-squared chose ---\nv_hybrid = hybrid_predict_value(\n    y_pred_by_t, y_pred_by_s, y_prob_by_t, y_prob_by_s, w=best_w_r2\n)\nprint(&quot;v_hybrid   :&quot;, np.round(v_hybrid[:10], 4))\"><pre><span class=\"pl-c\"># --- synthetic validation data ---<\/span>\n<span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">random<\/span>.<span class=\"pl-c1\">seed<\/span>(<span class=\"pl-c1\">42<\/span>)\n<span class=\"pl-v\">N_samples<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">1000<\/span>\n\n<span class=\"pl-c\"># ground truth<\/span>\n<span class=\"pl-s1\">y_true<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">random<\/span>.<span class=\"pl-c1\">randint<\/span>(<span class=\"pl-c1\">0<\/span>, <span class=\"pl-c1\">2<\/span>, <span class=\"pl-s1\">size<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-v\">N_samples<\/span>)\n\n<span class=\"pl-c\"># probability from model T, relatively close to the truth<\/span>\n<span class=\"pl-s1\">y_prob_by_t<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">y_true<\/span> <span class=\"pl-c1\">*<\/span> <span class=\"pl-c1\">0.7<\/span> <span class=\"pl-c1\">+<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">random<\/span>.<span class=\"pl-c1\">normal<\/span>(<span class=\"pl-c1\">0<\/span>, <span class=\"pl-c1\">0.2<\/span>, <span class=\"pl-s1\">size<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-v\">N_samples<\/span>)\n<span class=\"pl-s1\">y_prob_by_t<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">clip<\/span>(<span class=\"pl-s1\">y_prob_by_t<\/span>, <span class=\"pl-c1\">0.01<\/span>, <span class=\"pl-c1\">1<\/span>)\n\n<span class=\"pl-c\"># probability from model S<\/span>\n<span class=\"pl-s1\">y_prob_by_s<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">y_true<\/span> <span class=\"pl-c1\">*<\/span> <span class=\"pl-c1\">0.5<\/span> <span class=\"pl-c1\">+<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">random<\/span>.<span class=\"pl-c1\">normal<\/span>(<span class=\"pl-c1\">0<\/span>, <span class=\"pl-c1\">0.3<\/span>, <span class=\"pl-s1\">size<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-v\">N_samples<\/span>)\n<span class=\"pl-s1\">y_prob_by_s<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">clip<\/span>(<span class=\"pl-s1\">y_prob_by_s<\/span>, <span class=\"pl-c1\">0.01<\/span>, <span class=\"pl-c1\">1<\/span>)\n\n<span class=\"pl-c\"># the class each model predicts on its own, at the 0.5 threshold<\/span>\n<span class=\"pl-s1\">y_pred_by_t<\/span> <span class=\"pl-c1\">=<\/span> (<span class=\"pl-s1\">y_prob_by_t<\/span> <span class=\"pl-c1\">&gt;=<\/span> <span class=\"pl-c1\">0.5<\/span>).<span class=\"pl-c1\">astype<\/span>(<span class=\"pl-s1\">int<\/span>)\n<span class=\"pl-s1\">y_pred_by_s<\/span> <span class=\"pl-c1\">=<\/span> (<span class=\"pl-s1\">y_prob_by_s<\/span> <span class=\"pl-c1\">&gt;=<\/span> <span class=\"pl-c1\">0.5<\/span>).<span class=\"pl-c1\">astype<\/span>(<span class=\"pl-s1\">int<\/span>)\n\n<span class=\"pl-c\"># --- the first ten rows of the sample ---<\/span>\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">\"y_true     :\"<\/span>, <span class=\"pl-s1\">y_true<\/span>&#91;:<span class=\"pl-c1\">10<\/span>&#93;)\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">\"y_pred_by_t:\"<\/span>, <span class=\"pl-s1\">y_pred_by_t<\/span>&#91;:<span class=\"pl-c1\">10<\/span>&#93;)\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">\"y_pred_by_s:\"<\/span>, <span class=\"pl-s1\">y_pred_by_s<\/span>&#91;:<span class=\"pl-c1\">10<\/span>&#93;)\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">\"y_prob_by_t:\"<\/span>, <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">round<\/span>(<span class=\"pl-s1\">y_prob_by_t<\/span>&#91;:<span class=\"pl-c1\">10<\/span>&#93;, <span class=\"pl-c1\">4<\/span>))\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">\"y_prob_by_s:\"<\/span>, <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">round<\/span>(<span class=\"pl-s1\">y_prob_by_s<\/span>&#91;:<span class=\"pl-c1\">10<\/span>&#93;, <span class=\"pl-c1\">4<\/span>))\n\n<span class=\"pl-c\"># --- run the grid search ---<\/span>\n<span class=\"pl-c\"># 1. optimize on F1-score, which needs the threshold the class is read at<\/span>\n<span class=\"pl-s1\">best_w_f1<\/span>, <span class=\"pl-s1\">best_score_f1<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">find_optimal_weight<\/span>(\n    <span class=\"pl-s1\">y_true<\/span>, <span class=\"pl-s1\">y_prob_by_t<\/span>, <span class=\"pl-s1\">y_prob_by_s<\/span>, <span class=\"pl-s1\">metric<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-en\">ThresholdMetric<\/span>(<span class=\"pl-s1\">f1_score<\/span>, <span class=\"pl-s1\">threshold<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-c1\">0.5<\/span>)\n)\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">f\"&#91;F1-Score&#93;  best w: <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">best_w_f1<\/span><span class=\"pl-kos\">}<\/span><\/span> | score: <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">best_score_f1<\/span>:.4f<span class=\"pl-kos\">}<\/span><\/span>\"<\/span>)\n\n<span class=\"pl-c\"># 2. optimize on ROC-AUC<\/span>\n<span class=\"pl-s1\">best_w_auc<\/span>, <span class=\"pl-s1\">best_score_auc<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">find_optimal_weight<\/span>(\n    <span class=\"pl-s1\">y_true<\/span>, <span class=\"pl-s1\">y_prob_by_t<\/span>, <span class=\"pl-s1\">y_prob_by_s<\/span>, <span class=\"pl-s1\">metric<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">roc_auc_score<\/span>\n)\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">f\"&#91;ROC-AUC&#93;   best w: <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">best_w_auc<\/span><span class=\"pl-kos\">}<\/span><\/span> | score: <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">best_score_auc<\/span>:.4f<span class=\"pl-kos\">}<\/span><\/span>\"<\/span>)\n\n<span class=\"pl-c\"># 3. optimize on log loss, lower is better<\/span>\n<span class=\"pl-s1\">best_w_loss<\/span>, <span class=\"pl-s1\">best_score_loss<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">find_optimal_weight<\/span>(\n    <span class=\"pl-s1\">y_true<\/span>, <span class=\"pl-s1\">y_prob_by_t<\/span>, <span class=\"pl-s1\">y_prob_by_s<\/span>, <span class=\"pl-s1\">metric<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">log_loss<\/span>, <span class=\"pl-s1\">higher_is_better<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-c1\">False<\/span>\n)\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">f\"&#91;Log Loss&#93;  best w: <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">best_w_loss<\/span><span class=\"pl-kos\">}<\/span><\/span> | score: <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">best_score_loss<\/span>:.4f<span class=\"pl-kos\">}<\/span><\/span>\"<\/span>)\n\n<span class=\"pl-c\"># 4. optimize on R-squared, which scores the single predicted value itself<\/span>\n<span class=\"pl-s1\">best_w_r2<\/span>, <span class=\"pl-s1\">best_score_r2<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">find_optimal_weight<\/span>(\n    <span class=\"pl-s1\">y_true<\/span>, <span class=\"pl-s1\">y_prob_by_t<\/span>, <span class=\"pl-s1\">y_prob_by_s<\/span>, <span class=\"pl-s1\">metric<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">r2_score<\/span>,\n    <span class=\"pl-s1\">v_T<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">y_pred_by_t<\/span>, <span class=\"pl-s1\">v_S<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">y_pred_by_s<\/span>\n)\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">f\"&#91;R-squared&#93; best w: <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">best_w_r2<\/span><span class=\"pl-kos\">}<\/span><\/span> | score: <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">best_score_r2<\/span>:.4f<span class=\"pl-kos\">}<\/span><\/span>\"<\/span>)\n\n<span class=\"pl-c\"># 5. optimize on MAPE, which scores the same value on a percentage scale<\/span>\n<span class=\"pl-s1\">best_w_mape<\/span>, <span class=\"pl-s1\">best_score_mape<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">find_optimal_weight<\/span>(\n    <span class=\"pl-s1\">y_true<\/span>, <span class=\"pl-s1\">y_prob_by_t<\/span>, <span class=\"pl-s1\">y_prob_by_s<\/span>, <span class=\"pl-s1\">metric<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">mean_absolute_percentage_error<\/span>,\n    <span class=\"pl-s1\">higher_is_better<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-c1\">False<\/span>, <span class=\"pl-s1\">v_T<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">y_pred_by_t<\/span>, <span class=\"pl-s1\">v_S<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">y_pred_by_s<\/span>\n)\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">f\"&#91;MAPE&#93;      best w: <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">best_w_mape<\/span><span class=\"pl-kos\">}<\/span><\/span> | score: <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">best_score_mape<\/span>:.4f<span class=\"pl-kos\">}<\/span><\/span>\"<\/span>)\n\n<span class=\"pl-c\"># --- the single predicted value at the weight R-squared chose ---<\/span>\n<span class=\"pl-s1\">v_hybrid<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">hybrid_predict_value<\/span>(\n    <span class=\"pl-s1\">y_pred_by_t<\/span>, <span class=\"pl-s1\">y_pred_by_s<\/span>, <span class=\"pl-s1\">y_prob_by_t<\/span>, <span class=\"pl-s1\">y_prob_by_s<\/span>, <span class=\"pl-s1\">w<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">best_w_r2<\/span>\n)\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">\"v_hybrid   :\"<\/span>, <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">round<\/span>(<span class=\"pl-s1\">v_hybrid<\/span>&#91;:<span class=\"pl-c1\">10<\/span>&#93;, <span class=\"pl-c1\">4<\/span>))<\/pre><\/div>\n<p dir=\"auto\">The five arrays printed first are the head of the sample, ten rows of it, the five lines after them are the search result, and the last line is the single predicted value at the weight R-squared chose. The MAPE score runs to 1e13 because <code>y_true<\/code> is 0 on most rows and the metric divides by it, the weakness section 4.2 names.<\/p>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"y_true     : [0 1 0 0 0 1 0 0 0 1]\ny_pred_by_t: [0 1 0 0 0 1 0 0 0 1]\ny_pred_by_s: [0 1 0 0 0 0 1 0 0 1]\ny_prob_by_t: [0.0684 1.     0.1901 0.01   0.01   0.7984 0.01   0.3663 0.2359 0.6062]\ny_prob_by_s: [0.3905 0.9685 0.01   0.01   0.138  0.2967 0.604  0.041  0.01   0.5554]\n[F1-Score]  best w: 0.78 | score: 0.9174\n[ROC-AUC]   best w: 0.73 | score: 0.9968\n[Log Loss]  best w: 1.0 | score: 0.2542\n[R-squared] best w: 0.7 | score: 0.7127\n[MAPE]      best w: 1.0 | score: 13510798882111.5684\nv_hybrid   : [0.     1.     0.     0.     0.     0.8626 0.9628 0.     0.     1.    ]\"><pre lang=\"text\" class=\"notranslate\"><code>y_true     : &#91;0 1 0 0 0 1 0 0 0 1&#93;\ny_pred_by_t: &#91;0 1 0 0 0 1 0 0 0 1&#93;\ny_pred_by_s: &#91;0 1 0 0 0 0 1 0 0 1&#93;\ny_prob_by_t: &#91;0.0684 1.     0.1901 0.01   0.01   0.7984 0.01   0.3663 0.2359 0.6062&#93;\ny_prob_by_s: &#91;0.3905 0.9685 0.01   0.01   0.138  0.2967 0.604  0.041  0.01   0.5554&#93;\n&#91;F1-Score&#93;  best w: 0.78 | score: 0.9174\n&#91;ROC-AUC&#93;   best w: 0.73 | score: 0.9968\n&#91;Log Loss&#93;  best w: 1.0 | score: 0.2542\n&#91;R-squared&#93; best w: 0.7 | score: 0.7127\n&#91;MAPE&#93;      best w: 1.0 | score: 13510798882111.5684\nv_hybrid   : &#91;0.     1.     0.     0.     0.     0.8626 0.9628 0.     0.     1.    &#93;\n<\/code><\/pre><\/div>\n<\/article><\/div><\/div><\/p>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-kadence-tab kt-tab-inner-content kt-inner-tab-2 kt-inner-tab7063_ad7177-60\"><div class=\"kt-tab-inner-content-inner\"><p><div class=\"github-readme-container markdown-body\"><div id=\"file\" class=\"md\" data-path=\"Models\/Hybrid\/Single-Predicted-Value\/single-predicted-value-ko.md\"><article class=\"markdown-body entry-content container-lg\" itemprop=\"text\"><div class=\"markdown-heading\" dir=\"auto\"><h1 class=\"heading-element\" dir=\"auto\">Single Predicted Value From Two Models<\/h1><a id=\"user-content-single-predicted-value-from-two-models\" class=\"anchor\" aria-label=\"Permalink: Single Predicted Value From Two Models\" href=\"#single-predicted-value-from-two-models\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">Version 32 | Created: 2026-09-11 | Updated: 2026-11-07 13:46 UTC<\/p>\n<ul dir=\"auto\">\n<li><a href=\"#1-purpose\">1. Purpose<\/a><\/li>\n<li><a href=\"#2-summary\">2. Summary<\/a><\/li>\n<li><a href=\"#3-principle\">3. Principle<\/a>\n<ul dir=\"auto\">\n<li><a href=\"#31-weighted-soft-voting\">3.1 Weighted Soft Voting<\/a><\/li>\n<li><a href=\"#32-multi-class-extension\">3.2 Multi-Class Extension<\/a><\/li>\n<li><a href=\"#33-single-predicted-value\">3.3 Single Predicted Value<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#4-optimal-weight-search\">4. Optimal Weight Search<\/a>\n<ul dir=\"auto\">\n<li><a href=\"#41-grid-search\">4.1 Grid Search<\/a><\/li>\n<li><a href=\"#42-metric-selection\">4.2 Metric Selection<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#5-cautions\">5. Cautions<\/a><\/li>\n<li><a href=\"#6-further-work\">6. Further Work<\/a><\/li>\n<li><a href=\"#references\">References<\/a><\/li>\n<li><a href=\"#appendix-a-terminology\">Appendix A. Terminology<\/a><\/li>\n<li><a href=\"#appendix-b-python-implementation\">Appendix B. Python Implementation<\/a>\n<ul dir=\"auto\">\n<li><a href=\"#b1-single-predicted-value\">B.1 Single Predicted Value<\/a><\/li>\n<li><a href=\"#b2-optimal-weight-search\">B.2 Optimal Weight Search<\/a><\/li>\n<li><a href=\"#b3-execution-example\">B.3 Execution Example<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">1. Purpose<\/h2><a id=\"user-content-1-purpose\" class=\"anchor\" aria-label=\"Permalink: 1. Purpose\" href=\"#1-purpose\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<ul dir=\"auto\">\n<li><strong>Problem Statement<\/strong>: \ubcf5\uc218\uc758 \ubaa8\ub378\uc5d0\uc11c \uacc4\uc0b0\ud55c \uc608\uce21\uac12\uc744 \ud558\ub098\ub85c \ud569\uce58\ub294 \uac04\ub2e8\ud55c \ubc29\ubc95\uc774 \uc5c6\ub2e4.<\/li>\n<li><strong>Goal<\/strong>: \ub450 \ubaa8\ub378\uc5d0\uc11c \uac01\uac01 \uc608\uce21 \uac12\uacfc \ud655\ub960\uc744 \ub0b4\ub193\uc744 \ub54c, \ub450 \ud655\ub960\uc744 \uace0\ub824\ud55c \ub2e8\uc77c \uc608\uce21\uac12\uc744 \uc81c\uc2dc\ud558\uace0\uc790 \ud55c\ub2e4.<\/li>\n<li><strong>Non-Goal<\/strong>: \ubaa8\ub378 \uc790\uccb4\uc758 \ud559\uc2b5\uacfc \uac1c\uc120\uc740 \ud558\uc9c0 \uc54a\ub294\ub2e4.<\/li>\n<\/ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">2. Summary<\/h2><a id=\"user-content-2-summary\" class=\"anchor\" aria-label=\"Permalink: 2. Summary\" href=\"#2-summary\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">\ub2e8\uc77c \uc608\uce21\uac12\uc740 \ub450 \ud655\ub960\uc5d0\uc11c \ub098\uc635\ub2c8\ub2e4. <code>y_pred<\/code> \ub294 \ub450 \ud655\ub960\uc758 \uac00\uc911 \ud3c9\uade0\uc5d0\uc11c \ub2e4\uc2dc \uc77d\uc5b4\ub0b4\uace0, \ud074\ub798\uc2a4\uac00 \uc544\ub2cc \uc608\uce21 \uac12\uc740 \uadf8 \ub450 \ud655\ub960\uc744 \uac00\uc911\uce58\ub85c \uc0bc\uc544 \ud3c9\uade0\ud569\ub2c8\ub2e4. \ub450 \ubaa8\ub378 T\uc640 S\uac00 \ubaa8\ub450 \uc608\uce21 \ud655\ub960 (<math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"81b2477d902b542d9f095a2bcc064a72\">$p_T$<\/math-renderer>, <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"81b2477d902b542d9f095a2bcc064a72\">$p_S$<\/math-renderer>) \uc744 \uc81c\uacf5\ud55c\ub2e4\uba74, \uac01 \ubaa8\ub378\uc758 \ud655\uc2e0\ub3c4\ub97c \uc815\ubc00\ud558\uac8c \ubc18\uc601\ud558\ub294 Soft Voting (\ud655\ub960 \uac00\uc911 \ud3c9\uade0) \ubc29\uc2dd\uc744 \uc0ac\uc6a9\ud558\ub294 \uac83\uc774 \uac00\uc7a5 \ud6a8\uacfc\uc801\uc785\ub2c8\ub2e4. \uac00\uc911\uce58 w \ub294 \uc784\uc758\ub85c \uc815\ud558\uc9c0 \uc54a\uace0 validation dataset \uc5d0\uc11c grid search \ub85c \ucc3e\uc73c\uba70 (section 4.1), \ucc3e\uc740 \uac12\uc744 test dataset \uc758 \uac00\uc911\ud569\uc5d0 \uadf8\ub300\ub85c \uc801\uc6a9\ud569\ub2c8\ub2e4.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">3. Principle<\/h2><a id=\"user-content-3-principle\" class=\"anchor\" aria-label=\"Permalink: 3. Principle\" href=\"#3-principle\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">3.1 Weighted Soft Voting<\/h3><a id=\"user-content-31-weighted-soft-voting\" class=\"anchor\" aria-label=\"Permalink: 3.1 Weighted Soft Voting\" href=\"#31-weighted-soft-voting\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">\ub450 \ubaa8\ub378\uc758 \ud655\ub960\uac12 <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"81b2477d902b542d9f095a2bcc064a72\">$p_T$<\/math-renderer> \uacfc <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"81b2477d902b542d9f095a2bcc064a72\">$p_S$<\/math-renderer> \uc5d0 \uac00\uc911\uce58 w (<math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"81b2477d902b542d9f095a2bcc064a72\">$0 \\le w \\le 1$<\/math-renderer>) \ub97c \uc801\uc6a9\ud558\uc5ec \ud558\uc774\ube0c\ub9ac\ub4dc \ud655\ub960 <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"81b2477d902b542d9f095a2bcc064a72\">$p_{\\mathrm{hybrid}}$<\/math-renderer> \ub97c \uacc4\uc0b0\ud569\ub2c8\ub2e4.<\/p>\n<math-renderer class=\"js-display-math\" style=\"display: block\" data-run-id=\"81b2477d902b542d9f095a2bcc064a72\">$$p_{\\mathrm{hybrid}} = w \\cdot p_T + (1 - w) \\cdot p_S \\hspace{19em} (1)$$<\/math-renderer>\n<p dir=\"auto\">\uc774\uc9c4 \ubd84\ub958\uc758 \uc608\uce21\uac12 <code>y_pred<\/code> \ub294 \uc784\uacc4\uac12 0.5 \ub97c \uae30\uc900\uc73c\ub85c \uac08\ub9bd\ub2c8\ub2e4.<\/p>\n<math-renderer class=\"js-display-math\" style=\"display: block\" data-run-id=\"81b2477d902b542d9f095a2bcc064a72\">$$y_{\\mathrm{pred}} =\n\\begin{cases}\n1 &amp; \\mathrm{if}\\ p_{\\mathrm{hybrid}} \\ge 0.5 \\\\\\\n0 &amp; \\mathrm{otherwise}\n\\end{cases}\n\\hspace{15em} (2)$$<\/math-renderer>\n<p dir=\"auto\">\uac01 \ubaa8\ub378\uc774 \ub0b4\ub193\uc740 \uc608\uce21\uac12\uc740 \uc5ec\uae30\uc5d0 \uc4f0\uc774\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4. <code>y_pred<\/code> \ub294 <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"81b2477d902b542d9f095a2bcc064a72\">$p_{\\mathrm{hybrid}}$<\/math-renderer> \uc5d0\uc11c \ub2e4\uc2dc \uc77d\uc5b4\ub0b4\uba70, \uac01 \ubaa8\ub378\uc774 \uadf8 \uc548\uc5d0\uc11c \ucc28\uc9c0\ud558\ub294 \ubaab\uc740 \uac00\uc911\uce58 w \uac00 \uc815\ud569\ub2c8\ub2e4. \uc608\uce21 \uac12 \uc790\uccb4\ub97c \ud569\uce58\ub294 \uaddc\uce59\uc740 \uaf2d\uc9c0 3.3 \uc5d0 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">3.2 Multi-Class Extension<\/h3><a id=\"user-content-32-multi-class-extension\" class=\"anchor\" aria-label=\"Permalink: 3.2 Multi-Class Extension\" href=\"#32-multi-class-extension\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">\ud074\ub798\uc2a4\uac00 3\uac1c \uc774\uc0c1\uc778 \ub2e4\uc911 \ud074\ub798\uc2a4 \ubd84\ub958\uc5d0\uc11c\ub294 \uac01 \ud074\ub798\uc2a4\ubcc4 \ud655\ub960 \ubca1\ud130 <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"81b2477d902b542d9f095a2bcc064a72\">$p_T$<\/math-renderer> \uacfc <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"81b2477d902b542d9f095a2bcc064a72\">$p_S$<\/math-renderer> \ub97c \uac00\uc911\ud569\ud55c \ud6c4 \uac00\uc7a5 \ub192\uc740 \ud655\ub960\uc744 \uac00\uc9c4 \ud074\ub798\uc2a4\ub97c <code>y_pred<\/code> \ub85c \uc0bc\uc2b5\ub2c8\ub2e4.<\/p>\n<math-renderer class=\"js-display-math\" style=\"display: block\" data-run-id=\"81b2477d902b542d9f095a2bcc064a72\">$$\\mathbf{p}_{\\mathrm{hybrid}} = w \\cdot \\mathbf{p}_T + (1 - w) \\cdot \\mathbf{p}_S \\hspace{19em} (3)$$<\/math-renderer>\n<math-renderer class=\"js-display-math\" style=\"display: block\" data-run-id=\"81b2477d902b542d9f095a2bcc064a72\">$$y_{\\mathrm{pred}} = \\arg\\max \\left( \\mathbf{p}_{\\mathrm{hybrid}} \\right) \\hspace{19em} (4)$$<\/math-renderer>\n<p dir=\"auto\">\uc785\ub825 \ub450 \uac1c\ub294 \ubaa8\ub450 (<code>N_samples<\/code>, <code>N_classes<\/code>) \ud615\uc0c1\uc758 \ubc30\uc5f4\uc785\ub2c8\ub2e4.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">3.3 Single Predicted Value<\/h3><a id=\"user-content-33-single-predicted-value\" class=\"anchor\" aria-label=\"Permalink: 3.3 Single Predicted Value\" href=\"#33-single-predicted-value\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">\uac01 \ubaa8\ub378\uc774 \uc608\uce21 \uac12\uc744 \ud568\uaed8 \ub0b4\ub193\ub294 \uacbd\uc6b0, \ub2e8\uc77c \uc608\uce21\uac12\uc740 \ub450 \uac12\uc744 \ud655\ub960\ub85c \uac00\uc911 \ud3c9\uade0\ud55c \uac83\uc785\ub2c8\ub2e4. \uc790\uae30 \ub2f5\uc744 \ub354 \ud655\uc2e0\ud558\ub294 \ubaa8\ub378 \ucabd\uc73c\ub85c \uacb0\uacfc\uac00 \ub04c\ub9bd\ub2c8\ub2e4.<\/p>\n<math-renderer class=\"js-display-math\" style=\"display: block\" data-run-id=\"81b2477d902b542d9f095a2bcc064a72\">$$v_{\\mathrm{hybrid}} = \\frac{w \\cdot p_T \\cdot v_T + (1 - w) \\cdot p_S \\cdot v_S}{w \\cdot p_T + (1 - w) \\cdot p_S} \\hspace{15em} (5)$$<\/math-renderer>\n<p dir=\"auto\">\ubd84\ubaa8\ub294 \uc2dd (1) \uc758 \ud558\uc774\ube0c\ub9ac\ub4dc \ud655\ub960\uc774\ubbc0\ub85c, \uaf2d\uc9c0 3.1 \uc758 Soft Voting \uc774 \uc5ec\uae30\uc11c\ub3c4 \ub450 \uac12\uc744 \uc2e4\uc5b4 \ub098\ub985\ub2c8\ub2e4. \uad6c\ud604\uc740 <a href=\"#b1-single-predicted-value\">Appendix B.1<\/a> \uc785\ub2c8\ub2e4. \uac00\uc911\ud569\uc5d0 \uc55e\uc11c \ub450 \ud655\ub960\uc774 0~1 \uc548\uc5d0 \uc788\ub294\uc9c0 \ud655\uc778\ud558\uba70, \ub450 \ud655\ub960\uc774 \ubaa8\ub450 0 \uc778 \ud589\uc5d0\uc11c\ub294 \uac12\uc744 \ub3cc\ub824\uc8fc\ub294 \ub300\uc2e0 \uc624\ub958\ub97c \ub0c5\ub2c8\ub2e4.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">4. Optimal Weight Search<\/h2><a id=\"user-content-4-optimal-weight-search\" class=\"anchor\" aria-label=\"Permalink: 4. Optimal Weight Search\" href=\"#4-optimal-weight-search\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">w \uac12\uc744 \uc784\uc758\ub85c \uc815\ud558\uae30\ubcf4\ub2e4\ub294, Validation Dataset\uc5d0\uc11c \uc131\ub2a5 \uc9c0\ud45c (R-squared, ROC-AUC, F1-score \ub4f1) \ub97c \uac00\uc7a5 \ub192\uc5ec\uc8fc\ub294 w\ub97c \ud0d0\uc0c9 (Grid Search) \ud558\uc5ec \uc120\uc815\ud558\ub294 \uac83\uc744 \uad8c\uc7a5\ud569\ub2c8\ub2e4.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">4.1 Grid Search<\/h3><a id=\"user-content-41-grid-search\" class=\"anchor\" aria-label=\"Permalink: 4.1 Grid Search\" href=\"#41-grid-search\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">Validation \ub370\uc774\ud130\uc14b\uc5d0\uc11c R-squared, MAPE, F1-score, ROC-AUC, Log-Loss \ub4f1 \uc0ac\uc6a9\uc790\uac00 \uc815\uc758\ud55c \ud3c9\uac00 \uc9c0\ud45c\ub97c \uae30\uc900\uc73c\ub85c \ucd5c\uc801\uc758 \uac00\uc911\uce58 w\ub97c Grid Search\ub85c \ud0d0\uc0c9\ud569\ub2c8\ub2e4. \uc9c0\ud45c\ub294 (<code>y_true<\/code>, <code>y_score<\/code>) \ub97c \ubc1b\ub294 callable \uc774\ubbc0\ub85c <code>roc_auc_score<\/code> \uac19\uc740 \ud568\uc218\ub294 \uadf8\ub300\ub85c \ub118\uae30\uace0, <code>f1_score<\/code> \uc640 <code>accuracy_score<\/code> \ub294 \uc784\uacc4\uac12\uc744 \uba3c\uc800 \ubc1b\uc544\uc57c \ud558\ubbc0\ub85c <code>ThresholdMetric<\/code> \uc5d0 \uc2f8\uc11c \ub118\uae41\ub2c8\ub2e4. \ubc29\ud5a5\uc740 <code>higher_is_better<\/code> \uac00 \uc815\ud558\uace0, \uac01 \ubaa8\ub378\uc758 \uc608\uce21 \uac12 <code>v_T<\/code>, <code>v_S<\/code> \ub97c \ud568\uaed8 \ub118\uae30\uba74 \uc9c0\ud45c\uac00 \ud655\ub960 \ub300\uc2e0 \ub2e8\uc77c \uc608\uce21\uac12\uc744 \ucc44\uc810\ud569\ub2c8\ub2e4. \ud0d0\uc0c9 \uad6c\uac04\uc740 0.0 \uc5d0\uc11c 1.0 \uae4c\uc9c0\uc774\uace0, \uac04\uaca9\uc740 \uae30\ubcf8\uac12 0.01 \ub85c 100\uac1c \uad6c\uac04\uc744 \ud6d1\uc2b5\ub2c8\ub2e4. \ubc18\ud658\uac12\uc740 \ubaa8\ub378 T \uc5d0 \ubd80\uc5ec\ud560 \ucd5c\uc801 \uac00\uc911\uce58 <code>best_w<\/code> \uc640 \uadf8 \uac00\uc911\uce58\uc5d0\uc11c\uc758 \ud3c9\uac00 \uc9c0\ud45c \uc810\uc218\uc774\uba70, \ubaa8\ub378 S \uc758 \uac00\uc911\uce58\ub294 <code>1 - best_w<\/code> \uc785\ub2c8\ub2e4. \ud0d0\uc0c9 \ud568\uc218\ub294 <a href=\"#b2-optimal-weight-search\">Appendix B.2<\/a> \uc774\uace0, \uac00\uc0c1 \ub370\uc774\ud130\ub97c \ud65c\uc6a9\ud55c \uc2e4\ud589 \uc608\uc2dc\ub294 <a href=\"#b3-execution-example\">Appendix B.3<\/a> \uc785\ub2c8\ub2e4.<\/p>\n<p dir=\"auto\">Validation \ub370\uc774\ud130\ub85c \ucc3e\uc544\ub0b8 \ucd5c\uc801\uc758 <code>best_w<\/code> \ub97c \uadf8\ub300\ub85c Test \ub370\uc774\ud130\uc14b\uc758 \uac00\uc911\ud569 \uacc4\uc0b0\uc5d0 \uc801\uc6a9\ud558\uc5ec \ucd5c\uc885 \ud3c9\uac00\ub97c \uc218\ud589\ud558\uba74 \ub429\ub2c8\ub2e4.<\/p>\n<math-renderer class=\"js-display-math\" style=\"display: block\" data-run-id=\"81b2477d902b542d9f095a2bcc064a72\">$$p_{\\mathrm{hybrid,test}} = w_{\\mathrm{best}} \\cdot p_{T,\\mathrm{test}} + (1 - w_{\\mathrm{best}}) \\cdot p_{S,\\mathrm{test}} \\hspace{19em} (6)$$<\/math-renderer>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">4.2 Metric Selection<\/h3><a id=\"user-content-42-metric-selection\" class=\"anchor\" aria-label=\"Permalink: 4.2 Metric Selection\" href=\"#42-metric-selection\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">\uc9c0\ud45c\ub294 <code>y_true<\/code> \uc640 \ubb34\uc5c7\uc744 \ub300\ub294\uc9c0\ub85c \uac08\ub9bd\ub2c8\ub2e4. R-squared \uc640 MAPE \ub294 \uc2dd (5) \uc758 \ub2e8\uc77c \uc608\uce21\uac12\uc744 \uc7ac\uc5b4 \uc0b0\ucd9c\ubb3c\uc744 \ubc14\ub85c \uaca8\ub0e5\ud558\uace0, <code>F1-Score<\/code> \uc640 <code>Accuracy<\/code> \ub294 <code>threshold<\/code> \uac00 \ub9cc\ub4e0 \ud074\ub798\uc2a4 <code>y_pred<\/code> \ub97c \uc7ac\ubbc0\ub85c \uc774\ub4e4\uc774 \uace0\ub978 \uac00\uc911\uce58\ub294 <code>y_pred<\/code> \ub97c \uc6c0\uc9c1\uc774\uba70, <code>ROC-AUC<\/code> \uc640 <code>Log Loss<\/code> \ub294 \ud558\uc774\ube0c\ub9ac\ub4dc \ud655\ub960 \uc790\uccb4\ub97c \uc7ac\uc5b4 \uace0\ub978 \uac12\uc740 \uac74\ub4dc\ub9ac\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4.<\/p>\n<p dir=\"auto\">Table 1. Metrics for the weight search<\/p>\n<markdown-accessiblity-table><table>\n<thead>\n<tr>\n<th>#<\/th>\n<th>Metric<\/th>\n<th>Direction<\/th>\n<th>Threshold<\/th>\n<th>Compared with y_true<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td><code>r2_score<\/code><\/td>\n<td>Higher is better<\/td>\n<td>Not used<\/td>\n<td><code>v_hybrid<\/code> of equation (5)<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td><code>mean_absolute_percentage_error<\/code><\/td>\n<td>Lower is better<\/td>\n<td>Not used<\/td>\n<td><code>v_hybrid<\/code> of equation (5)<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td><code>ThresholdMetric(f1_score)<\/code><\/td>\n<td>Higher is better<\/td>\n<td>Used<\/td>\n<td><code>y_pred<\/code>, the class from the threshold<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td><code>ThresholdMetric(accuracy_score)<\/code><\/td>\n<td>Higher is better<\/td>\n<td>Used<\/td>\n<td><code>y_pred<\/code>, the class from the threshold<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td><code>roc_auc_score<\/code><\/td>\n<td>Higher is better<\/td>\n<td>Not used<\/td>\n<td><code>p_hybrid<\/code> of equation (1)<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td><code>log_loss<\/code><\/td>\n<td>Lower is better<\/td>\n<td>Not used<\/td>\n<td><code>p_hybrid<\/code> of equation (1)<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/markdown-accessiblity-table>\n<div class=\"markdown-heading\" dir=\"auto\"><h4 class=\"heading-element\" dir=\"auto\"><code>r2_score<\/code><\/h4><a id=\"user-content-r2_score\" class=\"anchor\" aria-label=\"Permalink: r2_score\" href=\"#r2_score\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">\uc2dd (5) \uc758 <code>v_hybrid<\/code> \ub97c <code>y_true<\/code> \uc640 \ub311\ub2c8\ub2e4. \uc774 \ubb38\uc11c\uc758 \uc0b0\ucd9c\ubb3c\uc774 \ubc14\ub85c \uadf8 \uac12\uc785\ub2c8\ub2e4.<\/p>\n<ul dir=\"auto\">\n<li>\uc7a5\uc810: \ub3c5\uc790\uac00 \uac00\uc838\uac00\ub294 \uac12\uc744 \uc9c1\uc811 \uaca8\ub0e5. \uc784\uacc4\uac12\uc744 \uc815\ud560 \ud544\uc694 \uc5c6\uc74c. \uc5f0\uc18d\uac12\uacfc \ud074\ub798\uc2a4\uc5d0 \uac19\uc740 \uaddc\uce59\uc73c\ub85c \uc801\uc6a9.<\/li>\n<li>\ub2e8\uc810: <code>v_T<\/code>, <code>v_S<\/code> \uac00 \uc788\uc5b4\uc57c \ud568. \ub450 \ud655\ub960\uc774 \ubaa8\ub450 0 \uc778 \ud589\uc5d0\uc11c\ub294 \uc2dd (5) \uc758 \ubd84\ubaa8\uac00 0 \uc774\ub77c \uc815\uc758\ub418\uc9c0 \uc54a\uc74c. \uc624\ucc28\ub97c \uc81c\uacf1\ud558\ubbc0\ub85c \ud55c \ud589\uc758 \ud070 \uc624\ucc28\uac00 w \ub97c \uc88c\uc6b0.<\/li>\n<\/ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h4 class=\"heading-element\" dir=\"auto\"><code>mean_absolute_percentage_error<\/code><\/h4><a id=\"user-content-mean_absolute_percentage_error\" class=\"anchor\" aria-label=\"Permalink: mean_absolute_percentage_error\" href=\"#mean_absolute_percentage_error\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">\uc2dd (5) \uc758 <code>v_hybrid<\/code> \ub97c <code>y_true<\/code> \uc640 \ub300\uc5b4, \uc808\ub300 \uc624\ucc28\ub97c \uc815\ub2f5\uc73c\ub85c \ub098\ub208 \uac12\uc758 \ud3c9\uade0\uc744 \ub0c5\ub2c8\ub2e4.<\/p>\n<ul dir=\"auto\">\n<li>\uc7a5\uc810: \ubc31\ubd84\uc728\ub85c \uc77d\ud788\ubbc0\ub85c \ub2e8\uc704\uc640 \ud06c\uae30\uac00 \ub2e4\ub978 \ub300\uc0c1\ub07c\ub9ac \uacb0\uacfc\ub97c \uacac\uc904 \uc218 \uc788\uc74c. \uc815\ub2f5\uc774 \ud070 \ud589\uc774 \uc9c0\ud45c\ub97c \ub3c5\ucc28\uc9c0\ud558\uc9c0 \uc54a\uc74c.<\/li>\n<li>\ub2e8\uc810: \uc815\ub2f5\uc774 0 \uc774\uac70\ub098 0 \uc5d0 \uac00\uae4c\uc6b0\uba74 \ubc1c\uc0b0. \uac19\uc740 \ud06c\uae30\ub77c\ub3c4 \uacfc\ub300\uc608\uce21\uc758 \ubc8c\uc810\uc774 \uacfc\uc18c\uc608\uce21\ubcf4\ub2e4 \ud07c.<\/li>\n<\/ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h4 class=\"heading-element\" dir=\"auto\"><code>ThresholdMetric(f1_score)<\/code><\/h4><a id=\"user-content-thresholdmetricf1_score\" class=\"anchor\" aria-label=\"Permalink: ThresholdMetric(f1_score)\" href=\"#thresholdmetricf1_score\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\"><code>threshold<\/code> \uac00 \ub9cc\ub4e0 \ud074\ub798\uc2a4 <code>y_pred<\/code> \ub97c \uc815\ubc00\ub3c4\uc640 \uc7ac\ud604\uc728\uc758 \uc870\ud654 \ud3c9\uade0\uc73c\ub85c \uc7bd\ub2c8\ub2e4.<\/p>\n<ul dir=\"auto\">\n<li>\uc7a5\uc810: \ub808\uc774\ube14\uc774 \ubd88\uade0\ud615\uc77c \ub54c \uc591\uc131 \ud074\ub798\uc2a4\uc758 \uc131\ub2a5\uc774 \ub4dc\ub7ec\ub0a8. \uc2e4\uc81c\ub85c \uc4f0\ub294 \ub3d9\uc791\uc810\uc5d0\uc11c\uc758 \uc131\ub2a5\uc744 \ud55c \uc22b\uc790\ub85c \uc77d\uc74c.<\/li>\n<li>\ub2e8\uc810: <code>ThresholdMetric<\/code> \uc774 \uc954 \uc784\uacc4\uac12\uc5d0 \ubb36\uc5ec \uc788\uc5b4 \uc784\uacc4\uac12\uc774 \ubc14\ub00c\uba74 \uace0\ub978 w \uac00 \ub0a1\uc74c. \uc74c\uc131 \ud074\ub798\uc2a4\ub294 \uadf8\uac83\uc774 \ubd80\ub978 \uc624\ub958\ub85c\ub9cc \ubc18\uc601.<\/li>\n<\/ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h4 class=\"heading-element\" dir=\"auto\"><code>ThresholdMetric(accuracy_score)<\/code><\/h4><a id=\"user-content-thresholdmetricaccuracy_score\" class=\"anchor\" aria-label=\"Permalink: ThresholdMetric(accuracy_score)\" href=\"#thresholdmetricaccuracy_score\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\"><code>threshold<\/code> \uac00 \ub9cc\ub4e0 \ud074\ub798\uc2a4 <code>y_pred<\/code> \uac00\uc6b4\ub370 \ub9de\ud78c \ud589\uc758 \ube44\uc728\uc785\ub2c8\ub2e4.<\/p>\n<ul dir=\"auto\">\n<li>\uc7a5\uc810: \uacb0\uacfc\ub97c \uac00\uc7a5 \ub2e8\uc21c\ud558\uac8c \uc77d\ub294 \ubc29\uc2dd. \ub450 \ud074\ub798\uc2a4\ub97c \uac19\uc740 \ubb34\uac8c\ub85c \uc148.<\/li>\n<li>\ub2e8\uc810: \ub808\uc774\ube14\uc774 \ubd88\uade0\ud615\uc774\uba74 \ub2e4\uc218 \ud074\ub798\uc2a4\ub9cc \ub9de\ud600\ub3c4 \ub192\uac8c \ub098\uc634. <code>f1_score<\/code> \uc640 \uac19\uc740 \ubc29\uc2dd\uc73c\ub85c \uc784\uacc4\uac12\uc5d0 \ubb36\uc784.<\/li>\n<\/ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h4 class=\"heading-element\" dir=\"auto\"><code>roc_auc_score<\/code><\/h4><a id=\"user-content-roc_auc_score\" class=\"anchor\" aria-label=\"Permalink: roc_auc_score\" href=\"#roc_auc_score\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">\uc2dd (1) \uc758 <code>p_hybrid<\/code> \uac00 \ub9cc\ub4dc\ub294 \uc21c\uc704\ub97c \ubaa8\ub4e0 \uc784\uacc4\uac12\uc5d0 \uac78\uccd0 \ud55c\uaebc\ubc88\uc5d0 \uc7bd\ub2c8\ub2e4.<\/p>\n<ul dir=\"auto\">\n<li>\uc7a5\uc810: \uc784\uacc4\uac12\uc744 \uc815\ud560 \ud544\uc694\uac00 \uc5c6\uc5b4 \ub3d9\uc791\uc810\uc744 \uc815\ud558\uae30 \uc804\uc758 \ud0d0\uc0c9\uc5d0 \ub9de\uc74c. \ub808\uc774\ube14 \ubd88\uade0\ud615\uc5d0 \uacac\uace0.<\/li>\n<li>\ub2e8\uc810: \ud655\ub960\uc744 \ub2e8\uc870 \ubcc0\ud658\ud574\ub3c4 \uac12\uc774 \uadf8\ub300\ub85c\ub77c calibration \uc774 \uc5b4\uae0b\ub09c \ubaa8\ub378\ub3c4 \ud1b5\uacfc. \ub2e8\uc77c \uc608\uce21\uac12\uc744 \uc7ac\ub294 \uc9c0\ud45c\uac00 \uc544\ub2d8.<\/li>\n<\/ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h4 class=\"heading-element\" dir=\"auto\"><code>log_loss<\/code><\/h4><a id=\"user-content-log_loss\" class=\"anchor\" aria-label=\"Permalink: log_loss\" href=\"#log_loss\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">\uc2dd (1) \uc758 <code>p_hybrid<\/code> \ub97c <code>y_true<\/code> \uc640 \ub300\uc5b4, \ud655\ub960\uc774 \uc815\ub2f5\uc5d0\uc11c \uc5bc\ub9c8\ub098 \ub5a8\uc5b4\uc838 \uc788\ub294\uc9c0\ub85c \ubc8c\uc810\uc744 \ub9e4\uae41\ub2c8\ub2e4.<\/p>\n<ul dir=\"auto\">\n<li>\uc7a5\uc810: \ud655\ub960\uc758 \ub208\uae08\uae4c\uc9c0 \ucc44\uc810\ud558\ub294 \uc720\uc77c\ud55c \uc9c0\ud45c\ub77c, \uaf2d\uc9c0 5 \uac00 \uacbd\uace0\ud558\ub294 calibration \uc0c1\ud0dc\uac00 \ub4dc\ub7ec\ub0a8.<\/li>\n<li>\ub2e8\uc810: \ud655\uc2e0\uc744 \uac16\uace0 \ud2c0\ub9b0 \ud55c \ud589\uc758 \ubc8c\uc810\uc774 \ub9e4\uc6b0 \ucee4\uc11c \uadf8 \ud589\uc774 w \ub97c \uc88c\uc6b0. \ud655\ub960\uc774 0 \uc774\ub098 1 \uc774\uba74 \ud074\ub9ac\ud551 \uc5c6\uc774\ub294 \ubc1c\uc0b0.<\/li>\n<\/ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">5. Cautions<\/h2><a id=\"user-content-5-cautions\" class=\"anchor\" aria-label=\"Permalink: 5. Cautions\" href=\"#5-cautions\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">\ub450 \ubaa8\ub378\uc758 \ud655\ub960 \ubd84\ud3ec\uac00 \uc815\uad50\ud558\uac8c \ub9de\ucd94\uc5b4\uc838 \uc788\ub294\uc9c0 \ud655\uc778\ud574\uc57c \ud569\ub2c8\ub2e4. \ud55c \ubaa8\ub378\uc774 \ud655\ub960\uc744 \ub108\ubb34 \uacfc\uc2e0 (\uc608: \ub300\ubd80\ubd84 0.05 \ub610\ub294 0.95 \uadfc\ucc98) \ud558\uace0 \ub2e4\ub978 \ubaa8\ub378\uc740 \uc2e0\uc911\ud55c \uacbd\uc6b0 (\uc608: 0.4\u223c0.6 \uc0ac\uc774), \ub2e8\uc21c \uac00\uc911\uce58 \uc870\ud569 \uc2dc \uacfc\uc2e0\ud558\ub294 \ubaa8\ub378\uc758 \uc601\ud5a5\ub825\uc774 \uacfc\ub3c4\ud558\uac8c \ucee4\uc9c8 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">6. Further Work<\/h2><a id=\"user-content-6-further-work\" class=\"anchor\" aria-label=\"Permalink: 6. Further Work\" href=\"#6-further-work\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<ul dir=\"auto\">\n<li><strong>\ud655\ub960 calibration \uc801\uc6a9<\/strong>\n<ul dir=\"auto\">\n<li>\ubb34\uc5c7: <code>IsotonicRegression<\/code>\uc774\ub098 <code>Platt Scaling<\/code>\uc744 \ud1b5\ud55c calibration \uc744 \ub450 \ubaa8\ub378\uc758 \ud655\ub960\uc5d0 \uc801\uc6a9\ud55c \ub4a4 \uac00\uc911\ud569.<\/li>\n<li>\uc65c \uc9c0\uae08: \uaf2d\uc9c0 5 \uc758 \uc870\uac74, \uc989 \ud55c \ubaa8\ub378\uc774 \uacfc\uc2e0\ud558\uace0 \ub2e4\ub978 \ubaa8\ub378\uc774 \uc2e0\uc911\ud55c \uc0c1\ud0dc\uc5d0\uc11c\ub294 \uac00\uc911\uce58\ub9cc\uc73c\ub85c \uc601\ud5a5\ub825\uc758 \ubd88\uade0\ud615\uc744 \ubc14\ub85c\uc7a1\uc9c0 \ubabb\ud568.<\/li>\n<li>\ubb34\uc5c7\uc774 \ud544\uc694: Calibration \uc5d0 \uc4f8 \ub370\uc774\ud130\uc640, calibration \uc804\ud6c4\uc758 \ucd5c\uc801 w \ubc0f \uc9c0\ud45c \uc810\uc218 \ube44\uad50.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">References<\/h2><a id=\"user-content-references\" class=\"anchor\" aria-label=\"Permalink: References\" href=\"#references\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">N\/A \u2014 \uc678\ubd80 \ucd9c\ucc98\ub97c \uc778\uc6a9\ud558\uc9c0 \uc54a\uc74c.<\/p>\n<hr>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">Appendix A. Terminology<\/h2><a id=\"user-content-appendix-a-terminology\" class=\"anchor\" aria-label=\"Permalink: Appendix A. Terminology\" href=\"#appendix-a-terminology\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<ul dir=\"auto\">\n<li><strong>Grid Search<\/strong>: \uc815\ud574\uc9c4 \uad6c\uac04\uc744 \uc77c\uc815 \uac04\uaca9\uc73c\ub85c \ud6d1\uc5b4 \ucd5c\uc801\uac12\uc744 \ucc3e\ub294 \ud0d0\uc0c9.<\/li>\n<li><strong>Isotonic Regression<\/strong>: \ub2e8\uc870 \uc99d\uac00 \uc81c\uc57d \uc544\ub798 \uc608\uce21 \ud655\ub960\uc744 \uc2e4\uc81c \ube48\ub3c4\uc5d0 \ub9de\ucd94\ub294 \uad50\uc815 \ubc29\ubc95.<\/li>\n<li><strong>Log Loss<\/strong>: \uc608\uce21 \ud655\ub960\uacfc \uc815\ub2f5\uc758 \ubd88\uc77c\uce58\ub97c \uc7ac\ub294 \uc9c0\ud45c. \uc791\uc744\uc218\ub85d \uc88b\uc74c.<\/li>\n<li><strong>MAPE<\/strong>: Mean absolute percentage error, the mean of the absolute errors divided by the true value. Lower is better.<\/li>\n<li><strong>Platt Scaling<\/strong>: \ubaa8\ub378\uc758 \ucd9c\ub825\uc744 logistic \ud568\uc218\uc5d0 \ud1b5\uacfc\uc2dc\ucf1c \ud655\ub960\ub85c \ub9de\ucd94\ub294 \uad50\uc815 \ubc29\ubc95.<\/li>\n<li><strong>Probability Calibration<\/strong>: \ubaa8\ub378\uc774 \ub0b4\ub193\ub294 \ud655\ub960\uc744 \uc2e4\uc81c \ube48\ub3c4\uc5d0 \ub9de\ucd94\ub294 \uc808\ucc28.<\/li>\n<li><strong>R-squared<\/strong>: A metric of how much of the variance of the true value the prediction accounts for. Higher is better.<\/li>\n<li><strong>ROC-AUC<\/strong>: \ubaa8\ub4e0 \uc784\uacc4\uac12\uc5d0 \uac78\uce5c \ubd84\ub958 \uc131\ub2a5\uc744 \ud558\ub098\ub85c \uc694\uc57d\ud55c \uc9c0\ud45c.<\/li>\n<li><strong>Soft Voting<\/strong>: \uac01 \ubaa8\ub378\uc758 \uc608\uce21 \ud655\ub960\uc744 \uac00\uc911 \ud3c9\uade0\ud558\uc5ec \ucd5c\uc885 \ud074\ub798\uc2a4\ub97c \uc815\ud558\ub294 \uacb0\ud569 \ubc29\uc2dd.<\/li>\n<li><strong>Threshold<\/strong>: \ud655\ub960\uc744 \ucd5c\uc885 \ud074\ub798\uc2a4\ub85c \ubcc0\ud658\ud558\ub294 \ubd84\ub958 \uc784\uacc4\uac12.<\/li>\n<li><strong>ThresholdMetric<\/strong>: \ud074\ub798\uc2a4\ub97c \uc7ac\ub294 \uc9c0\ud45c\uc640 \uadf8\uac83\uc774 \ud544\uc694\ud55c \uc784\uacc4\uac12\uc744 \ud568\uaed8 \uc954 callable. \ud655\ub960\uc744 \ubc14\ub85c \ubc1b\ub294 \uc9c0\ud45c\ub4e4\uacfc \uac19\uc740 \ubc29\uc2dd\uc73c\ub85c \ud655\ub960\uc744 \ucc44\uc810\ud55c\ub2e4.<\/li>\n<\/ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">Appendix B. Python Implementation<\/h2><a id=\"user-content-appendix-b-python-implementation\" class=\"anchor\" aria-label=\"Permalink: Appendix B. Python Implementation\" href=\"#appendix-b-python-implementation\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">B.1 Single Predicted Value<\/h3><a id=\"user-content-b1-single-predicted-value\" class=\"anchor\" aria-label=\"Permalink: B.1 Single Predicted Value\" href=\"#b1-single-predicted-value\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<div class=\"highlight highlight-source-python notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"from typing import Union\n\nimport numpy as np\n\nProbability = Union[float, np.ndarray]\n\n\ndef check_probability(p: Probability) -&gt; np.ndarray:\n    &quot;&quot;&quot;Check that the probability lies within 0~1.\n\n    p: predicted probability of a model\n\n    &gt;&gt;&gt; check_probability(np.array([0.9, 0.5, 0.2]))\n    array([0.9, 0.5, 0.2])\n    &gt;&gt;&gt; check_probability(np.array([0.9, 1.4]))\n    Traceback (most recent call last):\n    ValueError: probability outside 0~1: min=0.9, max=1.4\n    &quot;&quot;&quot;\n    p = np.asarray(p, dtype=float)\n    if p.min() &lt; 0 or p.max() &gt; 1:\n        raise ValueError(f&quot;probability outside 0~1: min={p.min()}, max={p.max()}&quot;)\n    return p\n\n\ndef hybrid_predict_value(v_T: np.ndarray, v_S: np.ndarray, p_T: Probability, p_S: Probability,\n                         w: float = 0.5) -&gt; np.ndarray:\n    &quot;&quot;&quot;\n    v_T: predicted value of model T\n    v_S: predicted value of model S\n    p_T: predicted probability of model T (0~1)\n    p_S: predicted probability of model S (0~1)\n    w: weight given to model T (0~1)\n\n    &gt;&gt;&gt; y_pred_by_t = np.array([10.0, 20.0, 30.0])\n    &gt;&gt;&gt; y_pred_by_s = np.array([12.0, 22.0, 36.0])\n    &gt;&gt;&gt; y_prob_by_t = np.array([0.9, 0.5, 0.2])\n    &gt;&gt;&gt; y_prob_by_s = np.array([0.3, 0.6, 0.9])\n    &gt;&gt;&gt; np.round(hybrid_predict_value(y_pred_by_t, y_pred_by_s, y_prob_by_t, y_prob_by_s, w=0.5), 4)\n    array([10.5   , 21.0909, 34.9091])\n    &gt;&gt;&gt; hybrid_predict_value(y_pred_by_t, y_pred_by_s, np.array([0.0, 0.5, 0.2]), np.array([0.0, 0.6, 0.9]))\n    Traceback (most recent call last):\n    ValueError: both models report zero probability, so the weighted value is undefined.\n    &quot;&quot;&quot;\n    # both probabilities have to be on the 0~1 scale before they are weighed against each other\n    p_T = check_probability(p_T)\n    p_S = check_probability(p_S)\n\n    # confidence each model carries into the combination\n    weight_T = w * p_T\n    weight_S = (1 - w) * p_S\n\n    denominator = weight_T + weight_S\n    if np.any(denominator == 0):\n        raise ValueError(&quot;both models report zero probability, so the weighted value is undefined.&quot;)\n    return (weight_T * v_T + weight_S * v_S) \/ denominator\"><pre><span class=\"pl-k\">from<\/span> <span class=\"pl-s1\">typing<\/span> <span class=\"pl-k\">import<\/span> <span class=\"pl-v\">Union<\/span>\n\n<span class=\"pl-k\">import<\/span> <span class=\"pl-s1\">numpy<\/span> <span class=\"pl-k\">as<\/span> <span class=\"pl-s1\">np<\/span>\n\n<span class=\"pl-v\">Probability<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-v\">Union<\/span>&#91;<span class=\"pl-s1\">float<\/span>, <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>&#93;\n\n\n<span class=\"pl-k\">def<\/span> <span class=\"pl-en\">check_probability<\/span>(<span class=\"pl-s1\">p<\/span>: <span class=\"pl-smi\">Probability<\/span>) <span class=\"pl-c1\">-&gt;<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>:\n    <span class=\"pl-s\">\"\"\"Check that the probability lies within 0~1.<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    p: predicted probability of a model<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; check_probability(np.array(&#91;0.9, 0.5, 0.2&#93;))<\/span>\n<span class=\"pl-s\">    array(&#91;0.9, 0.5, 0.2&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; check_probability(np.array(&#91;0.9, 1.4&#93;))<\/span>\n<span class=\"pl-s\">    Traceback (most recent call last):<\/span>\n<span class=\"pl-s\">    ValueError: probability outside 0~1: min=0.9, max=1.4<\/span>\n<span class=\"pl-s\">    \"\"\"<\/span>\n    <span class=\"pl-s1\">p<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">asarray<\/span>(<span class=\"pl-s1\">p<\/span>, <span class=\"pl-s1\">dtype<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">float<\/span>)\n    <span class=\"pl-k\">if<\/span> <span class=\"pl-s1\">p<\/span>.<span class=\"pl-c1\">min<\/span>() <span class=\"pl-c1\">&lt;<\/span> <span class=\"pl-c1\">0<\/span> <span class=\"pl-c1\">or<\/span> <span class=\"pl-s1\">p<\/span>.<span class=\"pl-c1\">max<\/span>() <span class=\"pl-c1\">&gt;<\/span> <span class=\"pl-c1\">1<\/span>:\n        <span class=\"pl-k\">raise<\/span> <span class=\"pl-en\">ValueError<\/span>(<span class=\"pl-s\">f\"probability outside 0~1: min=<span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">p<\/span>.<span class=\"pl-c1\">min<\/span>()<span class=\"pl-kos\">}<\/span><\/span>, max=<span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">p<\/span>.<span class=\"pl-c1\">max<\/span>()<span class=\"pl-kos\">}<\/span><\/span>\"<\/span>)\n    <span class=\"pl-k\">return<\/span> <span class=\"pl-s1\">p<\/span>\n\n\n<span class=\"pl-k\">def<\/span> <span class=\"pl-en\">hybrid_predict_value<\/span>(<span class=\"pl-s1\">v_T<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>, <span class=\"pl-s1\">v_S<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>, <span class=\"pl-s1\">p_T<\/span>: <span class=\"pl-smi\">Probability<\/span>, <span class=\"pl-s1\">p_S<\/span>: <span class=\"pl-smi\">Probability<\/span>,\n                         <span class=\"pl-s1\">w<\/span>: <span class=\"pl-smi\">float<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">0.5<\/span>) <span class=\"pl-c1\">-&gt;<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>:\n    <span class=\"pl-s\">\"\"\"<\/span>\n<span class=\"pl-s\">    v_T: predicted value of model T<\/span>\n<span class=\"pl-s\">    v_S: predicted value of model S<\/span>\n<span class=\"pl-s\">    p_T: predicted probability of model T (0~1)<\/span>\n<span class=\"pl-s\">    p_S: predicted probability of model S (0~1)<\/span>\n<span class=\"pl-s\">    w: weight given to model T (0~1)<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; y_pred_by_t = np.array(&#91;10.0, 20.0, 30.0&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; y_pred_by_s = np.array(&#91;12.0, 22.0, 36.0&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; y_prob_by_t = np.array(&#91;0.9, 0.5, 0.2&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; y_prob_by_s = np.array(&#91;0.3, 0.6, 0.9&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; np.round(hybrid_predict_value(y_pred_by_t, y_pred_by_s, y_prob_by_t, y_prob_by_s, w=0.5), 4)<\/span>\n<span class=\"pl-s\">    array(&#91;10.5   , 21.0909, 34.9091&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; hybrid_predict_value(y_pred_by_t, y_pred_by_s, np.array(&#91;0.0, 0.5, 0.2&#93;), np.array(&#91;0.0, 0.6, 0.9&#93;))<\/span>\n<span class=\"pl-s\">    Traceback (most recent call last):<\/span>\n<span class=\"pl-s\">    ValueError: both models report zero probability, so the weighted value is undefined.<\/span>\n<span class=\"pl-s\">    \"\"\"<\/span>\n    <span class=\"pl-c\"># both probabilities have to be on the 0~1 scale before they are weighed against each other<\/span>\n    <span class=\"pl-s1\">p_T<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">check_probability<\/span>(<span class=\"pl-s1\">p_T<\/span>)\n    <span class=\"pl-s1\">p_S<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">check_probability<\/span>(<span class=\"pl-s1\">p_S<\/span>)\n\n    <span class=\"pl-c\"># confidence each model carries into the combination<\/span>\n    <span class=\"pl-s1\">weight_T<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">w<\/span> <span class=\"pl-c1\">*<\/span> <span class=\"pl-s1\">p_T<\/span>\n    <span class=\"pl-s1\">weight_S<\/span> <span class=\"pl-c1\">=<\/span> (<span class=\"pl-c1\">1<\/span> <span class=\"pl-c1\">-<\/span> <span class=\"pl-s1\">w<\/span>) <span class=\"pl-c1\">*<\/span> <span class=\"pl-s1\">p_S<\/span>\n\n    <span class=\"pl-s1\">denominator<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">weight_T<\/span> <span class=\"pl-c1\">+<\/span> <span class=\"pl-s1\">weight_S<\/span>\n    <span class=\"pl-k\">if<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">any<\/span>(<span class=\"pl-s1\">denominator<\/span> <span class=\"pl-c1\">==<\/span> <span class=\"pl-c1\">0<\/span>):\n        <span class=\"pl-k\">raise<\/span> <span class=\"pl-en\">ValueError<\/span>(<span class=\"pl-s\">\"both models report zero probability, so the weighted value is undefined.\"<\/span>)\n    <span class=\"pl-k\">return<\/span> (<span class=\"pl-s1\">weight_T<\/span> <span class=\"pl-c1\">*<\/span> <span class=\"pl-s1\">v_T<\/span> <span class=\"pl-c1\">+<\/span> <span class=\"pl-s1\">weight_S<\/span> <span class=\"pl-c1\">*<\/span> <span class=\"pl-s1\">v_S<\/span>) <span class=\"pl-c1\">\/<\/span> <span class=\"pl-s1\">denominator<\/span><\/pre><\/div>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">B.2 Optimal Weight Search<\/h3><a id=\"user-content-b2-optimal-weight-search\" class=\"anchor\" aria-label=\"Permalink: B.2 Optimal Weight Search\" href=\"#b2-optimal-weight-search\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<div class=\"highlight highlight-source-python notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"from typing import Callable\n\nimport numpy as np\nfrom sklearn.metrics import (accuracy_score, f1_score, log_loss, mean_absolute_percentage_error, r2_score,\n                             roc_auc_score)\n\nScore = Callable[[np.ndarray, np.ndarray], float]\n\n\nclass ThresholdMetric:\n    &quot;&quot;&quot;Turn a metric that scores a class into one that scores a probability.\n\n    score_fn: metric taking (y_true, y_pred), such as f1_score or accuracy_score\n    threshold: classification threshold applied before the metric runs\n\n    &gt;&gt;&gt; y_true = np.array([0, 0, 1, 1])\n    &gt;&gt;&gt; p_hybrid = np.array([0.2, 0.6, 0.7, 0.4])\n    &gt;&gt;&gt; metric = ThresholdMetric(f1_score, threshold=0.5)\n    &gt;&gt;&gt; round(float(metric(y_true, p_hybrid)), 4)\n    0.5\n    &quot;&quot;&quot;\n\n    def __init__(self, score_fn: Score, threshold: float = 0.5):\n        self.score_fn = score_fn\n        self.threshold = threshold\n\n    def __call__(self, y_true: np.ndarray, p_hybrid: np.ndarray) -&gt; float:\n        y_pred = (p_hybrid &gt;= self.threshold).astype(int)\n        return self.score_fn(y_true, y_pred)\n\n\ndef find_optimal_weight(y_true: np.ndarray, p_T: np.ndarray, p_S: np.ndarray, metric: Score,\n                        higher_is_better: bool = True, step: float = 0.01,\n                        v_T: np.ndarray = None, v_S: np.ndarray = None) -&gt; tuple[float, float]:\n    &quot;&quot;&quot;Search the weight w of models T and S that suits the validation dataset best, by grid search.\n\n    Parameters:\n    - y_true: true labels (N,)\n    - p_T: predicted probability of model T (N,)\n    - p_S: predicted probability of model S (N,)\n    - metric: callable taking (y_true, y_score), such as roc_auc_score or ThresholdMetric(f1_score)\n    - higher_is_better: direction of the metric, False for log_loss and mean_absolute_percentage_error\n    - step: weight step of the grid search (default: 0.01 -&gt; 100 intervals)\n    - v_T: predicted value of model T (N,), which makes the metric score the single predicted value\n    - v_S: predicted value of model S (N,), given together with v_T\n\n    Returns:\n    - best_w: optimal weight for model T (model S takes 1 - best_w)\n    - best_score: metric score at that weight\n\n    &gt;&gt;&gt; y_true = np.array([0, 0, 1, 1])\n    &gt;&gt;&gt; p_T = np.array([0.2, 0.3, 0.7, 0.8])\n    &gt;&gt;&gt; p_S = np.array([0.6, 0.4, 0.5, 0.3])\n    &gt;&gt;&gt; best_w, best_score = find_optimal_weight(y_true, p_T, p_S, metric=roc_auc_score, step=0.25)\n    &gt;&gt;&gt; float(best_w), round(float(best_score), 4)\n    (0.5, 1.0)\n    &gt;&gt;&gt; best_w, best_score = find_optimal_weight(\n    ...     y_true, p_T, p_S, metric=log_loss, higher_is_better=False, step=0.25\n    ... )\n    &gt;&gt;&gt; float(best_w), round(float(best_score), 4)\n    (1.0, 0.2899)\n    &gt;&gt;&gt; y_value = np.array([10.0, 20.0, 30.0, 40.0])\n    &gt;&gt;&gt; v_T = np.array([11.0, 19.0, 33.0, 37.0])\n    &gt;&gt;&gt; v_S = np.array([14.0, 25.0, 26.0, 44.0])\n    &gt;&gt;&gt; best_w, best_score = find_optimal_weight(\n    ...     y_value, p_T, p_S, metric=r2_score, step=0.25, v_T=v_T, v_S=v_S\n    ... )\n    &gt;&gt;&gt; float(best_w), round(float(best_score), 4)\n    (0.75, 0.9707)\n    &gt;&gt;&gt; best_w, best_score = find_optimal_weight(\n    ...     y_true, p_T, p_S, metric=ThresholdMetric(accuracy_score), step=0.25\n    ... )\n    &gt;&gt;&gt; float(best_w), round(float(best_score), 4)\n    (0.5, 1.0)\n    &quot;&quot;&quot;\n    if not callable(metric):\n        raise TypeError(f&quot;metric must be callable, not {type(metric).__name__}.&quot;)\n    if (v_T is None) != (v_S is None):\n        raise ValueError(&quot;v_T and v_S are given together or not at all.&quot;)\n\n    weights = np.arange(0.0, 1.0 + step, step)\n    best_w = None\n    best_score = -float(&quot;inf&quot;) if higher_is_better else float(&quot;inf&quot;)\n\n    for w in weights:\n        # weighted average probability\n        p_hybrid = w * p_T + (1 - w) * p_S\n\n        # the metric scores the single predicted value where both models report one\n        if v_T is None:\n            score = metric(y_true, p_hybrid)\n        else:\n            score = metric(y_true, hybrid_predict_value(v_T, v_S, p_T, p_S, w))\n\n        # keep the best so far\n        if higher_is_better:\n            if score &gt; best_score:\n                best_score = score\n                best_w = round(w, 4)\n        else:\n            if score &lt; best_score:\n                best_score = score\n                best_w = round(w, 4)\n\n    return best_w, best_score\"><pre><span class=\"pl-k\">from<\/span> <span class=\"pl-s1\">typing<\/span> <span class=\"pl-k\">import<\/span> <span class=\"pl-v\">Callable<\/span>\n\n<span class=\"pl-k\">import<\/span> <span class=\"pl-s1\">numpy<\/span> <span class=\"pl-k\">as<\/span> <span class=\"pl-s1\">np<\/span>\n<span class=\"pl-k\">from<\/span> <span class=\"pl-s1\">sklearn<\/span>.<span class=\"pl-s1\">metrics<\/span> <span class=\"pl-k\">import<\/span> (<span class=\"pl-s1\">accuracy_score<\/span>, <span class=\"pl-s1\">f1_score<\/span>, <span class=\"pl-s1\">log_loss<\/span>, <span class=\"pl-s1\">mean_absolute_percentage_error<\/span>, <span class=\"pl-s1\">r2_score<\/span>,\n                             <span class=\"pl-s1\">roc_auc_score<\/span>)\n\n<span class=\"pl-v\">Score<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-v\">Callable<\/span>&#91;&#91;<span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>, <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>&#93;, <span class=\"pl-s1\">float<\/span>&#93;\n\n\n<span class=\"pl-k\">class<\/span> <span class=\"pl-v\">ThresholdMetric<\/span>:\n    <span class=\"pl-s\">\"\"\"Turn a metric that scores a class into one that scores a probability.<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    score_fn: metric taking (y_true, y_pred), such as f1_score or accuracy_score<\/span>\n<span class=\"pl-s\">    threshold: classification threshold applied before the metric runs<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; y_true = np.array(&#91;0, 0, 1, 1&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; p_hybrid = np.array(&#91;0.2, 0.6, 0.7, 0.4&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; metric = ThresholdMetric(f1_score, threshold=0.5)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; round(float(metric(y_true, p_hybrid)), 4)<\/span>\n<span class=\"pl-s\">    0.5<\/span>\n<span class=\"pl-s\">    \"\"\"<\/span>\n\n    <span class=\"pl-k\">def<\/span> <span class=\"pl-en\">__init__<\/span>(<span class=\"pl-s1\">self<\/span>, <span class=\"pl-s1\">score_fn<\/span>: <span class=\"pl-smi\">Score<\/span>, <span class=\"pl-s1\">threshold<\/span>: <span class=\"pl-smi\">float<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">0.5<\/span>):\n        <span class=\"pl-s1\">self<\/span>.<span class=\"pl-c1\">score_fn<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">score_fn<\/span>\n        <span class=\"pl-s1\">self<\/span>.<span class=\"pl-c1\">threshold<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">threshold<\/span>\n\n    <span class=\"pl-k\">def<\/span> <span class=\"pl-en\">__call__<\/span>(<span class=\"pl-s1\">self<\/span>, <span class=\"pl-s1\">y_true<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>, <span class=\"pl-s1\">p_hybrid<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>) <span class=\"pl-c1\">-&gt;<\/span> <span class=\"pl-smi\">float<\/span>:\n        <span class=\"pl-s1\">y_pred<\/span> <span class=\"pl-c1\">=<\/span> (<span class=\"pl-s1\">p_hybrid<\/span> <span class=\"pl-c1\">&gt;=<\/span> <span class=\"pl-s1\">self<\/span>.<span class=\"pl-c1\">threshold<\/span>).<span class=\"pl-c1\">astype<\/span>(<span class=\"pl-s1\">int<\/span>)\n        <span class=\"pl-k\">return<\/span> <span class=\"pl-s1\">self<\/span>.<span class=\"pl-c1\">score_fn<\/span>(<span class=\"pl-s1\">y_true<\/span>, <span class=\"pl-s1\">y_pred<\/span>)\n\n\n<span class=\"pl-k\">def<\/span> <span class=\"pl-en\">find_optimal_weight<\/span>(<span class=\"pl-s1\">y_true<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>, <span class=\"pl-s1\">p_T<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>, <span class=\"pl-s1\">p_S<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>, <span class=\"pl-s1\">metric<\/span>: <span class=\"pl-smi\">Score<\/span>,\n                        <span class=\"pl-s1\">higher_is_better<\/span>: <span class=\"pl-smi\">bool<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">True<\/span>, <span class=\"pl-s1\">step<\/span>: <span class=\"pl-smi\">float<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">0.01<\/span>,\n                        <span class=\"pl-s1\">v_T<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">None<\/span>, <span class=\"pl-s1\">v_S<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">None<\/span>) <span class=\"pl-c1\">-&gt;<\/span> <span class=\"pl-s1\">tuple<\/span>&#91;<span class=\"pl-smi\">float<\/span>, <span class=\"pl-smi\">float<\/span>&#93;:\n    <span class=\"pl-s\">\"\"\"Search the weight w of models T and S that suits the validation dataset best, by grid search.<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    Parameters:<\/span>\n<span class=\"pl-s\">    - y_true: true labels (N,)<\/span>\n<span class=\"pl-s\">    - p_T: predicted probability of model T (N,)<\/span>\n<span class=\"pl-s\">    - p_S: predicted probability of model S (N,)<\/span>\n<span class=\"pl-s\">    - metric: callable taking (y_true, y_score), such as roc_auc_score or ThresholdMetric(f1_score)<\/span>\n<span class=\"pl-s\">    - higher_is_better: direction of the metric, False for log_loss and mean_absolute_percentage_error<\/span>\n<span class=\"pl-s\">    - step: weight step of the grid search (default: 0.01 -&gt; 100 intervals)<\/span>\n<span class=\"pl-s\">    - v_T: predicted value of model T (N,), which makes the metric score the single predicted value<\/span>\n<span class=\"pl-s\">    - v_S: predicted value of model S (N,), given together with v_T<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    Returns:<\/span>\n<span class=\"pl-s\">    - best_w: optimal weight for model T (model S takes 1 - best_w)<\/span>\n<span class=\"pl-s\">    - best_score: metric score at that weight<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; y_true = np.array(&#91;0, 0, 1, 1&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; p_T = np.array(&#91;0.2, 0.3, 0.7, 0.8&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; p_S = np.array(&#91;0.6, 0.4, 0.5, 0.3&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; best_w, best_score = find_optimal_weight(y_true, p_T, p_S, metric=roc_auc_score, step=0.25)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; float(best_w), round(float(best_score), 4)<\/span>\n<span class=\"pl-s\">    (0.5, 1.0)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; best_w, best_score = find_optimal_weight(<\/span>\n<span class=\"pl-s\">    ...     y_true, p_T, p_S, metric=log_loss, higher_is_better=False, step=0.25<\/span>\n<span class=\"pl-s\">    ... )<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; float(best_w), round(float(best_score), 4)<\/span>\n<span class=\"pl-s\">    (1.0, 0.2899)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; y_value = np.array(&#91;10.0, 20.0, 30.0, 40.0&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; v_T = np.array(&#91;11.0, 19.0, 33.0, 37.0&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; v_S = np.array(&#91;14.0, 25.0, 26.0, 44.0&#93;)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; best_w, best_score = find_optimal_weight(<\/span>\n<span class=\"pl-s\">    ...     y_value, p_T, p_S, metric=r2_score, step=0.25, v_T=v_T, v_S=v_S<\/span>\n<span class=\"pl-s\">    ... )<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; float(best_w), round(float(best_score), 4)<\/span>\n<span class=\"pl-s\">    (0.75, 0.9707)<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; best_w, best_score = find_optimal_weight(<\/span>\n<span class=\"pl-s\">    ...     y_true, p_T, p_S, metric=ThresholdMetric(accuracy_score), step=0.25<\/span>\n<span class=\"pl-s\">    ... )<\/span>\n<span class=\"pl-s\">    &gt;&gt;&gt; float(best_w), round(float(best_score), 4)<\/span>\n<span class=\"pl-s\">    (0.5, 1.0)<\/span>\n<span class=\"pl-s\">    \"\"\"<\/span>\n    <span class=\"pl-k\">if<\/span> <span class=\"pl-c1\">not<\/span> <span class=\"pl-en\">callable<\/span>(<span class=\"pl-s1\">metric<\/span>):\n        <span class=\"pl-k\">raise<\/span> <span class=\"pl-en\">TypeError<\/span>(<span class=\"pl-s\">f\"metric must be callable, not <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-en\">type<\/span>(<span class=\"pl-s1\">metric<\/span>).<span class=\"pl-c1\">__name__<\/span><span class=\"pl-kos\">}<\/span><\/span>.\"<\/span>)\n    <span class=\"pl-k\">if<\/span> (<span class=\"pl-s1\">v_T<\/span> <span class=\"pl-c1\">is<\/span> <span class=\"pl-c1\">None<\/span>) <span class=\"pl-c1\">!=<\/span> (<span class=\"pl-s1\">v_S<\/span> <span class=\"pl-c1\">is<\/span> <span class=\"pl-c1\">None<\/span>):\n        <span class=\"pl-k\">raise<\/span> <span class=\"pl-en\">ValueError<\/span>(<span class=\"pl-s\">\"v_T and v_S are given together or not at all.\"<\/span>)\n\n    <span class=\"pl-s1\">weights<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">arange<\/span>(<span class=\"pl-c1\">0.0<\/span>, <span class=\"pl-c1\">1.0<\/span> <span class=\"pl-c1\">+<\/span> <span class=\"pl-s1\">step<\/span>, <span class=\"pl-s1\">step<\/span>)\n    <span class=\"pl-s1\">best_w<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">None<\/span>\n    <span class=\"pl-s1\">best_score<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">-<\/span><span class=\"pl-en\">float<\/span>(<span class=\"pl-s\">\"inf\"<\/span>) <span class=\"pl-k\">if<\/span> <span class=\"pl-s1\">higher_is_better<\/span> <span class=\"pl-k\">else<\/span> <span class=\"pl-en\">float<\/span>(<span class=\"pl-s\">\"inf\"<\/span>)\n\n    <span class=\"pl-k\">for<\/span> <span class=\"pl-s1\">w<\/span> <span class=\"pl-c1\">in<\/span> <span class=\"pl-s1\">weights<\/span>:\n        <span class=\"pl-c\"># weighted average probability<\/span>\n        <span class=\"pl-s1\">p_hybrid<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">w<\/span> <span class=\"pl-c1\">*<\/span> <span class=\"pl-s1\">p_T<\/span> <span class=\"pl-c1\">+<\/span> (<span class=\"pl-c1\">1<\/span> <span class=\"pl-c1\">-<\/span> <span class=\"pl-s1\">w<\/span>) <span class=\"pl-c1\">*<\/span> <span class=\"pl-s1\">p_S<\/span>\n\n        <span class=\"pl-c\"># the metric scores the single predicted value where both models report one<\/span>\n        <span class=\"pl-k\">if<\/span> <span class=\"pl-s1\">v_T<\/span> <span class=\"pl-c1\">is<\/span> <span class=\"pl-c1\">None<\/span>:\n            <span class=\"pl-s1\">score<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">metric<\/span>(<span class=\"pl-s1\">y_true<\/span>, <span class=\"pl-s1\">p_hybrid<\/span>)\n        <span class=\"pl-k\">else<\/span>:\n            <span class=\"pl-s1\">score<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">metric<\/span>(<span class=\"pl-s1\">y_true<\/span>, <span class=\"pl-en\">hybrid_predict_value<\/span>(<span class=\"pl-s1\">v_T<\/span>, <span class=\"pl-s1\">v_S<\/span>, <span class=\"pl-s1\">p_T<\/span>, <span class=\"pl-s1\">p_S<\/span>, <span class=\"pl-s1\">w<\/span>))\n\n        <span class=\"pl-c\"># keep the best so far<\/span>\n        <span class=\"pl-k\">if<\/span> <span class=\"pl-s1\">higher_is_better<\/span>:\n            <span class=\"pl-k\">if<\/span> <span class=\"pl-s1\">score<\/span> <span class=\"pl-c1\">&gt;<\/span> <span class=\"pl-s1\">best_score<\/span>:\n                <span class=\"pl-s1\">best_score<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">score<\/span>\n                <span class=\"pl-s1\">best_w<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">round<\/span>(<span class=\"pl-s1\">w<\/span>, <span class=\"pl-c1\">4<\/span>)\n        <span class=\"pl-k\">else<\/span>:\n            <span class=\"pl-k\">if<\/span> <span class=\"pl-s1\">score<\/span> <span class=\"pl-c1\">&lt;<\/span> <span class=\"pl-s1\">best_score<\/span>:\n                <span class=\"pl-s1\">best_score<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">score<\/span>\n                <span class=\"pl-s1\">best_w<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">round<\/span>(<span class=\"pl-s1\">w<\/span>, <span class=\"pl-c1\">4<\/span>)\n\n    <span class=\"pl-k\">return<\/span> <span class=\"pl-s1\">best_w<\/span>, <span class=\"pl-s1\">best_score<\/span><\/pre><\/div>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">B.3 Execution Example<\/h3><a id=\"user-content-b3-execution-example\" class=\"anchor\" aria-label=\"Permalink: B.3 Execution Example\" href=\"#b3-execution-example\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<div class=\"highlight highlight-source-python notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"# --- synthetic validation data ---\nnp.random.seed(42)\nN_samples = 1000\n\n# ground truth\ny_true = np.random.randint(0, 2, size=N_samples)\n\n# probability from model T, relatively close to the truth\ny_prob_by_t = y_true * 0.7 + np.random.normal(0, 0.2, size=N_samples)\ny_prob_by_t = np.clip(y_prob_by_t, 0.01, 1)\n\n# probability from model S\ny_prob_by_s = y_true * 0.5 + np.random.normal(0, 0.3, size=N_samples)\ny_prob_by_s = np.clip(y_prob_by_s, 0.01, 1)\n\n# the class each model predicts on its own, at the 0.5 threshold\ny_pred_by_t = (y_prob_by_t &gt;= 0.5).astype(int)\ny_pred_by_s = (y_prob_by_s &gt;= 0.5).astype(int)\n\n# --- the first ten rows of the sample ---\nprint(&quot;y_true     :&quot;, y_true[:10])\nprint(&quot;y_pred_by_t:&quot;, y_pred_by_t[:10])\nprint(&quot;y_pred_by_s:&quot;, y_pred_by_s[:10])\nprint(&quot;y_prob_by_t:&quot;, np.round(y_prob_by_t[:10], 4))\nprint(&quot;y_prob_by_s:&quot;, np.round(y_prob_by_s[:10], 4))\n\n# --- run the grid search ---\n# 1. optimize on F1-score, which needs the threshold the class is read at\nbest_w_f1, best_score_f1 = find_optimal_weight(\n    y_true, y_prob_by_t, y_prob_by_s, metric=ThresholdMetric(f1_score, threshold=0.5)\n)\nprint(f&quot;[F1-Score]  best w: {best_w_f1} | score: {best_score_f1:.4f}&quot;)\n\n# 2. optimize on ROC-AUC\nbest_w_auc, best_score_auc = find_optimal_weight(\n    y_true, y_prob_by_t, y_prob_by_s, metric=roc_auc_score\n)\nprint(f&quot;[ROC-AUC]   best w: {best_w_auc} | score: {best_score_auc:.4f}&quot;)\n\n# 3. optimize on log loss, lower is better\nbest_w_loss, best_score_loss = find_optimal_weight(\n    y_true, y_prob_by_t, y_prob_by_s, metric=log_loss, higher_is_better=False\n)\nprint(f&quot;[Log Loss]  best w: {best_w_loss} | score: {best_score_loss:.4f}&quot;)\n\n# 4. optimize on R-squared, which scores the single predicted value itself\nbest_w_r2, best_score_r2 = find_optimal_weight(\n    y_true, y_prob_by_t, y_prob_by_s, metric=r2_score,\n    v_T=y_pred_by_t, v_S=y_pred_by_s\n)\nprint(f&quot;[R-squared] best w: {best_w_r2} | score: {best_score_r2:.4f}&quot;)\n\n# 5. optimize on MAPE, which scores the same value on a percentage scale\nbest_w_mape, best_score_mape = find_optimal_weight(\n    y_true, y_prob_by_t, y_prob_by_s, metric=mean_absolute_percentage_error,\n    higher_is_better=False, v_T=y_pred_by_t, v_S=y_pred_by_s\n)\nprint(f&quot;[MAPE]      best w: {best_w_mape} | score: {best_score_mape:.4f}&quot;)\n\n# --- the single predicted value at the weight R-squared chose ---\nv_hybrid = hybrid_predict_value(\n    y_pred_by_t, y_pred_by_s, y_prob_by_t, y_prob_by_s, w=best_w_r2\n)\nprint(&quot;v_hybrid   :&quot;, np.round(v_hybrid[:10], 4))\"><pre><span class=\"pl-c\"># --- synthetic validation data ---<\/span>\n<span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">random<\/span>.<span class=\"pl-c1\">seed<\/span>(<span class=\"pl-c1\">42<\/span>)\n<span class=\"pl-v\">N_samples<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">1000<\/span>\n\n<span class=\"pl-c\"># ground truth<\/span>\n<span class=\"pl-s1\">y_true<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">random<\/span>.<span class=\"pl-c1\">randint<\/span>(<span class=\"pl-c1\">0<\/span>, <span class=\"pl-c1\">2<\/span>, <span class=\"pl-s1\">size<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-v\">N_samples<\/span>)\n\n<span class=\"pl-c\"># probability from model T, relatively close to the truth<\/span>\n<span class=\"pl-s1\">y_prob_by_t<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">y_true<\/span> <span class=\"pl-c1\">*<\/span> <span class=\"pl-c1\">0.7<\/span> <span class=\"pl-c1\">+<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">random<\/span>.<span class=\"pl-c1\">normal<\/span>(<span class=\"pl-c1\">0<\/span>, <span class=\"pl-c1\">0.2<\/span>, <span class=\"pl-s1\">size<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-v\">N_samples<\/span>)\n<span class=\"pl-s1\">y_prob_by_t<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">clip<\/span>(<span class=\"pl-s1\">y_prob_by_t<\/span>, <span class=\"pl-c1\">0.01<\/span>, <span class=\"pl-c1\">1<\/span>)\n\n<span class=\"pl-c\"># probability from model S<\/span>\n<span class=\"pl-s1\">y_prob_by_s<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">y_true<\/span> <span class=\"pl-c1\">*<\/span> <span class=\"pl-c1\">0.5<\/span> <span class=\"pl-c1\">+<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">random<\/span>.<span class=\"pl-c1\">normal<\/span>(<span class=\"pl-c1\">0<\/span>, <span class=\"pl-c1\">0.3<\/span>, <span class=\"pl-s1\">size<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-v\">N_samples<\/span>)\n<span class=\"pl-s1\">y_prob_by_s<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">clip<\/span>(<span class=\"pl-s1\">y_prob_by_s<\/span>, <span class=\"pl-c1\">0.01<\/span>, <span class=\"pl-c1\">1<\/span>)\n\n<span class=\"pl-c\"># the class each model predicts on its own, at the 0.5 threshold<\/span>\n<span class=\"pl-s1\">y_pred_by_t<\/span> <span class=\"pl-c1\">=<\/span> (<span class=\"pl-s1\">y_prob_by_t<\/span> <span class=\"pl-c1\">&gt;=<\/span> <span class=\"pl-c1\">0.5<\/span>).<span class=\"pl-c1\">astype<\/span>(<span class=\"pl-s1\">int<\/span>)\n<span class=\"pl-s1\">y_pred_by_s<\/span> <span class=\"pl-c1\">=<\/span> (<span class=\"pl-s1\">y_prob_by_s<\/span> <span class=\"pl-c1\">&gt;=<\/span> <span class=\"pl-c1\">0.5<\/span>).<span class=\"pl-c1\">astype<\/span>(<span class=\"pl-s1\">int<\/span>)\n\n<span class=\"pl-c\"># --- the first ten rows of the sample ---<\/span>\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">\"y_true     :\"<\/span>, <span class=\"pl-s1\">y_true<\/span>&#91;:<span class=\"pl-c1\">10<\/span>&#93;)\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">\"y_pred_by_t:\"<\/span>, <span class=\"pl-s1\">y_pred_by_t<\/span>&#91;:<span class=\"pl-c1\">10<\/span>&#93;)\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">\"y_pred_by_s:\"<\/span>, <span class=\"pl-s1\">y_pred_by_s<\/span>&#91;:<span class=\"pl-c1\">10<\/span>&#93;)\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">\"y_prob_by_t:\"<\/span>, <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">round<\/span>(<span class=\"pl-s1\">y_prob_by_t<\/span>&#91;:<span class=\"pl-c1\">10<\/span>&#93;, <span class=\"pl-c1\">4<\/span>))\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">\"y_prob_by_s:\"<\/span>, <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">round<\/span>(<span class=\"pl-s1\">y_prob_by_s<\/span>&#91;:<span class=\"pl-c1\">10<\/span>&#93;, <span class=\"pl-c1\">4<\/span>))\n\n<span class=\"pl-c\"># --- run the grid search ---<\/span>\n<span class=\"pl-c\"># 1. optimize on F1-score, which needs the threshold the class is read at<\/span>\n<span class=\"pl-s1\">best_w_f1<\/span>, <span class=\"pl-s1\">best_score_f1<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">find_optimal_weight<\/span>(\n    <span class=\"pl-s1\">y_true<\/span>, <span class=\"pl-s1\">y_prob_by_t<\/span>, <span class=\"pl-s1\">y_prob_by_s<\/span>, <span class=\"pl-s1\">metric<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-en\">ThresholdMetric<\/span>(<span class=\"pl-s1\">f1_score<\/span>, <span class=\"pl-s1\">threshold<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-c1\">0.5<\/span>)\n)\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">f\"&#91;F1-Score&#93;  best w: <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">best_w_f1<\/span><span class=\"pl-kos\">}<\/span><\/span> | score: <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">best_score_f1<\/span>:.4f<span class=\"pl-kos\">}<\/span><\/span>\"<\/span>)\n\n<span class=\"pl-c\"># 2. optimize on ROC-AUC<\/span>\n<span class=\"pl-s1\">best_w_auc<\/span>, <span class=\"pl-s1\">best_score_auc<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">find_optimal_weight<\/span>(\n    <span class=\"pl-s1\">y_true<\/span>, <span class=\"pl-s1\">y_prob_by_t<\/span>, <span class=\"pl-s1\">y_prob_by_s<\/span>, <span class=\"pl-s1\">metric<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">roc_auc_score<\/span>\n)\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">f\"&#91;ROC-AUC&#93;   best w: <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">best_w_auc<\/span><span class=\"pl-kos\">}<\/span><\/span> | score: <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">best_score_auc<\/span>:.4f<span class=\"pl-kos\">}<\/span><\/span>\"<\/span>)\n\n<span class=\"pl-c\"># 3. optimize on log loss, lower is better<\/span>\n<span class=\"pl-s1\">best_w_loss<\/span>, <span class=\"pl-s1\">best_score_loss<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">find_optimal_weight<\/span>(\n    <span class=\"pl-s1\">y_true<\/span>, <span class=\"pl-s1\">y_prob_by_t<\/span>, <span class=\"pl-s1\">y_prob_by_s<\/span>, <span class=\"pl-s1\">metric<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">log_loss<\/span>, <span class=\"pl-s1\">higher_is_better<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-c1\">False<\/span>\n)\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">f\"&#91;Log Loss&#93;  best w: <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">best_w_loss<\/span><span class=\"pl-kos\">}<\/span><\/span> | score: <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">best_score_loss<\/span>:.4f<span class=\"pl-kos\">}<\/span><\/span>\"<\/span>)\n\n<span class=\"pl-c\"># 4. optimize on R-squared, which scores the single predicted value itself<\/span>\n<span class=\"pl-s1\">best_w_r2<\/span>, <span class=\"pl-s1\">best_score_r2<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">find_optimal_weight<\/span>(\n    <span class=\"pl-s1\">y_true<\/span>, <span class=\"pl-s1\">y_prob_by_t<\/span>, <span class=\"pl-s1\">y_prob_by_s<\/span>, <span class=\"pl-s1\">metric<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">r2_score<\/span>,\n    <span class=\"pl-s1\">v_T<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">y_pred_by_t<\/span>, <span class=\"pl-s1\">v_S<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">y_pred_by_s<\/span>\n)\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">f\"&#91;R-squared&#93; best w: <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">best_w_r2<\/span><span class=\"pl-kos\">}<\/span><\/span> | score: <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">best_score_r2<\/span>:.4f<span class=\"pl-kos\">}<\/span><\/span>\"<\/span>)\n\n<span class=\"pl-c\"># 5. optimize on MAPE, which scores the same value on a percentage scale<\/span>\n<span class=\"pl-s1\">best_w_mape<\/span>, <span class=\"pl-s1\">best_score_mape<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">find_optimal_weight<\/span>(\n    <span class=\"pl-s1\">y_true<\/span>, <span class=\"pl-s1\">y_prob_by_t<\/span>, <span class=\"pl-s1\">y_prob_by_s<\/span>, <span class=\"pl-s1\">metric<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">mean_absolute_percentage_error<\/span>,\n    <span class=\"pl-s1\">higher_is_better<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-c1\">False<\/span>, <span class=\"pl-s1\">v_T<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">y_pred_by_t<\/span>, <span class=\"pl-s1\">v_S<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">y_pred_by_s<\/span>\n)\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">f\"&#91;MAPE&#93;      best w: <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">best_w_mape<\/span><span class=\"pl-kos\">}<\/span><\/span> | score: <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">best_score_mape<\/span>:.4f<span class=\"pl-kos\">}<\/span><\/span>\"<\/span>)\n\n<span class=\"pl-c\"># --- the single predicted value at the weight R-squared chose ---<\/span>\n<span class=\"pl-s1\">v_hybrid<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">hybrid_predict_value<\/span>(\n    <span class=\"pl-s1\">y_pred_by_t<\/span>, <span class=\"pl-s1\">y_pred_by_s<\/span>, <span class=\"pl-s1\">y_prob_by_t<\/span>, <span class=\"pl-s1\">y_prob_by_s<\/span>, <span class=\"pl-s1\">w<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">best_w_r2<\/span>\n)\n<span class=\"pl-en\">print<\/span>(<span class=\"pl-s\">\"v_hybrid   :\"<\/span>, <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">round<\/span>(<span class=\"pl-s1\">v_hybrid<\/span>&#91;:<span class=\"pl-c1\">10<\/span>&#93;, <span class=\"pl-c1\">4<\/span>))<\/pre><\/div>\n<p dir=\"auto\">\uba3c\uc800 \ucc0d\ud788\ub294 \ub2e4\uc12f \ubc30\uc5f4\uc774 \ud45c\ubcf8\uc758 \uba38\ub9ac \uc5f4 \ud589\uc774\uace0, \uadf8 \ub4a4 \ub2e4\uc12f \uc904\uc774 \ud0d0\uc0c9 \uacb0\uacfc\uc774\uba70, \ub9c8\uc9c0\ub9c9 \uc904\uc774 R-squared \uac00 \uace0\ub978 \uac00\uc911\uce58\uc5d0\uc11c\uc758 \ub2e8\uc77c \uc608\uce21\uac12\uc785\ub2c8\ub2e4. MAPE \uc810\uc218\uac00 1e13 \uc5d0 \uc774\ub974\ub294 \uac83\uc740 <code>y_true<\/code> \uac00 \ub300\ubd80\ubd84\uc758 \ud589\uc5d0\uc11c 0 \uc774\uace0 \uadf8 \uac12\uc73c\ub85c \ub098\ub204\uae30 \ub54c\ubb38\uc774\uba70, \uaf2d\uc9c0 4.2 \uac00 \uc801\uc740 \ub2e8\uc810\uc774 \uadf8\ub300\ub85c \ub4dc\ub7ec\ub09c \uac83\uc785\ub2c8\ub2e4.<\/p>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"y_true     : [0 1 0 0 0 1 0 0 0 1]\ny_pred_by_t: [0 1 0 0 0 1 0 0 0 1]\ny_pred_by_s: [0 1 0 0 0 0 1 0 0 1]\ny_prob_by_t: [0.0684 1.     0.1901 0.01   0.01   0.7984 0.01   0.3663 0.2359 0.6062]\ny_prob_by_s: [0.3905 0.9685 0.01   0.01   0.138  0.2967 0.604  0.041  0.01   0.5554]\n[F1-Score]  best w: 0.78 | score: 0.9174\n[ROC-AUC]   best w: 0.73 | score: 0.9968\n[Log Loss]  best w: 1.0 | score: 0.2542\n[R-squared] best w: 0.7 | score: 0.7127\n[MAPE]      best w: 1.0 | score: 13510798882111.5684\nv_hybrid   : [0.     1.     0.     0.     0.     0.8626 0.9628 0.     0.     1.    ]\"><pre lang=\"text\" class=\"notranslate\"><code>y_true     : &#91;0 1 0 0 0 1 0 0 0 1&#93;\ny_pred_by_t: &#91;0 1 0 0 0 1 0 0 0 1&#93;\ny_pred_by_s: &#91;0 1 0 0 0 0 1 0 0 1&#93;\ny_prob_by_t: &#91;0.0684 1.     0.1901 0.01   0.01   0.7984 0.01   0.3663 0.2359 0.6062&#93;\ny_prob_by_s: &#91;0.3905 0.9685 0.01   0.01   0.138  0.2967 0.604  0.041  0.01   0.5554&#93;\n&#91;F1-Score&#93;  best w: 0.78 | score: 0.9174\n&#91;ROC-AUC&#93;   best w: 0.73 | score: 0.9968\n&#91;Log Loss&#93;  best w: 1.0 | score: 0.2542\n&#91;R-squared&#93; best w: 0.7 | score: 0.7127\n&#91;MAPE&#93;      best w: 1.0 | score: 13510798882111.5684\nv_hybrid   : &#91;0.     1.     0.     0.     0.     0.8626 0.9628 0.     0.     1.    &#93;\n<\/code><\/pre><\/div>\n<\/article><\/div><\/div><\/p>\n<\/div><\/div>\n<\/div><\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n<div style='text-align:center' class='yasr-auto-insert-overall'><\/div><div style='text-align:center' class='yasr-auto-insert-visitor'><\/div>","protected":false},"excerpt":{"rendered":"<p>\ud83c\uddfa\ud83c\uddf8\ud83c\uddf0\ud83c\uddf7  Two models each emit a prediction and a probability. A weighted average of the probabilities gives the class, and the same weights average the predicted values into one. The weight itself comes from a grid search on a validation dataset, scored by F1, ROC-AUC or log loss.<\/p>\n","protected":false},"author":4,"featured_media":7064,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"_kadence_starter_templates_imported_post":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","yasr_overall_rating":0,"yasr_post_is_review":"","yasr_auto_insert_disabled":"","yasr_review_type":"","fifu_image_url":"","fifu_image_alt":"","iawp_total_views":9,"footnotes":""},"categories":[56,392],"tags":[386,426,427],"class_list":["post-7063","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-science-slug","category-models-slug","tag-github-hosted","tag-hybrid","tag-voting"],"yasr_visitor_votes":{"stars_attributes":{"read_only":false,"span_bottom":false},"number_of_votes":1,"sum_votes":4},"jetpack_featured_media_url":"https:\/\/ykim.synology.me\/wordpress\/wp-content\/uploads\/2026\/09\/smartwater-1l-bottles-shelf-brightened.jpg","_links":{"self":[{"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/posts\/7063","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/comments?post=7063"}],"version-history":[{"count":4,"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/posts\/7063\/revisions"}],"predecessor-version":[{"id":7070,"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/posts\/7063\/revisions\/7070"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/media\/7064"}],"wp:attachment":[{"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/media?parent=7063"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/categories?post=7063"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/tags?post=7063"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}