Based on the MLS-C01 exam guideReport an error
y − ŷ. Do you square it, take the absolute value, or use a ratio?RMSE ≥ MAE.If classification asks "was it right or wrong," regression measures "how far off was it." For each sample i, the error is as follows.
residual_i = y_i (actual value) - ŷ_i (predicted value)Every regression metric gathers these errors and compresses them into one score. The difference lies in how the error is handled — do you square it, take the absolute value, or look at it as a ratio?
MAE = (1/n) Σ |y_i - ŷ_i|
MSE = (1/n) Σ (y_i - ŷ_i)²
RMSE = √[ (1/n) Σ (y_i - ŷ_i)² ]| Item | MAE | RMSE |
|---|---|---|
| Error handling | Absolute value | Square, then square root |
| Unit | Same as target (e.g., dollars) | Same as target |
| Outlier sensitivity | Low (robust) | High (amplifies) |
| Treatment of all errors | Equal | Weights large errors |
| Suitable situation | When outliers are a data quality problem | When a single large mistake is fatal |
| What it optimizes | Conditional median | Conditional mean |
Errors [1, 1, 1, 1, 6]
MAE = (1+1+1+1+6)/5 = 2.0
RMSE = √((1+1+1+1+36)/5) = √8 = 2.83 ← the error of 6 stands out moreThe choice between RMSE and MAE is a question of "how heavily do you penalize large errors." RMSE penalizes large errors strongly through squaring, so it fits problems where a single large mistake is fatal (stockouts from under-forecasting demand, etc.). MAE reflects large errors only proportionally, so it is stable when outliers are a data quality problem (sensor errors, etc.).
MAPE = (100%/n) Σ |y_i - ŷ_i| / |y_i|It converts the error into a ratio (%) of the actual value and averages it.
y_i is 0 or close to 0, the denominator blows up or becomes undefined[How the same absolute error of 1.0 looks depending on the actual value]
Actual y = 1000, predicted 1001 → |1|/1000 = 0.1%
Actual y = 10, predicted 11 → |1|/10 = 10.0%
Actual y = 1, predicted 2 → |1|/1 = 100.0%
Actual y = 0.1, predicted 1.1 → |1|/0.1 = 1000.0% ← a single case dominates the average
Actual y = 0, predicted 1 → |1|/0 = undefined (∞)⚠️ Trap: Don't pick MAPE just because you see "I want to compare stores with different scales." If the passage also says "some stores' sales are close to 0" or "there are days with no demand," MAPE is the wrong answer, and if scale correction is needed, consider RMSLE or per-store normalization.
R² = 1 - (SS_res / SS_tot)
SS_res = Σ (y_i - ŷ_i)² (sum of squared model errors)
SS_tot = Σ (y_i - ȳ)² (variance relative to the mean line)It measures "what % of the target's variance the model explains."
| R² value | Meaning |
|---|---|
| 1.0 | Perfect prediction (SS_res = 0) |
| 0.7 ~ 0.9 | Considerable explanatory power |
| 0 | Same level as simply predicting the mean (ȳ) |
| Negative | A model worse than the mean — it captures no signal at all |
Adding features raises R² even when it means nothing. Even an unrelated column reduces SS_res slightly by fitting the noise.
Adjusted R² = 1 - (1 - R²) × (n - 1) / (n - p - 1)
n = number of samples, p = number of features (explanatory variables)| Item | R² | Adjusted R² |
|---|---|---|
| When features are added | Never decreases | Decreases if there is no contribution |
| Range of values | Max 1 (can be negative) | Max 1, always less than or equal to R² |
| Use | Explanatory power of a single model | Comparing models with different numbers of features |
| Pitfall | Looks better just by adding features | Gets sharply worse when sample size n is small and p is large |
The key point is that R² measures "how much better than the baseline." The baseline is always the target mean (ȳ). So a negative R² means the model is worse than the simple mean, a strong warning that the model captured no signal at all. RMSE/MAE tell you the absolute size of the error, and R² tells you relative explanatory power, complementing each other.
| Metric | Unit | Outlier sensitivity | When to use | When not to use |
|---|---|---|---|---|
| MAE | Same as target | Low | When outliers are noise, when an easily interpreted error is needed | When you want to penalize large errors especially |
| RMSE | Same as target | High | When large mistakes are fatal, as the default tuning metric | When outliers are a data quality problem such as sensor errors |
| MSE | Square of the target unit | Very high | As an optimization loss function | When reporting results to people (the unit can't be interpreted) |
| MAPE | % (unitless) | Medium | Comparing items of different scale, when relative error is meaningful | When the actual value is 0 or near 0 |
| R² | Unitless | High (sum-of-squares based) | When reporting explanatory power as a ratio | Decisions where absolute error size matters |
| Adjusted R² | Unitless | High | When comparing models with different numbers of features | When samples are very few |
| RMSLE | Log scale | Low | When the target is heavily skewed and relative error matters | When there are negative targets |
You need to choose a regression metric
├─ Does the data have extreme outliers, and are they errors?
│ ├─ Yes → MAE (robust because it doesn't square)
│ └─ No ↓
├─ Is a single large error fatal to the business? (stockouts, overcharging, etc.)
│ ├─ Yes → RMSE (penalizes large errors by squaring)
│ └─ No ↓
├─ Must items of widely varying scale be compared with one metric?
│ ├─ No actual values near 0 → MAPE
│ └─ Actual values of 0 are common → No MAPE, use RMSE/MAE or normalization
└─ Must you report "how much it explains" as a ratio?
├─ Single model → R²
└─ Comparing models with different numbers of features → Adjusted R²
Even if one metric says the model is good, the model may have a systematic flaw. Drawing a residual plot (predicted value vs. residual) reveals it.
① Ideal — constant variance, no pattern ② Funnel — heteroscedasticity
Residual Residual
+│ · · · · · +│ · ·
│ · · · · · │ · · · ·
0├──·──·───·──·───·──→ Predicted 0├──·──·───·───·────·──→
│ · · · · · │ · · · ·
-│ · · · · -│ · ·
→ centered on residual 0, constant width → spreads out as the prediction grows
③ U-shape/curve — nonlinearity not captured ④ Skew — systematic bias
Residual Residual
+│ · · +│ · · · · · ·
│ · · │ · · · · · ·
0├────·─────────·────────→ 0├──────────────────────→
│ · · · │
-│ · · · │ (almost all above 0)
→ limit of a linear model, needs feature → consistently under-predicting
transformation| Pattern | Diagnosis | Action |
|---|---|---|
| Random scatter, constant width | Normal | Proceed as is |
| Curve/U-shape | Nonlinearity not captured | Feature transformation (square, log), nonlinear models (trees, boosting) |
| Funnel shape | Heteroscedasticity | Log-transform the target, weighted regression |
| Skewed to one side | Bias, systematic over/under-prediction | Recheck intercept/features, check for data shift |
| Autocorrelation along the time axis | Time-series structure not reflected | Lag features, time-series models |
import matplotlib.pyplot as plt
residuals = y_true - y_pred
plt.scatter(y_pred, residuals, alpha=0.3)
plt.axhline(0, color="red", linestyle="--")
plt.xlabel("Predicted value")
plt.ylabel("Residual (actual - predicted)")
# Random scatter is good; if you see a pattern, the model's assumptions are violatedEven with a low RMSE, if the residuals have a pattern, the model can't be trusted. That's because a single metric averages the errors into one number and erases "where and how" it's wrong. The residual plot restores the structure that the average hid — nonlinearity, heteroscedasticity, bias. On the exam, a passage like "the metric is good but it keeps being wrong in a particular range" points toward residual analysis / checking the model form.
Built-in regression algorithms emit RMSE as the default validation metric. An example of a regression objective metric in Automatic Model Tuning:
tuner = HyperparameterTuner(
estimator=xgb_estimator,
objective_metric_name="validation:rmse", # regression default
objective_type="Minimize", # it's an error, so minimize
hyperparameter_ranges=ranges,
)⚠️ Trap: Classification is usually Maximize (accuracy/F1/AUC), and regression is Minimize (RMSE/MAE). If you set
objective_typethe wrong way around, the tuner picks the worst model. If you use a regression metric where larger is better like R², then it's Maximize.
| Passage clue | Answer to pick | Reason |
|---|---|---|
| "Extreme outliers from sensor errors are mixed in" | MAE | Robust to outliers because it doesn't square |
| "RMSE is markedly larger than MAE" | A few large errors (outlier-like residuals) exist | Only RMSE is amplified by squaring |
| "Stockouts are fatal, so large under-forecasts must be avoided" | RMSE | Strongly penalizes large errors |
| "Compare stores with different sales volumes" | MAPE | Scale-free relative error |
| "But some stores' sales are close to 0" | MAPE is unsuitable | Distorted by the denominator blowing up |
| "R² came out at -0.2" | Worse than predicting the mean | The baseline is the target mean (ȳ) |
| "I added features and only R² went up" | Compare with Adjusted R² | Penalizes the number of features |
| "RMSE is good but the residuals form a U-curve" | Nonlinearity not captured → feature transformation/nonlinear model | Violates the assumed model form |
| "Residuals spread out as the prediction grows" | Heteroscedasticity → consider a log transform of the target | Classic funnel pattern |
| "What objective_type for regression tuning?" | Minimize (RMSE/MAE basis) | For error metrics, smaller is better |
Tomorrow we move on to tools that look into why a model is wrong — SageMaker Debugger, Clarify (bias detection, SHAP explainability), and error analysis.
Click a choice to reveal the answer and explanation.
Question 1
The data has a few extreme outliers caused by sensor errors, and you want an evaluation metric that doesn't overreact to them. What is the most appropriate choice?
Question 2
On the same prediction results, RMSE came out markedly larger than MAE. What does this suggest?
Question 3
You want to compare the prediction performance of several stores with widely varying sales volumes regardless of scale. However, some stores have sales close to 0. Which statement about the caveat of this metric is correct?
Question 4
A regression model's R² was calculated as -0.2. What does this mean?
Question 5
The RMSE is low and satisfying, but the residual plot (predicted value vs. residual) shows a clear U-shaped curve. What is the most reasonable interpretation and action?