<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Classification on davethehuman.com</title><link>https://davethehuman.com/tags/classification/</link><description>Recent content in Classification on davethehuman.com</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>© 2026 Dave the human</copyright><lastBuildDate>Tue, 13 Oct 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://davethehuman.com/tags/classification/index.xml" rel="self" type="application/rss+xml"/><item><title>softmax</title><link>https://davethehuman.com/notes/softmax/</link><pubDate>Tue, 13 Oct 2026 00:00:00 +0000</pubDate><guid>https://davethehuman.com/notes/softmax/</guid><description>&lt;p&gt;

The &lt;em&gt;softmax&lt;/em&gt; function (also known as &lt;em&gt;&lt;strong&gt;normalized exponential&lt;/strong&gt;&lt;/em&gt;) is a generalization and extension of the &lt;a href="https://davethehuman.com/notes/sigmoid/"&gt;sigmoid&lt;/a&gt; to move from &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;binary classification&lt;/a&gt; to &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;multi-class classification&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It takes a vector of $K$ real numbers (&lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;logits&lt;/a&gt;) and &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;normalizes&lt;/a&gt; it into a &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;probability distribution&lt;/a&gt; consisting of $K$ probabilities proportional to the exponentials of the input numbers.&lt;/p&gt;
&lt;p&gt;For an input vector $\mathbf{z} = (z_1, z_2, \dots, z_K) \in \mathbb{R}^K$, the Softmax function $\sigma(\mathbf{z})_i$ for a specific component $i$ is defined as: &lt;/p&gt;</description></item><item><title>accuracy</title><link>https://davethehuman.com/notes/accuracy/</link><pubDate>Tue, 29 Sep 2026 00:00:00 +0000</pubDate><guid>https://davethehuman.com/notes/accuracy/</guid><description>&lt;p&gt;&lt;em&gt;Accuracy&lt;/em&gt; is the &lt;strong&gt;ratio of the correctly classified observations&lt;/strong&gt;.
In &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;binary classification&lt;/a&gt; settings, it checks the sum of &lt;a href="https://davethehuman.com/notes/tp/"&gt;TP&lt;/a&gt; and &lt;a href="https://davethehuman.com/notes/tn/"&gt;TN&lt;/a&gt; over all the predictions:
&lt;/p&gt;
$$
\mathrm{Accuracy} = \frac{TP + TN}{TP + TN + FP + FN}
$$&lt;p&gt;It is very important to use this metric on datasets that &lt;strong&gt;do not suffer from &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;class imbalance&lt;/a&gt;&lt;/strong&gt;; for example, a model that always predicts &amp;ldquo;False&amp;rdquo; on a dataset having 99.9% of False observations will have a very high 0.999 accuracy score but it won&amp;rsquo;t be meaningful for detecting the True observations.&lt;/p&gt;</description></item><item><title>classification metrics</title><link>https://davethehuman.com/notes/classification-metrics/</link><pubDate>Tue, 29 Sep 2026 00:00:00 +0000</pubDate><guid>https://davethehuman.com/notes/classification-metrics/</guid><description>&lt;p&gt;When building a &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;classifier&lt;/a&gt; we want to minimize the number of misclassified observations.
In &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;binary&lt;/a&gt; cases, we talk about &lt;a href="https://davethehuman.com/notes/tp/"&gt;true positives&lt;/a&gt;, &lt;a href="https://davethehuman.com/notes/fp/"&gt;false positives&lt;/a&gt;, &lt;a href="https://davethehuman.com/notes/tn/"&gt;true negatives&lt;/a&gt; and &lt;a href="https://davethehuman.com/notes/fn/"&gt;false negatives&lt;/a&gt; that can be visualized in a &lt;strong&gt;confusion matrix&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;&lt;figure&gt;&lt;img
 class="my-0 rounded-md"
 loading="lazy"
 decoding="async"
 fetchpriority="auto"
 alt="confusion-matrix"
 width="2400"
 height="1640"
 src="https://davethehuman.com/attachments/confusion-matrix_hu_51d2cad18105cc81.png"
 srcset="https://davethehuman.com/attachments/confusion-matrix_hu_51d2cad18105cc81.png 800w, https://davethehuman.com/attachments/confusion-matrix_hu_bd6c4f8161120a6d.png 1280w"
 sizes="(min-width: 768px) 50vw, 65vw"
 data-zoom-src="https://davethehuman.com/attachments/confusion-matrix.png"&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;The main classification metrics are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://davethehuman.com/notes/accuracy/"&gt;accuracy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://davethehuman.com/notes/precision/"&gt;precision&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://davethehuman.com/notes/recall/"&gt;recall&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://davethehuman.com/notes/fpr/"&gt;false positive rate&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Their usage depends on the classification task.&lt;/p&gt;</description></item><item><title>F1-score</title><link>https://davethehuman.com/notes/f1-score/</link><pubDate>Tue, 29 Sep 2026 00:00:00 +0000</pubDate><guid>https://davethehuman.com/notes/f1-score/</guid><description>&lt;p&gt;&lt;em&gt;F1-score&lt;/em&gt; (also called &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;harmonic mean&lt;/a&gt;) is a &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;metric&lt;/a&gt; that takes into account both &lt;a href="https://davethehuman.com/notes/precision/"&gt;precision&lt;/a&gt; and &lt;a href="https://davethehuman.com/notes/recall/"&gt;recall&lt;/a&gt;:
