{"id":177,"date":"2026-03-03T11:52:01","date_gmt":"2026-03-03T06:52:01","guid":{"rendered":"https:\/\/gigz.pk\/python\/?post_type=lesson&#038;p=177"},"modified":"2026-03-17T09:51:48","modified_gmt":"2026-03-17T04:51:48","slug":"model-evaluation","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/python\/lesson\/model-evaluation\/","title":{"rendered":"Model Evaluation"},"content":{"rendered":"\n<p>Model Evaluation is the process of measuring how well a Machine Learning model performs on unseen data.<\/p>\n\n\n\n<p>After training a model, we must check its performance to ensure it generalizes well and does not just memorize training data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Model Evaluation is Important<\/h2>\n\n\n\n<p>Model evaluation helps:<\/p>\n\n\n\n<p>Measure accuracy<br>Detect overfitting and underfitting<br>Compare different models<br>Improve model performance<br>Ensure reliability before deployment<\/p>\n\n\n\n<p>Without evaluation, we cannot trust predictions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Training vs Testing Data<\/h2>\n\n\n\n<p>Data is usually divided into:<\/p>\n\n\n\n<p>Training Set \u2192 Used to train the model<br>Testing Set \u2192 Used to evaluate performance<\/p>\n\n\n\n<p>This ensures the model is tested on unseen data.<\/p>\n\n\n\n<p>Common split:<\/p>\n\n\n\n<p>70\u201380% Training<br>20\u201330% Testing<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Evaluation for Regression Models<\/h2>\n\n\n\n<p>Regression models predict continuous values.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Mean Absolute Error (MAE)<\/h3>\n\n\n\n<p>Average of absolute differences between actual and predicted values.<\/p>\n\n\n\n<p>Lower MAE means better model.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Mean Squared Error (MSE)<\/h3>\n\n\n\n<p>Average of squared differences.<\/p>\n\n\n\n<p>Penalizes larger errors more than MAE.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Root Mean Squared Error (RMSE)<\/h3>\n\n\n\n<p>Square root of MSE.<\/p>\n\n\n\n<p>Easier to interpret because it is in original units.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. R-Squared (R\u00b2)<\/h3>\n\n\n\n<p>Measures how well the model explains variance in data.<\/p>\n\n\n\n<p>Value range:<\/p>\n\n\n\n<p>0 to 1<\/p>\n\n\n\n<p>Closer to 1 means better fit.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Evaluation for Classification Models<\/h2>\n\n\n\n<p>Classification models predict categories.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Accuracy<\/h3>\n\n\n\n<p>Percentage of correct predictions.<\/p>\n\n\n\n<p>Accuracy = Correct Predictions \/ Total Predictions<\/p>\n\n\n\n<p>Best used when data is balanced.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Confusion Matrix<\/h3>\n\n\n\n<p>Shows:<\/p>\n\n\n\n<p>True Positive (TP)<br>True Negative (TN)<br>False Positive (FP)<br>False Negative (FN)<\/p>\n\n\n\n<p>Helps analyze model errors.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Precision<\/h3>\n\n\n\n<p>Precision = TP \/ (TP + FP)<\/p>\n\n\n\n<p>Measures how many predicted positives are correct.<\/p>\n\n\n\n<p>Important when false positives are costly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. Recall<\/h3>\n\n\n\n<p>Recall = TP \/ (TP + FN)<\/p>\n\n\n\n<p>Measures how many actual positives are identified.<\/p>\n\n\n\n<p>Important when false negatives are costly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. F1-Score<\/h3>\n\n\n\n<p>Harmonic mean of precision and recall.<\/p>\n\n\n\n<p>Useful when dataset is imbalanced.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cross-Validation<\/h2>\n\n\n\n<p>Instead of using one train-test split, cross-validation divides data into multiple folds.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<p>5-Fold Cross Validation:<\/p>\n\n\n\n<p>Data split into 5 parts<br>Train on 4 parts<br>Test on 1 part<br>Repeat 5 times<\/p>\n\n\n\n<p>Final score is average of all folds.<\/p>\n\n\n\n<p>Benefits:<\/p>\n\n\n\n<p>More reliable evaluation<br>Reduces bias<br>Better performance estimation<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Overfitting and Underfitting<\/h2>\n\n\n\n<p>Overfitting:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Model performs well on training data<\/li>\n\n\n\n<li>Performs poorly on testing data<\/li>\n<\/ul>\n\n\n\n<p>Underfitting:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Model performs poorly on both training and testing data<\/li>\n<\/ul>\n\n\n\n<p>Good model:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Performs well on both<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Example Using Scikit-Learn<\/h2>\n\n\n\n<p>Regression evaluation:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from sklearn.metrics import mean_squared_error, r2_scoremse = mean_squared_error(y_test, predictions)<br>r2 = r2_score(y_test, predictions)print(\"MSE:\", mse)<br>print(\"R2 Score:\", r2)<\/pre>\n\n\n\n<p>Classification evaluation:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from sklearn.metrics import accuracy_score, classification_reportprint(\"Accuracy:\", accuracy_score(y_test, predictions))<br>print(classification_report(y_test, predictions))<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Choosing the Right Metric<\/h2>\n\n\n\n<p>Use MAE, MSE, RMSE for regression<br>Use Accuracy for balanced classification<br>Use Precision\/Recall for imbalanced data<br>Use F1-score when both precision and recall matter<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Key Takeaway<\/h2>\n\n\n\n<p>Model Evaluation measures how well a Machine Learning model performs on unseen data.<\/p>\n\n\n\n<p>Using proper metrics ensures the model is accurate, reliable, and ready for real-world applications.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/python\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">PYTHON FOR AI AND LLM (PYAI) > Scikit-Learn > Model Evaluation<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1773722916761\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<p><\/p>\n","protected":false},"menu_order":100,"template":"","class_list":["post-177","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Model Evaluation - One Language. Endless Possibilities<\/title>\n<meta name=\"description\" content=\"Learn Machine Learning model evaluation using MAE, MSE, RMSE, Accuracy, Precision, Recall, F1-score, and cross-validation techniques.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/python\/lesson\/model-evaluation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Model Evaluation - One Language. Endless Possibilities\" \/>\n<meta property=\"og:description\" content=\"Learn Machine Learning model evaluation using MAE, MSE, RMSE, Accuracy, Precision, Recall, F1-score, and cross-validation techniques.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/python\/lesson\/model-evaluation\/\" \/>\n<meta property=\"og:site_name\" content=\"One Language. Endless Possibilities\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-17T04:51:48+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/model-evaluation\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/model-evaluation\\\/\",\"name\":\"Model Evaluation - One Language. Endless Possibilities\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\"},\"datePublished\":\"2026-03-03T06:52:01+00:00\",\"dateModified\":\"2026-03-17T04:51:48+00:00\",\"description\":\"Learn Machine Learning model evaluation using MAE, MSE, RMSE, Accuracy, Precision, Recall, F1-score, and cross-validation techniques.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/model-evaluation\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/model-evaluation\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/model-evaluation\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PYTHON FOR AI AND LLM (PYAI) > Scikit-Learn > Model Evaluation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\",\"name\":\"One Language. Endless Possibilities\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/python\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Model Evaluation - One Language. Endless Possibilities","description":"Learn Machine Learning model evaluation using MAE, MSE, RMSE, Accuracy, Precision, Recall, F1-score, and cross-validation techniques.","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:\/\/gigz.pk\/python\/lesson\/model-evaluation\/","og_locale":"en_US","og_type":"article","og_title":"Model Evaluation - One Language. Endless Possibilities","og_description":"Learn Machine Learning model evaluation using MAE, MSE, RMSE, Accuracy, Precision, Recall, F1-score, and cross-validation techniques.","og_url":"https:\/\/gigz.pk\/python\/lesson\/model-evaluation\/","og_site_name":"One Language. Endless Possibilities","article_modified_time":"2026-03-17T04:51:48+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/python\/lesson\/model-evaluation\/","url":"https:\/\/gigz.pk\/python\/lesson\/model-evaluation\/","name":"Model Evaluation - One Language. Endless Possibilities","isPartOf":{"@id":"https:\/\/gigz.pk\/python\/#website"},"datePublished":"2026-03-03T06:52:01+00:00","dateModified":"2026-03-17T04:51:48+00:00","description":"Learn Machine Learning model evaluation using MAE, MSE, RMSE, Accuracy, Precision, Recall, F1-score, and cross-validation techniques.","breadcrumb":{"@id":"https:\/\/gigz.pk\/python\/lesson\/model-evaluation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/python\/lesson\/model-evaluation\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/python\/lesson\/model-evaluation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/python\/"},{"@type":"ListItem","position":2,"name":"PYTHON FOR AI AND LLM (PYAI) > Scikit-Learn > Model Evaluation"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/python\/#website","url":"https:\/\/gigz.pk\/python\/","name":"One Language. Endless Possibilities","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/python\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson\/177","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/media?parent=177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}