🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Deep Learning Notes
Topic #153

Regression Metrics

This note collects the standard evaluation metrics for regression tasks — MAE, MSE and RMSE were already introduced as training losses in the Loss Functions category; here, the focus shifts to , the metric most often reported alongside them for evaluating how good a regression model actually is.

MAE, MSE, RMSE — As Evaluation Metrics

Any of the regression losses covered in Mean Absolute Error, Mean Squared Error, and Root Mean Squared Error can double as an evaluation metric, computed on validation or test data rather than used to drive gradient updates. RMSE is the most commonly reported of the three specifically because its units match the target variable directly, as covered in that earlier note.

R² (Coefficient of Determination)

\[ R^2 = 1 - \frac{SS_{\text{res}}}{SS_{\text{tot}}}, \qquad SS_{\text{res}}=\sum_i(y_i-\hat y_i)^2, \qquad SS_{\text{tot}}=\sum_i(y_i-\bar y)^2 \]

\(SS_{\text{res}}\) (residual sum of squares) is exactly the numerator behind MSE — the model's actual prediction error. \(SS_{\text{tot}}\) (total sum of squares) measures how much the true values vary around their own mean \(\bar y\) — essentially, the error a trivial "always predict the average" baseline model would make. \(R^2\) measures what fraction of that baseline variance the model actually explains.

Interpreting R²

\(R^2\) ValueInterpretation
1.0The model perfectly predicts every value — \(SS_{\text{res}}=0\)
0.0The model performs exactly as well as always predicting the mean — no better than a trivial baseline
NegativeThe model performs worse than simply always predicting the mean — a genuinely bad model

Numerical Example

True values \([10, 20, 30]\), predictions \([12, 18, 35]\), mean \(\bar y = 20\). \(SS_{\text{res}} = (10-12)^2+(20-18)^2+(30-35)^2 = 4+4+25=33\). \(SS_{\text{tot}} = (10-20)^2+(20-20)^2+(30-20)^2 = 100+0+100=200\).

\[ R^2 = 1-\frac{33}{200} = 1-0.165 = 0.835 \]

The model explains about 83.5% of the variance in the true values relative to simply always guessing the mean.

Code

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

y_true = np.array([10, 20, 30])
y_pred = np.array([12, 18, 35])

print(r2_score(y_true, y_pred))                     # 0.835
print(np.sqrt(mean_squared_error(y_true, y_pred)))   # RMSE, for comparison

Common Mistakes

  • Assuming R² is always between 0 and 1 — a genuinely poor model (worse than the trivial mean-prediction baseline) can produce a negative R², which is a valid, meaningful result signaling a serious problem.
  • Comparing R² values across datasets with very different amounts of inherent variance — a high R² on a low-variance dataset and a lower R² on a high-variance, noisier dataset don't necessarily reflect a real difference in model quality.

Interview Relevance

Q: "What does it mean for a regression model to have a negative R²?" It means the model performs worse than the trivial baseline of always predicting the target's mean value — a clear sign of a poorly fit or fundamentally broken model, since even ignoring the input features entirely and guessing the average would do better.

Practice Question

For true values \([5, 10, 15]\) and predictions \([5, 10, 15]\) (a perfect model), what is \(R^2\)? What about for predictions that are all exactly the mean of the true values, \([10, 10, 10]\)?

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Regression Metrics – FAQs

Quick answers about learning Regression Metrics in Deep Learning.

This free note from CodingNow 2.0 explains Regression Metrics in Deep Learning — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including Regression Metrics, is 100% free with no signup required.
With focused practice, most students grasp Regression Metrics in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now