<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Christopher Bryant on Medium]]></title>
        <description><![CDATA[Stories by Christopher Bryant on Medium]]></description>
        <link>https://medium.com/@chrismbryant?source=rss-17f92bd83da6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Re-on_NWf8DTMrMbsdOA1A.jpeg</url>
            <title>Stories by Christopher Bryant on Medium</title>
            <link>https://medium.com/@chrismbryant?source=rss-17f92bd83da6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 16:25:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chrismbryant/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Choosing the Right Model Threshold]]></title>
            <link>https://medium.com/acorns-data-blog/choosing-the-right-model-threshold-a91bc48f354?source=rss-17f92bd83da6------2</link>
            <guid isPermaLink="false">https://medium.com/p/a91bc48f354</guid>
            <dc:creator><![CDATA[Christopher Bryant]]></dc:creator>
            <pubDate>Fri, 11 Dec 2020 19:25:08 GMT</pubDate>
            <atom:updated>2020-12-11T19:25:08.896Z</atom:updated>
            <content:encoded><![CDATA[<p><em>by </em><a href="https://www.linkedin.com/in/chris-m-bryant/"><em>Christopher Bryant</em></a><em> </em>|<em> Sr. Data Scientist at Acorns</em></p><p><em>Acorns is the country’s fastest-growing saving and investing app helping more than 8 million people save and invest for the future. Our Data Scientists are on the forefront of innovation, designing algorithms and experiments that help shape each product and customer experience. If that sounds like you, </em><a href="https://www.acorns.com/careers/"><em>click here</em></a><em> to learn more about joining our team!</em></p><p>In this post, we’ll explore the tradeoffs involved in choosing an operating point for a classification model, and what that choice implies about how we value different kinds of mistakes our model can make. To accompany this post and help intuitively understand the impact that different factors have on the optimal operating point, we’ve created an interactive “binary classification playground” desktop visualization which you can visit <a href="https://chrismbryant.github.io/binary-classification-playground/"><strong>here</strong></a>.</p><ol><li><a href="#a9d1">Introduction</a></li><li><a href="#9a4f">Binary Classification</a></li><li><a href="#2d8c">Cost Optimization</a></li><li><a href="#672c">Generalization</a></li><li><a href="#ee89">Conclusion</a></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*1TYM9RH5mcgGyNuLSzl7pg@2x.gif" /><figcaption>Move the sliders in our “Binary Classification Playground” to see the impact of changing a model output distribution or operating costs.</figcaption></figure><h3>Introduction</h3><p><a href="https://scikit-learn.org/stable/auto_examples/model_selection/plot_precision_recall.html">Precision-Recall</a> and <a href="https://en.wikipedia.org/wiki/Receiver_operating_characteristic">ROC curves</a> are great tools to help a data science practitioner understand the performance of a classification model across its operating spectrum, but it can be difficult to communicate the operating tradeoffs of a model to someone who isn’t deeply involved with the data. If you try to ask someone to conceptualize business performance tradeoffs using quantities like “true positive rate”, “false positive rate”, “false discovery rate”, etc., you may end up lost in confusing terminology. You can explain that decreasing the number of false positive cases will increase the number of false negative cases, and vice versa, but if you’re not very careful, you may still end up choosing a model operating point that conflicts with your basic assumptions about the problem. We propose a simpler approach: list out your operating costs, and let the optimal decision emerge.</p><h3>Binary Classification</h3><p>When we use machine learning for binary classification, our goal is to categorize data into one of two classes based on some underlying distribution of labeled data. Typically, any binary classifier we build — whether we use logistic regression, a gradient boosted trees model, or some complicated neural network — will output a probability score between 0 and 1 (or some real-valued score that can be converted into a probability), rather than a hard label<a href="#0397">¹</a> equal to 0 or 1. The standard process for turning a probability into a 0 or 1 prediction is simply to create a “decision boundary” at 0.5, rounding the probability up to 1 if it is ≥ 0.5, and rounding down to 0 if it’s &lt; 0.5. While this may feel natural, blindly choosing a model operating point of 0.5 can be a dangerous move to make.</p><p>In a data science team, each classification prediction is really a business recommendation, whether that recommendation is to show a user an ad for a new service, reject a defective product from a manufacturing assembly line, or decline a transaction for fraud. We need to make sure that whatever threshold we choose to operate our models at, we’re producing the best possible recommendations for our customers and our business.</p><p>Consider, for example, a hypothetical model which scores credit card transactions to predict whether each transaction is fraudulent. Any transaction with a probability above the operating threshold would get flagged as “fraudulent” and declined. How confident should we be that a transaction is fraudulent before we flag it as fraud? If we choose a low threshold like 0.1, we would catch almost every fraudulent transaction, but we would end up declining many valid transactions that should be let through. Conversely, if we choose a high threshold like 0.9, we would allow many more valid transactions, but we would also miss more fraudulent transactions. The model itself can’t prescribe the best balance between these two scenarios, so managing this trade-off by choosing an operating point will always be a business decision. <em>How, then, can we empower a business manager to make that decision in a systematic way?</em></p><p>At this point, it is useful to consider the <a href="https://en.wikipedia.org/wiki/Confusion_matrix">confusion matrix</a> of possibilities for a chosen operating threshold.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*2X-IL8DzXvvsnUIZG1umQw@2x.png" /><figcaption>For a single model, each threshold choice produces a different confusion matrix.</figcaption></figure><p>The elements on the diagonal of the confusion matrix represent the “happy path” cases—true positive (TP) and true negative (TN)—whereas the off-diagonal elements represent our model failure cases— false positive (FP) and false negative (FN). In the fraud example:</p><ul><li>a <strong>TP case</strong> is a fraudulent transaction which is correctly declined.</li><li>a <strong>TN case</strong> is a non-fraudulent transaction which is correctly ignored.</li><li>a <strong>FP case </strong>is a non-fraudulent transaction which is <em>incorrectly</em> declined (should have been ignored).</li><li>a <strong>FN case </strong>is a fraudulent transaction which is <em>incorrectly</em> ignored (should have been declined).</li></ul><p>To understand how we should best minimize the harm of misclassification, we first have to decide quantitatively how bad it is to suffer each kind of error, FP and FN. From there, we can formulate a new optimization problem. (If you want to skip the math and jump straight to the solution, you can go to the <a href="#ee89"><strong><em>Conclusion</em></strong></a> section.)</p><h3>Cost Optimization</h3><p>Our goal is to choose a threshold value which minimizes our total operating cost given a fixed model. We’ll start by creating a cost function, <em>C</em>(<em>t</em>), which sums together the “costs” associated with each type of classification error on a fixed data set of <em>N</em> examples, given our choice of threshold value <em>t</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*qStrw7Ane__YLCAYnTxj2A@2x.png" /></figure><p>where</p><ul><li><em>kₓ</em>: the cost<em> </em>of one error of type <em>x </em>∈<em> </em>{FP<em>, </em>FN} <a href="#b9d6">²</a>.</li><li><em>Nₓ</em>(<em>t</em>): the number of examples our model misclassified with error type <em>x</em>, given an operating threshold <em>t</em>.</li></ul><p>It can be helpful to think about the <em>kₓ </em>values in terms of dollar figures (so that <em>k_FP</em> dollars are lost for every FP case and <em>k_FN </em>dollars are lost for every FN case), but they can represent any kind of harm as long as their relative harm is quantifiable. What’s important to keep in mind here is that those two costs are <em>not necessarily the same</em>.</p><p>Equipped with an expression for cost, we can find the threshold value which minimizes it in the same way we would in any other 1-dimensional convex optimization problem — take the derivative <em>C</em>′(<em>t</em>), and find the value<em> t = τ</em> where <em>C</em>′(<em>t</em>) is 0:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*E1woB2PEIg7is-1_PagJEg@2x.png" /></figure><p>To evaluate this derivative, we need to rewrite our <em>Nₓ</em>(<em>t</em>) expressions so that they are in terms of quantities we can differentiate.<em> </em>To do this, let’s define a new function <em>f</em>(<em>s</em>) to be the probability density distribution of <em>model output scores</em> we would see if we applied the model to a representative dataset from the wild<a href="#36c4">³</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*SnCQsZvxqenMf6j1PlwLng@2x.png" /><figcaption>Example model score distributions f(s), f(s, y = 0), and f(s, <em>y</em> = 1).</figcaption></figure><p>Since f(s) is a probability distribution, by definition, this function integrated over all possible output scores evaluates to 1:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/218/1*_Ub8IGrBArVe8NMTCw7azg@2x.png" /></figure><p>Likewise, the marginal distribution <em>f</em>(<em>s, y </em>= 1) of examples with a positive class label (i.e. <em>y</em> = 1), when integrated over all possible scores, yields the fraction of all <em>N</em> examples which have an actual positive class label<a href="#fe7a">⁴</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*3As1uS9bLvFICdx8zayz2Q@2x.png" /></figure><p>By dividing <em>f</em>(<em>s, y </em>= 1) by <em>f</em>(<em>s</em>), we obtain the model’s <a href="https://scikit-learn.org/stable/modules/calibration.html#:~:text=Probability%20calibration,-When%20performing%20classification&amp;text=The%20calibration%20module%20allows%20you,interpreted%20as%20a%20confidence%20level."><strong>probability calibration curve</strong></a> <em>P</em>(<em>s</em>), which tells us the probability of an example having a true label of 1, given that it received a model score of <em>s</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*bZxELCpA7eyuTZJglcp0Tw@2x.png" /><figcaption>Left: Probability calibration curve P(s) definition; Right: Example P(s) curve.</figcaption></figure><p>Knowing <em>P</em>(<em>s</em>) is important because even if your classification model generates values that <em>look</em> like probabilities (i.e. are between 0 and 1), they may not represent <em>true</em> probabilities. You may find that on average, for instance, cases assigned a prediction value of 0.80 only have an actual positive label 70% of the time rather than 80% of the time.</p><p>We say that a model’s outputs are <em>well-calibrated</em> when each model score value matches the observed fraction of actual positive cases at that score; i.e. a well-calibrated <em>P</em>(<em>s</em>) is a straight line connecting (0, 0) to (1, 1). A probability calibration curve allows us to talk about model probabilities even if our model output space isn’t constrained to lie between 0 and 1, so our analysis here will hold for any process that generates a real-valued output<a href="#f375">⁵</a>.</p><p>By integrating the positive label distribution <em>f</em>(<em>s</em>, <em>y</em> = 1) only up to our threshold value <em>t</em>, we can derive an expression for the number of FN cases (predicted-negative, but actually-positive) our model generates:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/276/1*h4xKj-Bwj3jqh5US2n0fiA@2x.png" /></figure><p>Through similar logic, we can also obtain an expression for the number of FP cases:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/1*38Eh97ngpkAt9lvzP6ka2A@2x.png" /></figure><p>Now, using the <a href="https://en.wikipedia.org/wiki/Fundamental_theorem_of_calculus#First_part">first fundamental theorem of calculus</a>, we can evaluate the derivatives we care about<a href="#e2ea">⁶</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*679F5qlcucNbiu_I9HILow@2x.png" /></figure><p>We can plug those into <em>C</em>′(<em>t</em>) and rearrange the terms to find the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/1*ndOhorTfX0ekibbfNXRFcQ@2x.png" /></figure><p>By choosing a <em>t</em> = <em>τ</em> which sets <em>C</em>′(<em>t</em>) to 0, we arrive at the condition which optimizes the cost function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/209/1*Z2exiOQQxqE2XWcYP_iJCA@2x.png" /></figure><p>Our optimal threshold <em>τ</em> is the threshold at which the calibrated model probability equals the ratio of {<em>cost per false positive</em>} to {<em>cost per false positive</em> + <em>cost per false negative</em>}. (Technically, we’ve only shown here that <em>C</em>(<em>τ</em>) is a critical point, not a <em>minimum</em>, and we’ve ignored the trivial solution where <em>f</em>(<em>t</em>) = 0. We provide a more general proof and verify that <em>P</em>(<em>τ</em>) does in fact produce a minimum in the <a href="#672c">next section</a>).</p><p>Thus, when we choose to operate a model at a probability decision boundary <em>P</em>(<em>τ</em>) = 0.5, this solution implies that we actually consider the two types of misclassification costs as <em>equal</em>. Similarly, if we operate a model at <em>P</em>(<em>τ</em>) = 0.9, we implicitly optimize for the underlying assumption that a FP case is <em>9 times as bad </em>as a FN case, or in other words, that a single FP misclassification error costs the same amount as 9 FN misclassification errors. It’s now clear that blindly choosing a threshold of 0.5 can be dangerous if one type of misclassification error is much worse than the other or if your model’s outputs aren’t well-calibrated probabilities.</p><h3>Generalization</h3><p>In the derivation above, we only considered the cost of classifying a case incorrectly, but for some problems, we might also want to factor in other aspects of the confusion matrix of possibilities. For instance, we may want to consider the <em>benefit</em> of classifying a case correctly (e.g. if there is some revenue associated with every TP case), or the cost of reviewing a flagged case (e.g. if each predicted-positive case requires expensive secondary processing or manual review).</p><p>To account for these other costs and benefits, let’s create a new cost function, <em>C</em>(<em>t</em>), by extending the one we defined earlier. Here, we <em>subtract</em> out the “benefit” received from each TP and TN case (since higher values of <em>C</em>(<em>t</em>) should correspond to worse outcomes), and add in the cost of reviewing each flagged case<a href="#34d7">⁷</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*y1zWXbKLAv7C6hr1-IV0Qw@2x.png" /></figure><p>where</p><ul><li><em>k_TP</em>: the <em>benefit </em>provided by each TP case.</li><li><em>k_TN</em>: the <em>benefit</em> provided by each TN case.</li><li><em>k_rev</em>: the <em>cost</em> of reviewing each flagged (predicted-positive) case.</li></ul><p>We also included new <em>Nₓ</em>(<em>t</em>) expressions for the TP and TN cases. Like before, we will need to represent each <em>Nₓ</em>(<em>t</em>) in a form we can differentiate. Expanding them in terms of <em>P</em>(<em>s</em>) and <em>f</em>(<em>s</em>), we get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*PsMoZZHRTxKarqggoerK3g@2x.png" /></figure><p>Differentiating them, we get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/1*Ub7ovE4vtFDo-UqDRIV1wA@2x.png" /></figure><p>Notice that the derivatives of the TP and FN expressions sum to 0:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/217/1*bnbBAi-kje2ouhWUVL0qyA@2x.png" /></figure><p>This reflects the fact that our choice of threshold doesn’t change how many cases have an actual positive class label. As we increase the threshold, TP cases turn into FN cases with a 1:1 correspondence (their rates of change are equal and opposite). By the same logic, this relationship also holds between FP and TN cases:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/210/1*GzHvIHrWADtgcWpsn43rcw@2x.png" /></figure><p>We can now differentiate <em>C</em>(<em>t</em>) and use the above relationships to reduce <em>C</em>′(<em>t</em>) into a familiar form:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*QC8J1VWraDJu6TLGKgJ3Bg@2x.png" /></figure><p>From here, we can plug in the <em>Nₓ</em>(<em>t</em>) derivatives, and rearrange terms:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*VPKHax0xTvD0tfkJsrKY3w@2x.png" /></figure><p>When we set <em>C</em>′(<em>t</em>) = 0, we find two distinct solutions, only one of which actually depends on our cost coefficients:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*NqouvUqy83zs14nQPvsFIw@2x.png" /></figure><p>To assess what kind of critical points these solutions present, we have to understand the concavity of <em>C</em>(<em>t</em>) at each of these points; i.e. we have to take another derivative. Let’s start by defining new non-negative constants <em>a</em> and <em>b</em> to simplify our notation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/255/1*O4u47krN6MUe7uqWDRr6Yg@2x.png" /></figure><p>Rewriting C′(t) with these constants, we get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/243/1*7tchoJHB3AN_qUXpA-fFSg@2x.png" /></figure><p>We then differentiate using the product rule:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*xQUL4spMHYQWXefawmwEjQ@2x.png" /></figure><p>Evaluating this at our first solution, we find a somewhat complicated expression:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/466/1*zSvuquVfSnvhadXeLdaDow@2x.png" /></figure><p>To understand what this expression implies, we have to consider what a reasonable score distribution <em>f</em>(<em>s</em>) and probability calibration function <em>P</em>(<em>t</em>) look like. Recall that we assumed <em>f</em>(<em>s</em>) to be a differentiable probability distribution over the domain of possible model output scores. It could equal zero at any number of points within that domain. Since <em>f</em>(<em>s</em>) is smooth and can never go negative, any zero point within the distribution must also be a local minimum, making C′′ evaluate to 0; i.e. zeros of <em>f</em>(<em>s</em>) within the distribution generate inflection points in <em>C</em>(<em>t</em>), not minima or maxima.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*TbgCNuSDdJZU2ktN0Z7mJg@2x.png" /><figcaption>Example model score distribution f(s) and probability calibration curve P(s).</figcaption></figure><p>However, if <em>f</em>(<em>s</em>) is defined over a bounded domain and it vanishes at the extrema of <em>s</em>, its slope at the extrema is not necessarily 0. This is where we must consider the behavior of <em>P</em>(<em>s</em>). Any reasonable probability calibration function is monotonically increasing, meaning that higher score values always correspond to higher probabilities. If your model scores don’t produce this behavior, it isn’t doing a good job at modeling the distribution of your labeled data. At its lowest and highest <em>s</em> values, <em>P</em>(<em>s</em>) should be 0 and 1 (or at least close to 0 and 1), respectively.</p><p>Given our assumptions about reasonable probability calibration functions, if we evaluate our C′′ solution at <em>s_min</em> (the lowest possible value of <em>s</em>), we see the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*euSAzkVP00IFVVBErzzbKQ@2x.png" /></figure><p>At <em>s_min</em>,<em> f</em>′(<em>s</em>) must be ≥ 0, so since <em>b</em> ≥ 0, it must be the case that C′′ ≤ 0 if <em>f</em>(<em>s_min</em>) = 0; i.e. predicting every case as positive can only produce a maximum or inflection point.</p><p>On the other end of the distribution, suppose <em>f</em>(<em>s</em>) vanishes at <em>s_max</em> (the highest possible value of <em>s</em>). By substituting <em>P</em>(<em>s_max</em>) ≈ 1 into our expression for C′′, we see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*DIaata4lbx5AUSmFjTYcxA@2x.png" /></figure><p>At <em>s_max</em>,<em> f</em>′(<em>s</em>) must be ≤ 0, so it must be the case that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*kEdZ6aOuVi0ahIb7zK809Q@2x.png" /></figure><p>This means that a strategy of predicting every case as negative can only minimize total operating costs if the act of reviewing an actual positive case is more costly (even after considering the TP reward gained from assigning the correct prediction) than the FN cost incurred from ignoring it.</p><p>With the <em>τ₀</em> solutions understood, we can now turn to the non-trivial solution at <em>τ₁</em>. Plugging in <em>b</em>/<em>a</em> for <em>P</em>(<em>τ₁</em>), the <em>C</em>′′ at the critical point reduces like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*NmgyCwuzov0YpWoWcsIUUQ@2x.png" /></figure><p>The function <em>f</em>(<em>t</em>) is guaranteed to be nonnegative everywhere since it is a probability distribution. If we assume that there is at least <em>some</em> data density at the critical point, then our concavity condition becomes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/285/1*g1pBL_UG9oLCsNASdCSYYw@2x.png" /></figure><p>Thus, since any reasonable probability calibration function is strictly increasing, the optimal threshold we found will always <em>minimize</em> the cost. What we’ve shown here is a specific form of an <a href="http://www.cs.utexas.edu/~inderjit/public_papers/consistent_binaryclassification_nips2014.pdf">even more general proof</a> from Koyejo et al. on optimal binary classification metrics (our special case, if we exclude the “review cost”, <em>k_rev</em>, is <em>Corollary 4</em> in that paper)<a href="#c43a">⁸</a>.</p><h3>Conclusion</h3><p>To find the best operating point for a binary classification model, you need to have a good understanding of what all your operating costs and benefits are. Each mistake your model makes has a cost associated with it, and that cost may differ depending on the type of mistake the model makes, whether it’s flagging a case it should have ignored or failing to flag a case it <em>shouldn’t</em> have ignored. Additionally, the very act of flagging cases, regardless of their correctness, may introduce a secondary review cost that adds to your total costs. On the other hand, each correct prediction your model makes can have a benefit that offsets some of your operating costs. When considered together, these quantities tell you how much it costs to operate your model at each possible decision threshold.</p><p>A business manager can inform your choice of operating threshold by helping answer these questions:</p><ol><li>How much does one <strong>false positive</strong> case cost? (= <em>k_FP</em>)</li><li>How much does one <strong>false negative </strong>case cost? (= <em>k_FN</em>)</li><li>How much is one <strong>true positive </strong>case worth? (= <em>k_TP</em>)</li><li>How much is one <strong>true negative</strong> case worth? (= <em>k_TN</em>)</li><li>How much does it cost to <strong>review</strong> one flagged case (= <em>k_rev</em>)</li></ol><p>Once you can quantify each of these values, choosing the optimal operating point is a matter of locating the model score threshold <em>τ</em> at which the probability <em>P</em>(<em>τ</em>) of finding a positive label is the following ratio:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*nemDGs_yLQxZaL8eC5q84w@2x.png" /></figure><h4>Acknowledgements</h4><p>Thank you to my colleagues on the Acorns Data Science Team for their help structuring the contents of this post and for adding mathematical rigor to the problems discussed within.</p><h4>Footnotes</h4><ol><li><a href="#fda2"><strong>˄</strong></a> Some notable exceptions which only produce strict binary scores are <a href="https://en.wikipedia.org/wiki/Support_vector_machine#Hard-margin">hard-margin SVMs</a> and some <a href="https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm">nearest neighbor algorithms</a>.</li><li><a href="#9c62"><strong>˄</strong></a><strong> </strong>Throughout this post, we assume that each <em>kₓ </em>is a constant which does not depend at all on the data. In some use cases, this may not be a reasonable assumption. For example, a large-dollar FN fraud case may cause more harm than a small-dollar FN fraud case. If your misclassification costs vary with your data, you can still construct a <em>C</em>(<em>t</em>) by treating the product of <em>kₓ </em>and <em>Nₓ </em>as a vector dot product rather<em> </em>than a scalar product, where each element of the vector corresponds to a single example. Rather than finding the minimum of <em>C</em>(<em>t</em>) analytically, you would compute it empirically on a test set of model outputs.</li><li><a href="#f94a"><strong>˄</strong></a><strong> </strong>In practice, we can estimate <em>f</em>(<em>s</em>) empirically with a discrete histogram of model scores from a test set of examples, but we’ll assume here that <em>f</em>(<em>s</em>) represents a smooth (at least once-differentiable) theoretical distribution defined over the domain of all possible output scores for a given model.</li><li><a href="#923a"><strong>˄</strong></a><strong> </strong>This is only exactly true in the limit as <em>N</em> approaches infinity, so what we present is technically an approximation. For the sake of simplicity, in this post, we assume we’re working in the <em>N</em> → ∞ domain where all described functions are smooth and approximations are exact.</li><li><a href="#670e"><strong>˄</strong></a><strong> </strong>How to construct a probability calibration curve is beyond the scope of this post, but to give you a sense of the process, consider binning model output scores into a number of regions (e.g. group scores between 0 and 0.1, then between 0.1 and 0.2, etc.). If you measure what proportion of cases have a positive label within each of your regions, you have an approximate mapping between model “score” and calibrated “probability” across the range of possible model scores. Finding the inverse mapping from a probability value to an approximate model score would amount to finding the score bin which has a proportion of positive cases <em>closest</em> to the target probability. For further reading on probability calibration, see <a href="https://www.cs.cornell.edu/~alexn/papers/calibration.icml05.crc.rev3.pdf">Predicting Good Probabilities With Supervised Learning</a> (Niculescu-Mizil &amp; Caruana, 2005).</li><li><a href="#130d"><strong>˄</strong></a><strong> </strong>Technically, this theorem only applies to closed intervals. In practice, model output scores have some minimum and maximum value, though, so we can say that the upper bound of integration ∞ is really just some finite but possibly very large value.</li><li><a href="#0ebd"><strong>˄</strong></a><strong> </strong>We assume that the review process associated with predicted-positive cases doesn’t substantially impact any of the <em>Nₓ</em>(<em>t</em>) counts, but in practice, a secondary review process typically reclassifies some predicted-positive cases as predicted-negative cases, possibly decreasing the TP and FP counts and increasing the TN and FN counts. Assessing this possible interaction is beyond the scope of this post, so we will consider the interaction to be negligible here and allow <em>k_rev</em> to be a constant.</li><li><a href="#1916"><strong>˄</strong></a><strong> </strong>Oluwasanmi O. Koyejo, Nagarajan Natarajan, Pradeep K. Ravikumar, Inderjit S. Dhillon. <a href="http://www.cs.utexas.edu/~inderjit/public_papers/consistent_binaryclassification_nips2014.pdf">Consistent Binary Classification with Generalized Performance Metrics</a>. <em>Advances in Neural Information Processing Systems 27</em>, 2014.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a91bc48f354" width="1" height="1" alt=""><hr><p><a href="https://medium.com/acorns-data-blog/choosing-the-right-model-threshold-a91bc48f354">Choosing the Right Model Threshold</a> was originally published in <a href="https://medium.com/acorns-data-blog">Acorns Data Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>