{"id":65,"date":"2023-09-01T08:51:00","date_gmt":"2023-09-01T08:51:00","guid":{"rendered":"https:\/\/amirhooshang.com\/blog\/?p=65"},"modified":"2025-05-16T20:57:22","modified_gmt":"2025-05-16T20:57:22","slug":"evaluation-metrics-for-machine-learning-classification-models-from-accuracy-to-roc-auc","status":"publish","type":"post","link":"https:\/\/amirhooshang.com\/blog\/2023\/09\/01\/evaluation-metrics-for-machine-learning-classification-models-from-accuracy-to-roc-auc\/","title":{"rendered":"Evaluation Metrics for Machine Learning Classification Models: From Accuracy to ROC-AUC"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\"><\/h3>\n\n\n\n<p> Imagine you\u2019ve built a machine learning model to detect cancer from medical scans or filter spam emails. How do you know if it\u2019s actually working well? <strong>Evaluation metrics<\/strong> act like a report card for your model\u2014they tell you where it\u2019s crushing it and where it\u2019s falling short. In this article, we\u2019ll break down the key metrics for classification models and explain when to use them.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Accuracy \u2013 The Basic &#8220;Passing Grade&#8221;<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>What is it?<\/strong> The percentage of correct predictions. For example, if your model correctly labels 95 out of 100 cat\/dog images, its accuracy is 95%.<\/li>\n\n\n\n<li><strong>Formula:<\/strong><br><p class=\"ql-center-displayed-equation\" style=\"line-height: 37px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/amirhooshang.com\/blog\/wp-content\/ql-cache\/quicklatex.com-77a0c99430e561225f92bbb98384ec28_l3.png\" height=\"37\" width=\"249\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#91;&#92;&#116;&#101;&#120;&#116;&#123;&#65;&#99;&#99;&#117;&#114;&#97;&#99;&#121;&#125;&#32;&#61;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#92;&#116;&#101;&#120;&#116;&#123;&#67;&#111;&#114;&#114;&#101;&#99;&#116;&#32;&#80;&#114;&#101;&#100;&#105;&#99;&#116;&#105;&#111;&#110;&#115;&#125;&#125;&#123;&#92;&#116;&#101;&#120;&#116;&#123;&#84;&#111;&#116;&#97;&#108;&#32;&#68;&#97;&#116;&#97;&#125;&#125;&#92;&#93;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p><\/li>\n\n\n\n<li><strong>When to use it?<\/strong> Great for <strong>balanced datasets<\/strong> (where classes are roughly equal).<\/li>\n\n\n\n<li><strong>The catch?<\/strong> Misleading for <strong>imbalanced data<\/strong>. For example, if 95% of emails are <em>not<\/em> spam, a model that labels <em>everything<\/em> as &#8220;not spam&#8221; still gets 95% accuracy\u2014but fails to detect spam!<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. Precision \u2013 The &#8220;Trustworthy Yes&#8221; Metric<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>What is it?<\/strong> Out of all the <em>positive<\/em> predictions your model makes (e.g., &#8220;this is spam&#8221; or &#8220;this person is sick&#8221;), how many are <em>actually<\/em> correct?<\/li>\n\n\n\n<li><strong>Formula:<\/strong><br><p class=\"ql-center-displayed-equation\" style=\"line-height: 39px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/amirhooshang.com\/blog\/wp-content\/ql-cache\/quicklatex.com-c1a33bebfdb231f8d190a57b0b63ad6f_l3.png\" height=\"39\" width=\"344\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#91;&#92;&#116;&#101;&#120;&#116;&#123;&#80;&#114;&#101;&#99;&#105;&#115;&#105;&#111;&#110;&#125;&#32;&#61;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#92;&#116;&#101;&#120;&#116;&#123;&#84;&#114;&#117;&#101;&#32;&#80;&#111;&#115;&#105;&#116;&#105;&#118;&#101;&#115;&#125;&#125;&#123;&#92;&#116;&#101;&#120;&#116;&#123;&#84;&#114;&#117;&#101;&#32;&#80;&#111;&#115;&#105;&#116;&#105;&#118;&#101;&#115;&#32;&#43;&#32;&#70;&#97;&#108;&#115;&#101;&#32;&#80;&#111;&#115;&#105;&#116;&#105;&#118;&#101;&#115;&#125;&#125;&#92;&#93;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p><\/li>\n\n\n\n<li><strong>Example:<\/strong> If your model flags 80 patients as &#8220;sick&#8221; but 20 of those are actually healthy, Precision = 80%.<\/li>\n\n\n\n<li><strong>When does it matter?<\/strong> When <strong>False Positives (FP)<\/strong> are costly. For example, wrongly diagnosing a healthy person with a disease wastes resources and causes stress.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>3. Recall \u2013 The &#8220;Don\u2019t Miss the Positives&#8221; Metric<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>What is it?<\/strong> Out of all the <em>actual<\/em> positive cases (e.g., real cancer patients), how many did your model correctly identify?<\/li>\n\n\n\n<li><strong>Formula:<\/strong><br><p class=\"ql-center-displayed-equation\" style=\"line-height: 41px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/amirhooshang.com\/blog\/wp-content\/ql-cache\/quicklatex.com-a485381f707d75291e9a302dddec400e_l3.png\" height=\"41\" width=\"328\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#91;&#92;&#116;&#101;&#120;&#116;&#123;&#82;&#101;&#99;&#97;&#108;&#108;&#125;&#32;&#61;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#92;&#116;&#101;&#120;&#116;&#123;&#84;&#114;&#117;&#101;&#32;&#80;&#111;&#115;&#105;&#116;&#105;&#118;&#101;&#115;&#125;&#125;&#123;&#92;&#116;&#101;&#120;&#116;&#123;&#84;&#114;&#117;&#101;&#32;&#80;&#111;&#115;&#105;&#116;&#105;&#118;&#101;&#115;&#32;&#43;&#32;&#70;&#97;&#108;&#115;&#101;&#32;&#78;&#101;&#103;&#97;&#116;&#105;&#118;&#101;&#115;&#125;&#125;&#92;&#93;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p><\/li>\n\n\n\n<li><strong>Example:<\/strong> If there are 10 cancer patients and your model catches 9, Recall = 90%.<\/li>\n\n\n\n<li><strong>When does it matter?<\/strong> When <strong>False Negatives (FN)<\/strong> are dangerous. For example, missing a cancer diagnosis could be life-threatening!<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>4. F1-Score \u2013 The Balanced &#8220;Best of Both Worlds&#8221;<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>What is it?<\/strong> A single score that balances Precision and Recall. High F1 means your model is good at <em>both<\/em> avoiding false alarms <em>and<\/em> catching true positives.<\/li>\n\n\n\n<li><strong>Formula:<\/strong><br><p class=\"ql-center-displayed-equation\" style=\"line-height: 38px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/amirhooshang.com\/blog\/wp-content\/ql-cache\/quicklatex.com-7a3054b55742d04d0bfdf88d026aa1cd_l3.png\" height=\"38\" width=\"223\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#91;&#70;&#49;&#32;&#61;&#32;&#50;&#32;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#92;&#116;&#101;&#120;&#116;&#123;&#80;&#114;&#101;&#99;&#105;&#115;&#105;&#111;&#110;&#125;&#32;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#92;&#116;&#101;&#120;&#116;&#123;&#82;&#101;&#99;&#97;&#108;&#108;&#125;&#125;&#123;&#92;&#116;&#101;&#120;&#116;&#123;&#80;&#114;&#101;&#99;&#105;&#115;&#105;&#111;&#110;&#32;&#43;&#32;&#82;&#101;&#99;&#97;&#108;&#108;&#125;&#125;&#92;&#93;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p><\/li>\n\n\n\n<li><strong>Example:<\/strong> If Precision = 80% and Recall = 90%, F1 \u2248 85%.<\/li>\n\n\n\n<li><strong>When to use it?<\/strong> Ideal for <strong>imbalanced data<\/strong> or when both FP and FN matter. For example, fraud detection: you don\u2019t want to miss fraud (high Recall) <em>or<\/em> falsely accuse users (high Precision).<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>5. ROC-AUC \u2013 The &#8220;How Well Can It Tell Apart?&#8221; Score<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>What is it?<\/strong> A score between 0 and 1 that measures how well your model distinguishes between classes (e.g., sick vs. healthy). Closer to 1 = better.<\/li>\n\n\n\n<li><strong>Example:<\/strong> A model with AUC = 0.95 is way stronger than one with AUC = 0.70.<\/li>\n\n\n\n<li><strong>How does it work?<\/strong> The ROC curve plots the trade-off between True Positive Rate (Recall) and False Positive Rate. AUC = area under this curve.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>6. Confusion Matrix \u2013 The Model\u2019s &#8220;Performance Report&#8221;<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>What is it?<\/strong> A 2&#215;2 table summarizing your model\u2019s predictions:<\/li>\n\n\n\n<li><strong>True Positive (TP):<\/strong> Correctly predicted &#8220;positive&#8221; (e.g., correctly identified spam).<\/li>\n\n\n\n<li><strong>False Positive (FP):<\/strong> Wrongly predicted &#8220;positive&#8221; (e.g., flagged a normal email as spam).<\/li>\n\n\n\n<li><strong>True Negative (TN):<\/strong> Correctly predicted &#8220;negative&#8221; (e.g., correctly identified non-spam).<\/li>\n\n\n\n<li><strong>False Negative (FN):<\/strong> Wrongly predicted &#8220;negative&#8221; (e.g., missed a spam email).<\/li>\n\n\n\n<li><strong>Example:<\/strong> Predicted Sick Predicted Healthy <strong>Actual Sick<\/strong> 50 (TP) 5 (FN) <strong>Actual Healthy<\/strong> 10 (FP) 100 (TN)<\/li>\n\n\n\n<li><strong>Why use it?<\/strong> It shows <em>where<\/em> your model struggles. For instance, high FN means it\u2019s missing sick patients!<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Why You Can\u2019t Rely on Just One Metric<\/strong><\/h3>\n\n\n\n<p>Choosing metrics depends on your <strong>problem\u2019s context<\/strong> and <strong>error costs<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Imbalanced data (e.g., 90% healthy vs. 10% sick):<\/strong><\/li>\n\n\n\n<li>Accuracy is misleading. Use <strong>F1-Score<\/strong> or <strong>AUC<\/strong> instead.<\/li>\n\n\n\n<li><strong>Costly errors:<\/strong><\/li>\n\n\n\n<li><strong>High FP cost?<\/strong> Prioritize <strong>Precision<\/strong> (e.g., avoiding false fraud alerts).<\/li>\n\n\n\n<li><strong>High FN cost?<\/strong> Prioritize <strong>Recall<\/strong> (e.g., cancer screening).<\/li>\n\n\n\n<li><strong>Combining metrics:<\/strong><\/li>\n\n\n\n<li><strong>Bank fraud detection:<\/strong> Balance Precision (avoid false accusations) and Recall (catch all fraud). Use <strong>F1-Score<\/strong>.<\/li>\n\n\n\n<li><strong>Email marketing:<\/strong> Maximize Recall to reach all potential customers, even if some emails go to uninterested users.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Conclusion: Which Metric Should You Pick?<\/strong><\/h3>\n\n\n\n<p>No single metric tells the whole story!<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Quick check:<\/strong> Start with Accuracy, but <em>always<\/em> look at the Confusion Matrix.<\/li>\n\n\n\n<li><strong>Imbalanced data?<\/strong> Use <strong>F1-Score<\/strong> or <strong>AUC<\/strong>.<\/li>\n\n\n\n<li><strong>High-stakes errors?<\/strong> Focus on <strong>Recall<\/strong> (e.g., medical diagnoses) or <strong>Precision<\/strong> (e.g., drug testing).<\/li>\n<\/ul>\n\n\n\n<p>Ultimately, your choice should align with <strong>business goals<\/strong> and <strong>real-world impact<\/strong>. For example, in rare disease detection, you need high Recall (don\u2019t miss patients) <em>and<\/em> decent Precision (avoid overwhelming the system with false alarms).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Imagine you\u2019ve built a machine learning model to detect cancer from medical scans or filter spam emails. How do you know if it\u2019s actually working well? Evaluation metrics act like&#8230;<\/p>\n","protected":false},"author":1,"featured_media":93,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61,62],"tags":[73,78,76,80,56,79,74,75,77],"class_list":["post-65","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-machine-learning","category-model-evaluation","tag-accuracy-2","tag-classification-2","tag-confusion-matrix","tag-evaluation-metrics","tag-f1-score","tag-machine-learning","tag-precision-2","tag-recall","tag-roc-auc"],"_links":{"self":[{"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/posts\/65","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/comments?post=65"}],"version-history":[{"count":4,"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/posts\/65\/revisions"}],"predecessor-version":[{"id":74,"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/posts\/65\/revisions\/74"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/media\/93"}],"wp:attachment":[{"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/media?parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/categories?post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/tags?post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}