{"id":4960,"date":"2023-09-20T22:32:44","date_gmt":"2023-09-20T17:02:44","guid":{"rendered":"https:\/\/pravysoft.org\/eduserver\/?p=4960"},"modified":"2023-09-20T22:32:52","modified_gmt":"2023-09-20T17:02:52","slug":"machine-learning-difference-between-accuracy-precision-and-recall","status":"publish","type":"post","link":"https:\/\/pravysoft.org\/eduserver\/machine-learning-difference-between-accuracy-precision-and-recall\/","title":{"rendered":"Machine Learning: Difference between accuracy, precision and recall"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"4960\" class=\"elementor elementor-4960\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-8703f0c elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"8703f0c\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-3c78ef81\" data-id=\"3c78ef81\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-d134f46 elementor-widget elementor-widget-text-editor\" data-id=\"d134f46\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\n<p>For simplicity, we can start with an example.<\/p>\n\n\n\n<p>Suppose you have a dataset of 100 apples, and you&#8217;ve built a machine learning model to predict whether each apple is &#8220;Good&#8221; or &#8220;Bad&#8221; based on certain features like color, size, and texture.<\/p>\n\n\n\n<h2><strong>Accuracy:<\/strong><\/h2>\n\n\n\n<p>Accuracy is a measure of how many predictions your model got right overall.<br \/>In our example, let&#8217;s say your model made predictions for all 100 apples, and 90 of those predictions were correct (i.e., 90 apples were correctly classified as &#8220;Good&#8221; or &#8220;Bad&#8221;). The accuracy would be 90%.<br \/>Accuracy = (Number of Correct Predictions) \/ (Total Number of Predictions)<br \/>Accuracy = 90 \/ 100 = 0.90 (or 90%)<\/p>\n\n\n\n<p>So, your model has an accuracy of 90%, meaning it correctly classified 90% of the apples.<\/p>\n\n\n\n<h2><strong>Precision:<\/strong><\/h2>\n\n\n\n<p>Precision is a measure of how many of the apples predicted as &#8220;Good&#8221; by your model were actually &#8220;Good.&#8221;<br \/>Let&#8217;s say your model predicted 60 apples as &#8220;Good,&#8221; and out of those, 55 were actually &#8220;Good,&#8221; and 5 were &#8220;Bad.&#8221;<br \/>Precision = (Number of True Positives) \/ (Number of True Positives + Number of False Positives)<br \/>Precision = 55 \/ (55 + 5) = 55 \/ 60 = 0.917 (or 91.7%)<\/p>\n\n\n\n<p>The precision for &#8220;Good&#8221; apples is 91.7%. It means that when your model says an apple is &#8220;Good,&#8221; it is correct about 91.7% of the time.<\/p>\n\n\n\n<h2><strong>Recall:<\/strong><\/h2>\n\n\n\n<p>Recall is a measure of how many of the actual &#8220;Good&#8221; apples were correctly predicted as &#8220;Good&#8221; by your model.<br \/>Out of the 60 actual &#8220;Good&#8221; apples, let&#8217;s say your model correctly predicted 55 as &#8220;Good.&#8221;<br \/>Recall = (Number of True Positives) \/ (Number of True Positives + Number of False Negatives)<br \/>Recall = 55 \/ (55 + 5) = 55 \/ 60 = 0.917 (or 91.7%)<\/p>\n\n\n\n<p>The recall for &#8220;Good&#8221; apples is also 91.7%. It means that your model correctly identified 91.7% of the actual &#8220;Good&#8221; apples.<\/p>\n\n\n\n<h2>In summary<\/h2>\n\n\n\n<p>Accuracy tells you how many predictions are correct overall.<br \/>Precision tells you how many of the predicted positive cases are actually positive.<br \/>Recall tells you how many of the actual positive cases were correctly predicted as positive.<br \/>In the case of predicting good and bad apples, you want a balance between high precision and high recall. High precision means your model doesn&#8217;t incorrectly label good apples as bad, and high recall means your model doesn&#8217;t miss many actual good apples. It&#8217;s often a trade-off, and the choice depends on the specific goals of your application.<\/p>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-023b384 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"023b384\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-1222309\" data-id=\"1222309\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-f10ff3a elementor-widget elementor-widget-progress-tracker\" data-id=\"f10ff3a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"progress-tracker.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t \t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-65cc5c7 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"65cc5c7\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-8b775a8\" data-id=\"8b775a8\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-c18d98a elementor-widget elementor-widget-animated-headline\" data-id=\"c18d98a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"animated-headline.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t \t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-625a579 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"625a579\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-5035669\" data-id=\"5035669\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-bd5da68 elementor-widget elementor-widget-heading\" data-id=\"bd5da68\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Confusion Matrix<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-e0a65f4 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"e0a65f4\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-6a3c90d\" data-id=\"6a3c90d\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-92d7295 elementor-widget elementor-widget-text-editor\" data-id=\"92d7295\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Let&#8217;s use the same &#8220;Good&#8221; and &#8220;Bad&#8221; apple prediction example to explain a confusion matrix and how it&#8217;s represented as a heatmap.<\/p>\n<p>In a confusion matrix, we categorize the model&#8217;s predictions and the actual outcomes into four categories:<\/p>\n<ul>\n<li><strong>True Positives (TP)<\/strong>: The model correctly predicted &#8220;Good&#8221; apples as &#8220;Good.&#8221;<\/li>\n<li><strong>True Negatives (TN)<\/strong>: The model correctly predicted &#8220;Bad&#8221; apples as &#8220;Bad.&#8221;<\/li>\n<li><strong>False Positives (FP)<\/strong>: The model incorrectly predicted &#8220;Bad&#8221; apples as &#8220;Good.&#8221;<\/li>\n<li><strong>False Negatives (FN)<\/strong>: The model incorrectly predicted &#8220;Good&#8221; apples as &#8220;Bad.&#8221;<\/li>\n<\/ul>\n<p>Now, let&#8217;s say your model made predictions for 100 apples, and here&#8217;s the breakdown:<\/p>\n<ul>\n<li>True Positives (TP): 55 apples were correctly predicted as &#8220;Good.&#8221;<\/li>\n<li>True Negatives (TN): 35 apples were correctly predicted as &#8220;Bad.&#8221;<\/li>\n<li>False Positives (FP): 5 apples were incorrectly predicted as &#8220;Good&#8221; when they were actually &#8220;Bad.&#8221;<\/li>\n<li>False Negatives (FN): 5 apples were incorrectly predicted as &#8220;Bad&#8221; when they were actually &#8220;Good.&#8221;<\/li>\n<\/ul>\n<p>Your confusion matrix would look like this:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-fada5dd elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"fada5dd\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-246334c\" data-id=\"246334c\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-f49caf6 elementor-widget elementor-widget-image\" data-id=\"f49caf6\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"574\" height=\"453\" src=\"https:\/\/pravysoft.org\/eduserver\/wp-content\/uploads\/2023\/09\/Machinelearning-confusion-matrix.png\" class=\"img-fluid attachment-large size-large wp-image-4966\" alt=\"machine learning confusion matrix simple explanation\" srcset=\"https:\/\/pravysoft.org\/eduserver\/wp-content\/uploads\/2023\/09\/Machinelearning-confusion-matrix.png 574w, https:\/\/pravysoft.org\/eduserver\/wp-content\/uploads\/2023\/09\/Machinelearning-confusion-matrix-300x237.png 300w, https:\/\/pravysoft.org\/eduserver\/wp-content\/uploads\/2023\/09\/Machinelearning-confusion-matrix-63x50.png 63w\" sizes=\"(max-width: 574px) 100vw, 574px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-cf7c411 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"cf7c411\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-23d539e\" data-id=\"23d539e\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-05e40a7 elementor-widget elementor-widget-text-editor\" data-id=\"05e40a7\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Now, to create a heatmap visualization of this confusion matrix:<\/p>\n<ul>\n<li>The x-axis represents the predicted labels (Predicted Bad and Predicted Good).<\/li>\n<li>The y-axis represents the actual labels (Actual Bad and Actual Good).<\/li>\n<\/ul>\n<p>Each cell in the heatmap represents the count of apples falling into a particular category:<\/p>\n<ul>\n<li>The top-left cell (Actual Bad, Predicted Bad) contains the True Negatives (TN), which is 35 in our example.<\/li>\n<li>The top-right cell (Actual Bad, Predicted Good) contains the False Positives (FP), which is 5 in our example.<\/li>\n<li>The bottom-left cell (Actual Good, Predicted Bad) contains the False Negatives (FN), which is 5 in our example.<\/li>\n<li>The bottom-right cell (Actual Good, Predicted Good) contains the True Positives (TP), which is 55 in our example.<\/li>\n<\/ul>\n<p>The heatmap color intensity can be used to visualize the counts. Typically, you would see a dark color (e.g., dark blue) for high counts and a lighter color (e.g., light blue) for low counts.<\/p>\n<p>So, in this example, the heatmap would visually represent the distribution of correct and incorrect predictions for &#8220;Good&#8221; and &#8220;Bad&#8221; apples, helping you quickly identify where the model is performing well and where it may need improvement.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-70f71d4 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"70f71d4\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-a2e2f50\" data-id=\"a2e2f50\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-6961111 elementor-widget elementor-widget-animated-headline\" data-id=\"6961111\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"animated-headline.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t \t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>For simplicity, we can start with an example. Suppose you have a&#8230;<\/p>\n","protected":false},"author":1,"featured_media":4967,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","footnotes":""},"categories":[293,45],"tags":[509,501,506,500,504,507,508],"class_list":["post-4960","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-education","category-tutorial","tag-best-machine-learning-course-in-kozhikode-city","tag-difference-between-accuracy-and-precision","tag-heat-map","tag-machine-learning","tag-recall","tag-simple-explanation","tag-with-examples"],"_links":{"self":[{"href":"https:\/\/pravysoft.org\/eduserver\/wp-json\/wp\/v2\/posts\/4960","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pravysoft.org\/eduserver\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pravysoft.org\/eduserver\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pravysoft.org\/eduserver\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pravysoft.org\/eduserver\/wp-json\/wp\/v2\/comments?post=4960"}],"version-history":[{"count":0,"href":"https:\/\/pravysoft.org\/eduserver\/wp-json\/wp\/v2\/posts\/4960\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pravysoft.org\/eduserver\/wp-json\/wp\/v2\/media\/4967"}],"wp:attachment":[{"href":"https:\/\/pravysoft.org\/eduserver\/wp-json\/wp\/v2\/media?parent=4960"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pravysoft.org\/eduserver\/wp-json\/wp\/v2\/categories?post=4960"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pravysoft.org\/eduserver\/wp-json\/wp\/v2\/tags?post=4960"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}