&lt;/p&gt;
$$
\mathrm{F1} = \frac{2*Precision*Recall}{Precision + Recall}
$$&lt;p&gt;It is widely used in &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;NLP&lt;/a&gt; and it balances precision and recall, handling &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;class imbalance&lt;/a&gt; and highlighting poor performance on minority classes.&lt;/p&gt;</description></item><item><title>FN</title><link>https://davethehuman.com/notes/fn/</link><pubDate>Tue, 29 Sep 2026 00:00:00 +0000</pubDate><guid>https://davethehuman.com/notes/fn/</guid><description>&lt;p&gt;In &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;binary classification&lt;/a&gt;, a &lt;em&gt;False Negative (FN)&lt;/em&gt; is a misclassification of the model that assigns a &amp;ldquo;False&amp;rdquo; label to an observation whose label is actually &amp;ldquo;True&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;Used in the &lt;a href="https://davethehuman.com/notes/classification-metrics/"&gt;classification metrics&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>FP</title><link>https://davethehuman.com/notes/fp/</link><pubDate>Tue, 29 Sep 2026 00:00:00 +0000</pubDate><guid>https://davethehuman.com/notes/fp/</guid><description>&lt;p&gt;In &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;binary classification&lt;/a&gt;, a &lt;em&gt;False Positive (FP)&lt;/em&gt; is a misclassification of the model that assigns a &amp;ldquo;True&amp;rdquo; label to an observation whose actual label is &amp;ldquo;False&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;Used in the &lt;a href="https://davethehuman.com/notes/classification-metrics/"&gt;classification metrics&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>FPR</title><link>https://davethehuman.com/notes/fpr/</link><pubDate>Tue, 29 Sep 2026 00:00:00 +0000</pubDate><guid>https://davethehuman.com/notes/fpr/</guid><description>&lt;p&gt;&lt;em&gt;False Positive Rate (FPR)&lt;/em&gt; is the ratio of &lt;strong&gt;the negative observations that are classified as positives&lt;/strong&gt; (how many &lt;a href="https://davethehuman.com/notes/fp/"&gt;FP&lt;/a&gt; over the sum of &lt;a href="https://davethehuman.com/notes/tp/"&gt;FP&lt;/a&gt; and &lt;a href="https://davethehuman.com/notes/tn/"&gt;FN&lt;/a&gt;):
&lt;/p&gt;
$$
\mathrm{FPR} = \frac{FP}{FP + TN}
$$&lt;p&gt;It is used in &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;ROC-AUC&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>precision</title><link>https://davethehuman.com/notes/precision/</link><pubDate>Tue, 29 Sep 2026 00:00:00 +0000</pubDate><guid>https://davethehuman.com/notes/precision/</guid><description>&lt;p&gt;&lt;em&gt;Precision&lt;/em&gt; is the ratio of &lt;strong&gt;the observation classified as positives that are actually positives&lt;/strong&gt;.
In &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;binary classification&lt;/a&gt; settings, it takes the number of &lt;a href="https://davethehuman.com/notes/tp/"&gt;TP&lt;/a&gt; and divides it by the sum of &lt;a href="https://davethehuman.com/notes/tp/"&gt;TP&lt;/a&gt; and &lt;a href="https://davethehuman.com/notes/fp/"&gt;FP&lt;/a&gt;:
&lt;/p&gt;
$$
\mathrm{Precision} = \frac{TP}{TP + FP}
$$&lt;p&gt;While &lt;a href="https://davethehuman.com/notes/recall/"&gt;recall&lt;/a&gt; uses in the denominator the total number of observations that are actually positives, precision uses the total number of observations that are &lt;strong&gt;classified as positives&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This metric is useful in cases of &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;class imbalance&lt;/a&gt; and when the false positive creates severe inconvenience, financial loss or user distrust; a typical task where precision is used as a &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;metric&lt;/a&gt; is spam detection.&lt;/p&gt;</description></item><item><title>recall</title><link>https://davethehuman.com/notes/recall/</link><pubDate>Tue, 29 Sep 2026 00:00:00 +0000</pubDate><guid>https://davethehuman.com/notes/recall/</guid><description>&lt;p&gt;&lt;em&gt;Recall&lt;/em&gt; is the ratio of &lt;strong&gt;the positive observations that are actually classified as positives&lt;/strong&gt;.
In &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;binary classification&lt;/a&gt; setting, it takes the number of &lt;a href="https://davethehuman.com/notes/tp/"&gt;TP&lt;/a&gt; and divides it by the sum of &lt;a href="https://davethehuman.com/notes/tp/"&gt;TP&lt;/a&gt; and &lt;a href="https://davethehuman.com/notes/fn/"&gt;FN&lt;/a&gt;:
&lt;/p&gt;
$$
\mathrm{Recall} = \frac{TP}{TP + FN}
$$&lt;p&gt;It is also called &lt;a href="https://davethehuman.com/notes/sensitivity/"&gt;sensitivity&lt;/a&gt; or &lt;a href="https://davethehuman.com/notes/tpr/"&gt;true positive rate&lt;/a&gt;. the correctly classified observations.&lt;/p&gt;
&lt;p&gt;While &lt;a href="https://davethehuman.com/notes/precision/"&gt;precision&lt;/a&gt; uses in the denominator the total number of observations classified as positives, recall uses the total number of observations that are &lt;strong&gt;actual positives&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>sensitivity</title><link>https://davethehuman.com/notes/sensitivity/</link><pubDate>Tue, 29 Sep 2026 00:00:00 +0000</pubDate><guid>https://davethehuman.com/notes/sensitivity/</guid><description>&lt;p&gt;See &lt;a href="https://davethehuman.com/notes/recall/"&gt;recall&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>TN</title><link>https://davethehuman.com/notes/tn/</link><pubDate>Tue, 29 Sep 2026 00:00:00 +0000</pubDate><guid>https://davethehuman.com/notes/tn/</guid><description>&lt;p&gt;In &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;binary classification&lt;/a&gt;, a &lt;em&gt;True Negative (TN)&lt;/em&gt; is a correct classification of the model that assigns a &amp;ldquo;False&amp;rdquo; label to an observation whose label is &amp;ldquo;False&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;Used in the &lt;a href="https://davethehuman.com/notes/classification-metrics/"&gt;classification metrics&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>TP</title><link>https://davethehuman.com/notes/tp/</link><pubDate>Tue, 29 Sep 2026 00:00:00 +0000</pubDate><guid>https://davethehuman.com/notes/tp/</guid><description>&lt;p&gt;In &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;binary classification&lt;/a&gt;, a &lt;em&gt;True Positive (TP)&lt;/em&gt; is a correct classification of the model that assigns a &amp;ldquo;True&amp;rdquo; label to an observation whose label is &amp;ldquo;True&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;Used in the &lt;a href="https://davethehuman.com/notes/classification-metrics/"&gt;classification metrics&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>TPR</title><link>https://davethehuman.com/notes/tpr/</link><pubDate>Tue, 29 Sep 2026 00:00:00 +0000</pubDate><guid>https://davethehuman.com/notes/tpr/</guid><description>&lt;p&gt;See &lt;a href="https://davethehuman.com/notes/recall/"&gt;recall&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Logistic Regression</title><link>https://davethehuman.com/notes/logistic-regression/</link><pubDate>Sat, 26 Sep 2026 00:00:00 +0000</pubDate><guid>https://davethehuman.com/notes/logistic-regression/</guid><description>&lt;h2 class="relative group"&gt;Formula
 &lt;div id="formula" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#formula" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h2&gt;
