{"id":12614,"date":"2020-03-03T11:49:02","date_gmt":"2020-03-03T06:19:02","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/confusion-matrix-an-overview-with-python-and-r\/"},"modified":"2025-03-31T21:15:21","modified_gmt":"2025-03-31T15:45:21","slug":"confusion-matrix-an-overview-with-python-and-r","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/confusion-matrix-an-overview-with-python-and-r\/","title":{"rendered":"What is the Confusion Matrix in Machine Learning?"},"content":{"rendered":"\n<p>Building a <a href=\"https:\/\/www.mygreatlearning.com\/blog\/machine-learning-models\/\">machine learning classification model<\/a> involves several key steps, including data collection, exploration, preprocessing, and cleaning. After these steps, we apply classification techniques to generate predictions.<\/p>\n\n\n\n<p>However, before finalizing a classifier model, we need to evaluate its performance. One essential tool for this evaluation is the <strong>Confusion Matrix<\/strong>, which measures classification accuracy and identifies errors.\u00a0<\/p>\n\n\n\n<p>In this article, we will explore the confusion matrix in detail and demonstrate its implementation in Python and R.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-a-confusion-matrix\"><strong>What is a Confusion Matrix?<\/strong><\/h2>\n\n\n\n<p>A <strong>confusion matrix<\/strong> is a table used to assess the performance of a classification model on a test dataset where the actual values are known. It is also referred to as an <strong>error matrix<\/strong> and provides insight into the types of errors the model makes. It categorizes predictions into four groups:<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion0-matrix-viosualtion.webp\"><img decoding=\"async\" width=\"1024\" height=\"661\" src=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion0-matrix-viosualtion-1024x661.webp\" alt=\"Confusion Matrix Visualization\" class=\"wp-image-106433\" style=\"width:748px;height:auto\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion0-matrix-viosualtion-1024x661.webp 1024w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion0-matrix-viosualtion-300x194.webp 300w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion0-matrix-viosualtion-768x495.webp 768w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion0-matrix-viosualtion-150x97.webp 150w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion0-matrix-viosualtion.webp 1344w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>True Positive (TP)<\/strong> \u2013 The actual value is positive, and the model correctly predicts it as positive.<\/li>\n\n\n\n<li><strong>True Negative (TN)<\/strong> \u2013 The actual value is negative, and the model correctly predicts it as negative.<\/li>\n\n\n\n<li><strong>False Positive (FP)<\/strong> \u2013 The actual value is negative, but the model predicts it as positive (Type I error).<\/li>\n\n\n\n<li><strong>False Negative (FN)<\/strong> \u2013 The actual value is positive, but the model predicts it as negative (Type II error).<\/li>\n<\/ul>\n\n\n\n<p>This structured table allows us to analyze model performance beyond simple accuracy calculations.<\/p>\n\n\n\n<p class=\"block-course-highlighter\">The<a href=\"https:\/\/www.mygreatlearning.com\/blog\/multiclass-classification-explained\/\"> <strong>Multiclass Classification<\/strong><\/a> concept is closely related to the confusion matrix, which helps assess the performance of models handling multiple categories.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"performance-metrics-derived-from-confusion-matrix\"><strong>Performance Metrics Derived from Confusion Matrix<\/strong><\/h2>\n\n\n\n<p>The confusion matrix helps compute several performance metrics:<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/performance-confusuon-matrix.webp\"><img decoding=\"async\" width=\"1024\" height=\"568\" src=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/performance-confusuon-matrix-1024x568.webp\" alt=\"Performance Metrix from Confusion Matrix\" class=\"wp-image-106428\" style=\"width:793px;height:auto\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/performance-confusuon-matrix-1024x568.webp 1024w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/performance-confusuon-matrix-300x167.webp 300w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/performance-confusuon-matrix-768x426.webp 768w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/performance-confusuon-matrix-1536x852.webp 1536w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/performance-confusuon-matrix-150x83.webp 150w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/performance-confusuon-matrix.webp 1600w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1-accuracy\"><strong>1. Accuracy<\/strong><\/h3>\n\n\n\n<p><strong>Formula<\/strong>: Accuracy = (TP + TN) \/ (TP + TN + FP + FN)<\/p>\n\n\n\n<p>Accuracy measures how often the model makes correct predictions. However, in imbalanced datasets, high accuracy might be misleading.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2-precision\"><strong>2. Precision<\/strong><\/h3>\n\n\n\n<p><strong>Formula<\/strong>: Precision = TP \/ (TP + FP)<\/p>\n\n\n\n<p>Precision measures how many predicted positive values are actually correct. It is crucial in applications like spam detection.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3-recall-sensitivity\"><strong>3. Recall (Sensitivity)<\/strong><\/h3>\n\n\n\n<p><strong>Formula<\/strong>: Recall = TP \/ (TP + FN)<\/p>\n\n\n\n<p>Recall indicates how well the model identifies positive instances. A high recall means fewer false negatives.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"4-f1-score\"><strong>4. F1-Score<\/strong><\/h3>\n\n\n\n<p><strong>Formula<\/strong>: F-measure = 2 * Recall * Precision \/ (Recall + Precision)<\/p>\n\n\n\n<p>F1-Score balances precision and recall, making it useful when class distribution is uneven.<\/p>\n\n\n\n<p>Understanding different<a href=\"https:\/\/www.mygreatlearning.com\/blog\/machine-learning-algorithms\/\"> <strong>Machine Learning Algorithms<\/strong><\/a> is essential, as the confusion matrix is commonly used to evaluate classification models.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"calculation-of-2-class-confusion-matrix\"><strong>Calculation of 2-class confusion matrix<\/strong><\/h2>\n\n\n\n<p>Let us derive a confusion matrix and interpret the result using simple mathematics.<\/p>\n\n\n\n<p>Let us consider the actual and predicted values of y as given below:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Actual y<\/strong><\/td><td><strong>Y predicted<\/strong><\/td><td><strong>Predicted y with threshold 0.5<\/strong><\/td><\/tr><tr><td>1<\/td><td>0.7<\/td><td>1<\/td><\/tr><tr><td>0<\/td><td>0.1<\/td><td>0<\/td><\/tr><tr><td>0<\/td><td>0.6<\/td><td>1<\/td><\/tr><tr><td>1<\/td><td>0.4<\/td><td>0<\/td><\/tr><tr><td>0<\/td><td>0.2<\/td><td>0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Now, if we make a confusion matrix from this, it would look like:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>N=5<\/strong><\/td><td><strong>Predicted 1<\/strong><\/td><td><strong>Predicted 0<\/strong><\/td><\/tr><tr><td><strong>Actual: 1<\/strong><\/td><td>1 (TP)<\/td><td>1 (FN)<\/td><\/tr><tr><td><strong>Actual: 0<\/strong><\/td><td>1 (FP)<\/td><td>2 (TN)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>This is our derived confusion matrix. Now we can also see all the four terms used in the above confusion matrix. Now we will find all the above-defined performance metrics from this confusion matrix.<\/p>\n\n\n\n<p><strong>1. Accuracy<\/strong><\/p>\n\n\n\n<p><strong>Accuracy <\/strong>= (TP + TN) \/ (TP + TN + FP + FN)<\/p>\n\n\n\n<p>So, Accuracy = (1+2) \/ (1+2+1+1)<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0= 3\/5 which is 60%.<\/p>\n\n\n\n<p>So, the accuracy from the above confusion matrix is 60%.<\/p>\n\n\n\n<p><strong>2. Precision&nbsp;<\/strong><\/p>\n\n\n\n<p><strong>Precision <\/strong>= TP \/ (TP + FP)<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0= 1 \/ (1+1)<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0=1 \/ 2 which is 50%.<\/p>\n\n\n\n<p>So, the precision is 50%.<\/p>\n\n\n\n<p><strong>3. Recall&nbsp;<\/strong><\/p>\n\n\n\n<p><strong>Recall <\/strong>= TP \/ (TP + FN)<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0= 1 \/ (1+1)<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0= \u00bd which is 50%<\/p>\n\n\n\n<p>So, the Recall is 50%.<\/p>\n\n\n\n<p><strong>4. F-measure&nbsp;<\/strong><\/p>\n\n\n\n<p><strong>F-measure<\/strong> = 2 * Recall * Precision \/ (Recall + Precision)<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0= 2*0.5*0.5 \/ (0.5+0.5)<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0= 0.5<\/p>\n\n\n\n<p>So, the F-measure is 50%.<\/p>\n\n\n\n<p class=\"block-course-highlighter\">Identifying<a href=\"https:\/\/www.mygreatlearning.com\/blog\/overfitting-and-underfitting-in-machine-learning\/\"> <strong>Overfitting and Underfitting in Machine Learning<\/strong><\/a> is crucial when analyzing model performance, as a confusion matrix can highlight cases of misclassification.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"implementing-confusion-matrix-in-python\"><strong>Implementing Confusion Matrix in Python<\/strong><\/h2>\n\n\n\n<p>Using scikit-learn, we can compute the confusion matrix and performance metrics:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.metrics import accuracy_score, confusion_matrix, classification_report\n\n# Load dataset\ndf = pd.read_csv(&quot;bank.csv&quot;, delimiter=&quot;;&quot;)\n\n# Data preprocessing\nfrom sklearn.preprocessing import LabelEncoder\nle = LabelEncoder()\ndf.job = le.fit_transform(df.job)\ndf.marital = le.fit_transform(df.marital)\ndf.y = le.fit_transform(df.y)\n\nX = df.drop(&quot;y&quot;, axis=1)\ny = df&#x5B;&quot;y&quot;]\n\n# Train-Test Split\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)\n\n# Model Training\nmodel = LogisticRegression(max_iter=1000, random_state=42)\nmodel.fit(X_train, y_train)\ny_pred = model.predict(X_test)\n\n# Evaluating Model\nprint(&quot;Accuracy:&quot;, accuracy_score(y_test, y_pred))\nprint(&quot;Confusion Matrix:\\n&quot;, confusion_matrix(y_test, y_pred))\nprint(&quot;Classification Report:\\n&quot;, classification_report(y_test, y_pred))\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-full zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion-matricx.png\"><img decoding=\"async\" width=\"615\" height=\"501\" src=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion-matricx.png\" alt=\"Confusion Matrix\" class=\"wp-image-106429\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion-matricx.png 615w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion-matricx-300x244.png 300w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion-matricx-150x122.png 150w\" sizes=\"(max-width: 615px) 100vw, 615px\" \/><\/figure>\n\n\n\n<p><strong>1. Accuracy:<\/strong> <strong>48.67%<\/strong><\/p>\n\n\n\n<p><strong>2. Confusion Matrix:<\/strong><br>[79 72]<br>[82 67]<\/p>\n\n\n\n<p><strong>3. Classification Report<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">              precision    recall  f1-score   support<br><br>           0       0.49      0.52      0.51       151<br>           1       0.48      0.45      0.47       149<br><br> accuracy                           0.49       300<br>macro avg       0.49      0.49      0.49       300<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"implementing-confusion-matrix-in-r\"><strong>Implementing Confusion Matrix in R<\/strong><\/h2>\n\n\n\n<p>In R, we use logistic regression for classification and confusion matrix computation:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlibrary(dplyr)\nlibrary(ggplot2)\nlibrary(DataExplorer)\n\n# Load dataset\ndf &amp;lt;- read.csv(&quot;adult.csv&quot;)\n\n# Data Preprocessing\ndf$target &amp;lt;- ifelse(df$income == &#039;&gt;50K&#039;, 1, 0)\ndf$target &amp;lt;- as.factor(df$target)\n\n# Train-Test Split\nset.seed(1000)\nindex &amp;lt;- sample(nrow(df), 0.70 * nrow(df), replace=FALSE)\ntrain &amp;lt;- df&#x5B;index, ]\ntest &amp;lt;- df&#x5B;-index, ]\n\n# Logistic Regression Model\nmod &amp;lt;- glm(target ~ ., data=train, family=&#039;binomial&#039;)\npred &amp;lt;- predict(mod, test, type=&#039;response&#039;)\npred_class &amp;lt;- ifelse(pred &gt; 0.5, 1, 0)\n\n# Confusion Matrix\ntable(Predicted=pred_class, Actual=test$target)\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>The <strong>confusion matrix<\/strong> is a fundamental tool for evaluating classification models. It provides insights into model accuracy, precision, recall, and F1-score. While accuracy is often the primary metric, recall and precision are crucial in various real-world applications, such as fraud detection and medical diagnoses.<\/p>\n\n\n\n<p>By implementing confusion matrices in <strong>Python and R<\/strong>, we can better understand and optimize our machine learning models for improved performance.<\/p>\n\n\n\n<p class=\"block-course-highlighter\">Master <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-data-science-machine-learning-in-python\"><strong>Data Science and Machine Learning in Python<\/strong><\/a> with hands-on projects, real-world case studies, and expert-led lessons. Build job-ready skills in <strong>predictive modeling, feature engineering, and data analysis<\/strong>, and understand key evaluation techniques like the <strong>Confusion Matrix in Machine Learning<\/strong>, which helps assess model performance in classification tasks.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"frequently-asked-questionsfaqs\"><strong>Frequently Asked Questions(FAQ\u2019s)<\/strong><\/h2>\n\n\n\n<p><strong>1. What is the difference between a confusion matrix and a contingency table?<\/strong><\/p>\n\n\n\n<p>A confusion matrix is a special type of contingency table used for classification problems, where rows represent actual values and columns represent predicted values. A contingency table is a more general term used in statistics to display the frequency distribution of categorical variables.<\/p>\n\n\n\n<p><strong>2. Why is a confusion matrix important when accuracy is already given?<\/strong><\/p>\n\n\n\n<p>Accuracy alone can be misleading, especially in imbalanced datasets. A confusion matrix helps by showing False Positives (FP) and False Negatives (FN), which can be crucial in applications like medical diagnosis or fraud detection.<\/p>\n\n\n\n<p><strong>3. How does the confusion matrix change with imbalanced datasets?<\/strong><\/p>\n\n\n\n<p>In imbalanced datasets, the model tends to favor the majority class, leading to a misleadingly high accuracy. A confusion matrix reveals whether the model is simply predicting the dominant class, making metrics like Precision, Recall, and F1-score more important.<\/p>\n\n\n\n<p><strong>4. Can we use a confusion matrix for multi-class classification?<\/strong><\/p>\n\n\n\n<p>Yes, a confusion matrix can handle multi-class classification. Instead of a 2\u00d72 matrix, it becomes an N\u00d7N matrix, where N is the number of classes. Each cell represents the count of true vs. predicted values for a particular class.<\/p>\n\n\n\n<p><strong>5. How can I normalize a confusion matrix for better interpretation?<\/strong><\/p>\n\n\n\n<p>A raw confusion matrix shows absolute counts, which can be hard to interpret when class distributions vary. You can normalize it using:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cm_normalized = cm.astype('float') \/ cm.sum(axis=1)[:, np.newaxis]<\/pre>\n\n\n\n<p>This converts the confusion matrix values into <strong>percentages<\/strong>, making it easier to compare across classes.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A confusion matrix is a tool used to assess the performance of machine learning classification models. It categorizes predictions into true positives, true negatives, false positives, and false negatives. In this article, we explain the concept of confusion matrices, their performance metrics like accuracy, precision, recall, and F1-score, and show you how to implement them in Python and R.<\/p>\n","protected":false},"author":41,"featured_media":106431,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[2],"tags":[36799],"content_type":[],"class_list":["post-12614","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-artificial-intelligence","tag-machine-learning"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>What is the Confusion Matrix? Overview with Python and R<\/title>\n<meta name=\"description\" content=\"Learn what a confusion matrix is in machine learning and how it helps evaluate the performance of classification models. Explore its components, performance metrics, and implementation in Python and R with examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/confusion-matrix-an-overview-with-python-and-r\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is the Confusion Matrix in Machine Learning?\" \/>\n<meta property=\"og:description\" content=\"Learn what a confusion matrix is in machine learning and how it helps evaluate the performance of classification models. Explore its components, performance metrics, and implementation in Python and R with examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/confusion-matrix-an-overview-with-python-and-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-03T06:19:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-03-31T15:45:21+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion-matrix-banner.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1117\" \/>\n\t<meta property=\"og:image:height\" content=\"585\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/confusion-matrix-an-overview-with-python-and-r\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/confusion-matrix-an-overview-with-python-and-r\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"What is the Confusion Matrix in Machine Learning?\",\"datePublished\":\"2020-03-03T06:19:02+00:00\",\"dateModified\":\"2025-03-31T15:45:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/confusion-matrix-an-overview-with-python-and-r\\\/\"},\"wordCount\":945,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/confusion-matrix-an-overview-with-python-and-r\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/confusion-matrix-banner.jpg\",\"keywords\":[\"Machine Learning\"],\"articleSection\":[\"AI and Machine Learning\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/confusion-matrix-an-overview-with-python-and-r\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/confusion-matrix-an-overview-with-python-and-r\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/confusion-matrix-an-overview-with-python-and-r\\\/\",\"name\":\"What is the Confusion Matrix? Overview with Python and R\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/confusion-matrix-an-overview-with-python-and-r\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/confusion-matrix-an-overview-with-python-and-r\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/confusion-matrix-banner.jpg\",\"datePublished\":\"2020-03-03T06:19:02+00:00\",\"dateModified\":\"2025-03-31T15:45:21+00:00\",\"description\":\"Learn what a confusion matrix is in machine learning and how it helps evaluate the performance of classification models. Explore its components, performance metrics, and implementation in Python and R with examples.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/confusion-matrix-an-overview-with-python-and-r\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/confusion-matrix-an-overview-with-python-and-r\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/confusion-matrix-an-overview-with-python-and-r\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/confusion-matrix-banner.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/confusion-matrix-banner.jpg\",\"width\":1117,\"height\":585,\"caption\":\"Confusion Matrix banner\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/confusion-matrix-an-overview-with-python-and-r\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"AI and Machine Learning\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/artificial-intelligence\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"What is the Confusion Matrix in Machine Learning?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"What is the Confusion Matrix? Overview with Python and R","description":"Learn what a confusion matrix is in machine learning and how it helps evaluate the performance of classification models. Explore its components, performance metrics, and implementation in Python and R with examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/confusion-matrix-an-overview-with-python-and-r\/","og_locale":"en_US","og_type":"article","og_title":"What is the Confusion Matrix in Machine Learning?","og_description":"Learn what a confusion matrix is in machine learning and how it helps evaluate the performance of classification models. Explore its components, performance metrics, and implementation in Python and R with examples.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/confusion-matrix-an-overview-with-python-and-r\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2020-03-03T06:19:02+00:00","article_modified_time":"2025-03-31T15:45:21+00:00","og_image":[{"width":1117,"height":585,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion-matrix-banner.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/confusion-matrix-an-overview-with-python-and-r\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/confusion-matrix-an-overview-with-python-and-r\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"What is the Confusion Matrix in Machine Learning?","datePublished":"2020-03-03T06:19:02+00:00","dateModified":"2025-03-31T15:45:21+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/confusion-matrix-an-overview-with-python-and-r\/"},"wordCount":945,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/confusion-matrix-an-overview-with-python-and-r\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion-matrix-banner.jpg","keywords":["Machine Learning"],"articleSection":["AI and Machine Learning"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/confusion-matrix-an-overview-with-python-and-r\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/confusion-matrix-an-overview-with-python-and-r\/","url":"https:\/\/www.mygreatlearning.com\/blog\/confusion-matrix-an-overview-with-python-and-r\/","name":"What is the Confusion Matrix? Overview with Python and R","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/confusion-matrix-an-overview-with-python-and-r\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/confusion-matrix-an-overview-with-python-and-r\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion-matrix-banner.jpg","datePublished":"2020-03-03T06:19:02+00:00","dateModified":"2025-03-31T15:45:21+00:00","description":"Learn what a confusion matrix is in machine learning and how it helps evaluate the performance of classification models. Explore its components, performance metrics, and implementation in Python and R with examples.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/confusion-matrix-an-overview-with-python-and-r\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/confusion-matrix-an-overview-with-python-and-r\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/confusion-matrix-an-overview-with-python-and-r\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion-matrix-banner.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion-matrix-banner.jpg","width":1117,"height":585,"caption":"Confusion Matrix banner"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/confusion-matrix-an-overview-with-python-and-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"AI and Machine Learning","item":"https:\/\/www.mygreatlearning.com\/blog\/artificial-intelligence\/"},{"@type":"ListItem","position":3,"name":"What is the Confusion Matrix in Machine Learning?"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion-matrix-banner.jpg",1117,585,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion-matrix-banner-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion-matrix-banner-300x157.jpg",300,157,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion-matrix-banner-768x402.jpg",768,402,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion-matrix-banner-1024x536.jpg",1024,536,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion-matrix-banner.jpg",1117,585,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion-matrix-banner.jpg",1117,585,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion-matrix-banner-640x585.jpg",640,585,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion-matrix-banner-96x96.jpg",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/03\/confusion-matrix-banner-150x79.jpg",150,79,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"A confusion matrix is a tool used to assess the performance of machine learning classification models. It categorizes predictions into true positives, true negatives, false positives, and false negatives. In this article, we explain the concept of confusion matrices, their performance metrics like accuracy, precision, recall, and F1-score, and show you how to implement them&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/12614","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=12614"}],"version-history":[{"count":12,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/12614\/revisions"}],"predecessor-version":[{"id":107104,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/12614\/revisions\/107104"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/106431"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=12614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=12614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=12614"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=12614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}