promptdojo_

Regression metrics and residuals — step 7 of 7

Checkpoint

One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.

Build R² from scratch and put it next to the baseline it secretly contains. Compute ss_res (sum of squared model errors), ss_tot (sum of squared deviations of actuals from their mean), and R² = 1 - ss_res/ss_tot. Then compute the predict-the-mean baseline's MAE and the model's MAE. Print: f"R^2 = {r2:.2f}", f"predict-the-mean MAE = {...:.1f}", f"model MAE = {...:.1f}", and "beats the baseline:" with the comparison. R² is chapter 38's baseline rebuilt as a metric: 0 means no better than the mean, 1 means perfect.

full-screen editor opens — close anytime to keep reading.