Mahamudul Hasan Rubel
HomeAboutProjectsSkillsExperienceBlogCoursesPhotosContact
Mahamudul Hasan Rubel

Senior Software Engineer crafting high-performance web applications and SaaS platforms.

Navigation

  • Home
  • About
  • Projects
  • Skills
  • Experience
  • Blog
  • Courses
  • Photos
  • Contact

Get in Touch

Available for senior/lead roles and consulting.

bd.mhrubel@gmail.comHire Me

© 2026 Mahamudul Hasan Rubel. All rights reserved.

Built with using Next.js 16 & Tailwind v4

Back to Blog
Lesson 19 of the AI/ML Foundations: Core Concepts & First Models course
AI/MLJune 25, 20264 min read

Mastering Regression Evaluation Metrics: RMSE, MAE, and R-squared

Learn to measure model accuracy with essential regression metrics. We break down RMSE, MAE, and R-squared so you can evaluate your predictions like a pro.

machine learningregressionscikit-learndata sciencemodel evaluationaimachine-learningpython

Previously in this course, we covered training the baseline linear model. Now that you have a model spitting out predictions, you need a way to determine if those numbers are actually good. In this lesson, we move beyond "it looks okay" and into the quantitative world of regression metrics.

When predicting continuous values like house prices or temperature, we measure performance by calculating the distance between our predicted values ($\hat{y}$) and the actual ground truth values ($y$).

Why We Use Multiple Regression Metrics

There is no "perfect" metric. A single number often hides the nature of your model's errors. We use a combination of metrics to understand the magnitude, direction, and explanatory power of our predictions.

1. Mean Absolute Error (MAE)

MAE is the simplest metric: it is the average of the absolute differences between predictions and actuals. If your model predicts a house price is $500k but it's actually $520k, the error is $20k.

Mathematically, it's the mean of $|y - \hat{y}|$. Because it uses absolute values, it doesn't penalize large errors more than small ones. It tells you, on average, how many units "off" your model is.

2. Root Mean Squared Error (RMSE)

RMSE is the standard for most regression tasks. We take the difference, square it, find the average, and then take the square root.

The squaring step is critical: it heavily penalizes large errors. If your model is consistently off by a small amount, your RMSE will be low. If your model is mostly accurate but makes a few massive "outlier" mistakes, your RMSE will spike.

3. R-Squared ($R^2$)

While MAE and RMSE tell you about the scale of your error, $R^2$ tells you about the quality of your fit. Often called the "Coefficient of Determination," it represents the proportion of variance in the target variable that your model explains.

An $R^2$ of 1.0 is a perfect model; an $R^2$ of 0.0 is equivalent to a model that simply guesses the average value of the target every single time.

Worked Example: Calculating Metrics with Scikit-Learn

In practice, you shouldn't calculate these by hand. Use scikit-learn to ensure precision and consistency.

PYTHON
import numpy as np
from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score

# Simulated data from our project
y_true = np.array([100, 150, 200, 250, 300])
y_pred = np.array([105, 145, 210, 240, 310])

# Calculate metrics
mae = mean_absolute_error(y_true, y_pred)
rmse = np.sqrt(mean_squared_error(y_true, y_pred))
r2 = r2_score(y_true, y_pred)

print(f"MAE: {mae:.2f}")
print(f"RMSE: {rmse:.2f}")
print(f"R-squared: {r2:.2f}")

In this example, the MAE tells us we are off by about 7 units on average. The RMSE is slightly higher, which alerts us that our errors are spread out.

Hands-on Exercise

Using the dataset you cleaned in project dataset initialization, load your test set predictions from your previous model.

  1. Calculate the MAE and RMSE.
  2. Interpret the $R^2$ value. If it's negative, don't panic—it just means your model is performing worse than a horizontal line representing the mean of your data.
  3. Compare the MAE and RMSE. If RMSE is significantly larger than MAE, search your predictions for large outliers that might be skewing the results.

Common Pitfalls

  • Ignoring the units: Always keep your MAE and RMSE in the context of the target variable. An RMSE of 500 is "good" for a house price model but "catastrophic" for a model predicting the number of people in a room.
  • Over-relying on $R^2$: A high $R^2$ does not mean your model has zero error. It only means your model captures a large portion of the trend. Always check your error metrics (MAE/RMSE) alongside it.
  • Sensitivity to scale: Remember that RMSE is sensitive to outliers. If your data has extreme values, consider scaling or capping them before training to prevent your metric from being dominated by a few bad rows.