&lt;p&gt;Taking as a reference the &lt;a href="https://davethehuman.com/notes/linear-regression/"&gt;Linear Regression&lt;/a&gt;, in &lt;em&gt;Logistic Regression&lt;/em&gt; the linear output is converted into a probability between 0 and 1 using the &lt;a href="https://davethehuman.com/notes/sigmoid/"&gt;sigmoid&lt;/a&gt; function:&lt;/p&gt;
$$\sigma(z) = \frac{1}{1 + e^{-z}}$$&lt;p&gt;With \(z = \beta_0 + X\beta\) as the linear score, the model&amp;rsquo;s predicted probability is
\(\hat{p} = \sigma(z) = \sigma(\beta_0 + X\beta) = \frac{1}{1 + e^{-(\beta_0 + X\beta)}}\).&lt;/p&gt;</description></item><item><title>sigmoid</title><link>https://davethehuman.com/notes/sigmoid/</link><pubDate>Sat, 26 Sep 2026 00:00:00 +0000</pubDate><guid>https://davethehuman.com/notes/sigmoid/</guid><description>&lt;p&gt;

The &lt;em&gt;sigmoid&lt;/em&gt; function is used in &lt;a href="https://davethehuman.com/notes/logistic-regression/"&gt;Logistic Regression&lt;/a&gt; to transform the linear output in a probability between 0 and 1.&lt;/p&gt;
&lt;p&gt;For a linear score $z = X\beta$, the sigmoid function is: &lt;/p&gt;
$$\sigma(z) = \frac{1}{1 + e^{-z}}$$&lt;p&gt;
&lt;figure&gt;&lt;img
 class="my-0 rounded-md"
 loading="lazy"
 decoding="async"
 fetchpriority="auto"
 alt="sigmoid"
 width="1600"
 height="1100"
 src="https://davethehuman.com/attachments/sigmoid_hu_37d5cdef045797d8.png"
 srcset="https://davethehuman.com/attachments/sigmoid_hu_37d5cdef045797d8.png 800w, https://davethehuman.com/attachments/sigmoid_hu_60910846251427ee.png 1280w"
 sizes="(min-width: 768px) 50vw, 65vw"
 data-zoom-src="https://davethehuman.com/attachments/sigmoid.png"&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;When negative values are also needed while keeping the sigmoid&amp;rsquo;s smooth, bounded output, &lt;a href="https://davethehuman.com/notes/tanh/"&gt;tanh&lt;/a&gt; is used.&lt;/p&gt;

&lt;h2 class="relative group"&gt;Implementation
 &lt;div id="implementation" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#implementation" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h2&gt;
&lt;p&gt;A correct implementation of sigmoid has two branches: one for negative values and one for positive values.&lt;br&gt;
The original formula at the top of the page is correct for every &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;real number&lt;/a&gt;, but a computer has a largest representable floating-point value that can lead to overflow with exponential operation on large positive numbers.&lt;/p&gt;</description></item></channel></rss>