0Pricing
Data Science Academy · Lesson

Regression Metrics: MAE, MSE, R2

Measuring numeric prediction error.

Regression Metrics: MAE, MSE, R2 is a free Data Science Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Data Science Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Measure Error

When a model predicts numbers, you need one honest score for how far off it is. That score is an error metric, your truth-teller. 📏

The Residual Idea

Start with the residual: the gap between the true value and the predicted one. Every regression metric is just a way to summarize these gaps.

residual = y_true - y_pred

Mean Absolute Error

MAE takes the size of each error, ignores the sign, and averages them. It tells you the typical miss in the same units as your target.

from sklearn.metrics import mean_absolute_error
mean_absolute_error(y_true, y_pred)

MAE Is Easy to Explain

Because MAE stays in real units, you can say the model is off by about 5 dollars on average. Stakeholders love that plain reading.

Mean Squared Error

MSE squares each error before averaging. Squaring punishes big misses much harder, so a few large errors dominate the score.

from sklearn.metrics import mean_squared_error
mean_squared_error(y_true, y_pred)

Squaring Changes the Units

One catch: MSE is in squared units, so dollars become squared dollars. The number is hard to interpret on its own.

Root Mean Squared Error

Take the square root of MSE to get RMSE, back in normal units. It keeps the heavy penalty on big errors but reads cleanly.

rmse = mean_squared_error(y_true, y_pred) ** 0.5

MAE vs RMSE

Choose MAE when every error matters equally, and RMSE when large mistakes are especially costly and you want them penalized more.

The R-Squared Score

R2 asks a different question: what fraction of the variation in the target your model explains. Higher means a better fit.

from sklearn.metrics import r2_score
r2_score(y_true, y_pred)

Reading R-Squared

An R2 of 1.0 is perfect, 0.0 is no better than guessing the mean. It can even go negative when a model fits worse than that.

Use Them Together

No single number tells the whole story. Pair an error metric like RMSE with R2 to see both the typical miss and the overall fit.

Quick Check

Let's pin down what each regression metric really measures.

Recap

Use MAE for plain average error, RMSE to punish big misses, and R2 for fraction of variance explained. Read them together. 🎯

Frequently asked questions

Is the “Regression Metrics: MAE, MSE, R2” lesson free?

Yes — the full text of “Regression Metrics: MAE, MSE, R2” is free to read here on the web, and the Data Science Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Data Science Academy course, upgrade to CoddyKit PRO.

What will I learn in “Regression Metrics: MAE, MSE, R2”?

Measuring numeric prediction error. You practise Data Science Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Data Science Academy?

No prior experience is required. Data Science Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Regression Metrics: MAE, MSE, R2” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Data Science Academy lesson?

Yes. Every Data Science Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Regression Metrics: MAE, MSE, R2
  2. The Confusion Matrix Decoded
  3. Precision, Recall, and F1
  4. ROC, AUC, and Thresholds
← Back to Data Science Academy