Recap

Regression evaluation is about understanding the "distance" between your predictions and reality. Use MAE for an intuitive look at average error, RMSE to catch and penalize large mistakes, and R-squared to judge the overall explanatory power of your model. By mastering these regression metrics, you gain the ability to diagnose model performance objectively.

Up next: We will dive into the confusion matrix to see how we evaluate models that categorize data rather than predicting continuous numbers.

Previous lessonOverfitting and UnderfittingNext lesson The Confusion Matrix
Back to Blog

Similar Posts

AI/MLJune 25, 20264 min read

Training Error vs Generalization Error: A Practical Guide

Learn why high training performance often masks poor real-world results. Discover how to compare training and testing error to master model generalization.

Read more
AI/MLJune 25, 20264 min read

Evaluating Model Calibration: Accuracy Beyond Just Predictions

Learn how to evaluate model calibration using calibration curves and the Brier score. Ensure your predicted probabilities are accurate representations of reality.

Part of the course

AI/ML Foundations: Core Concepts & First Models

beginner · Lesson 19 of 50

  1. 1

    The Machine Learning Workflow

    4 min
  2. 2

    Setting Up the Python ML Environment

    4 min
  3. 3

    Introduction to NumPy for Data Handling

    4 min
Read more
AI/MLJune 25, 20264 min read

Model Interpretability Basics: Coefficients and SHAP Explained

Learn how to demystify your models using linear coefficients and SHAP values. Understand why transparency is essential for trust and debugging in production.

Read more
4

Loading and Inspecting Datasets with Pandas

3 min
  • 5

    Exploratory Data Analysis Fundamentals

    3 min
  • 6

    Handling Missing and Inconsistent Data

    3 min
  • 7

    Feature Selection and Basic Filtering

    3 min
  • 8

    Project Dataset Initialization

    3 min
  • 9

    Mechanics of Linear Regression

    4 min
  • 10

    Mechanics of Classification

    4 min
  • 11

    Loss Functions and Model Objectives

    4 min
  • 12

    Training and Testing Data Splits

    3 min
  • 13

    Data Scaling Techniques

    4 min
  • 14

    Encoding Categorical Variables

    3 min
  • 15

    Building Scikit-Learn Pipelines

    4 min
  • 16

    Training the Baseline Linear Model

    3 min
  • 17

    Training Error vs Generalization Error

    4 min
  • 18

    Overfitting and Underfitting

    4 min
  • 19

    Regression Evaluation Metrics

    4 min
  • 20

    The Confusion Matrix

    3 min
  • 21

    Error Analysis Plots

    4 min
  • 22

    Introduction to Cross-Validation

    4 min
  • 23

    Diagnosing Model Weaknesses

    3 min
  • 24

    Feature Engineering Strategies

    4 min
  • 25

    Handling Outliers

    3 min
  • 26

    The Bias-Variance Tradeoff

    3 min
  • 27

    Hyperparameter Tuning Basics

    4 min
  • 28

    Implementing Grid Search

    3 min
  • 29

    Refining the Project Model

    3 min
  • 30

    Evaluating Feature Importance

    3 min
  • 31

    Advanced Feature Transformation

    3 min
  • 32

    Regularization Techniques

    3 min
  • 33

    Comparing Different Algorithms

    3 min
  • 34

    Managing Model Complexity

    4 min
  • 35

    Understanding Data Drift

    4 min
  • 36

    Version Control for ML Experiments

    3 min
  • 37

    Exporting Trained Models

    3 min
  • 38

    Creating an Inference Script

    3 min
  • 39

    Building a Simple Web Interface

    3 min
  • 40

    Documenting ML Projects

    4 min
  • 41

    Final Project Review

    4 min
  • 42

    Ensemble Methods Overview

    4 min
  • 43

    Feature Selection via Recursive Elimination

    3 min
  • 44

    Model Interpretability Basics

    4 min
  • 45

    Dealing with High Cardinality

    3 min
  • 46

    Handling Multi-Collinearity

    4 min
  • 47

    Introduction to Pipelines with Custom Transformers

    3 min
  • 48

    Evaluating Model Calibration

    4 min
  • 49

    Advanced Hyperparameter Search

    3 min
  • 50

    Model Monitoring in Practice

    4 min
  • View full course