<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>confusion matrix Archives - Creatronix</title>
	<atom:link href="https://creatronix.de/tag/confusion-matrix/feed/" rel="self" type="application/rss+xml" />
	<link>https://creatronix.de/tag/confusion-matrix/</link>
	<description>My adventures in code &#38; business</description>
	<lastBuildDate>Sun, 05 Jan 2025 10:32:39 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>
	<item>
		<title>Confusion Matrix</title>
		<link>https://creatronix.de/confusion-matrix/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Tue, 03 Jul 2018 10:51:38 +0000</pubDate>
				<category><![CDATA[Data Science & SQL]]></category>
		<category><![CDATA[confusion matrix]]></category>
		<category><![CDATA[dog]]></category>
		<category><![CDATA[false positive]]></category>
		<category><![CDATA[sklearn]]></category>
		<category><![CDATA[true positive]]></category>
		<guid isPermaLink="false">http://creatronix.de/?p=1688</guid>

					<description><![CDATA[<p>Too confused of the confusion matrix? Let me bring some clarity into this topic! Let&#8217;s take the example from Precision and Recall: y_true = ["dog", "dog", "non-dog", "non-dog", "dog", "dog"] y_pred = ["dog", "non-dog", "dog", "non-dog", "dog", "non-dog"] When we look at the prediction we can count the correct and incorrect classifications: dog correctly classified&#8230;</p>
<p>The post <a href="https://creatronix.de/confusion-matrix/">Confusion Matrix</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Too confused of the confusion matrix?</h2>
<p>Let me bring some clarity into this topic!</p>
<p>Let&#8217;s take the example from <a href="https://creatronix.de/classification-precision-and-recall/">Precision and Recall:</a></p>
<pre>y_true = ["dog", "dog",     "non-dog", "non-dog", "dog", "dog"]
y_pred = ["dog", "non-dog", "dog",     "non-dog", "dog", "non-dog"]</pre>
<p>When we look at the prediction we can count the correct and incorrect classifications:</p>
<ul>
<li>dog correctly classified as dog: 2 times (True Positive)</li>
<li>non-dog incorrectly classified as dog: 1 time (False Positive)</li>
<li>dog incorrectly classified as non-dog: 2 times (False Negative)</li>
<li>non-dog correctly classified as non-dog: 1 time (True Negative)</li>
</ul>
<p>When we visualize these results in a matrix we already have the confusion matrix:<br />
<img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-1690" src="https://creatronix.de/wp-content/uploads/2018/07/confusion_matrix.png" alt="" width="479" height="480" srcset="https://creatronix.de/wp-content/uploads/2018/07/confusion_matrix.png 479w, https://creatronix.de/wp-content/uploads/2018/07/confusion_matrix-150x150.png 150w, https://creatronix.de/wp-content/uploads/2018/07/confusion_matrix-300x300.png 300w, https://creatronix.de/wp-content/uploads/2018/07/confusion_matrix-100x100.png 100w" sizes="(max-width: 479px) 100vw, 479px" /></p>
<h2>sklearn</h2>
<p>We can calculate the confusion matrix with sklearn in a very simple manner</p>
<pre>from sklearn.metrics import confusion_matrix
print(confusion_matrix(y_true, y_pred, labels=["dog", "non-dog"]))
</pre>
<p>the output is:</p>
<pre>[[2 2]
[1 1]]</pre>
<p>which can be indeed confusing because the matrix is transposed. In contrast to our matrix from above the columns are the prediction and the rows are the actual values:</p>
<p><img decoding="async" class="alignnone size-full wp-image-1692" src="https://creatronix.de/wp-content/uploads/2018/07/confusion_matrix_2.png" alt="" width="479" height="480" srcset="https://creatronix.de/wp-content/uploads/2018/07/confusion_matrix_2.png 479w, https://creatronix.de/wp-content/uploads/2018/07/confusion_matrix_2-150x150.png 150w, https://creatronix.de/wp-content/uploads/2018/07/confusion_matrix_2-300x300.png 300w, https://creatronix.de/wp-content/uploads/2018/07/confusion_matrix_2-100x100.png 100w" sizes="(max-width: 479px) 100vw, 479px" /></p>
<p>And that&#8217;s all &#8211; if you just have a binary classifier.</p>
<h2>Multi-label classifier</h2>
<p>So what happens, when your classifier can decide between three outcomes, say dog, cat and rabbit? (You can generate the test data with <a href="https://creatronix.de/numpy-random-choice/">numpy random choice</a>)</p>
<pre>y_true = ['rabbit', 'dog', 'rabbit', 'cat', 'cat', 'cat', 'cat', 'dog', 'cat']
y_pred = ['rabbit', 'rabbit', 'dog', 'cat', 'dog', 'rabbit', 'dog', 'cat', 'dog']

cm = confusion_matrix(y_true, y_pred, labels=["dog", "rabbit", "cat"])</pre>
<pre>[[0 1 1]
[1 1 0]
[3 1 1]]</pre>
<p>The post <a href="https://creatronix.de/confusion-matrix/">Confusion Matrix</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
