Baseline and feature pipeline
Quick answer
A baseline gives model improvements meaning. For temperature MAE, a constant equal to the training median is a simple baseline. A Ridge model with standardized inputs can learn associations while penalizing large coefficients. Objective: Fit a baseline and train-only feature transformations, then select a candidate on validation data. Examples are local, synthetic and not verified in ByteMind.
Train-only median
from statistics import mediantrain = [10, 12, 14]print(median(train))Expected output (locally tested): 12. Validation targets never enter the baseline fit.
How it works
For a constant c, MAE = sum(|y_i-c|)/n; a median minimizes the training absolute error. Standardization computes z_j=(x_j-m_j)/s_j using training feature statistics; apply those same numbers to validation and test. Handle constant features with a documented scale rule (StandardScaler uses scale 1 for zero variance). Ridge minimizes squared residuals plus alpha times the squared coefficient norm, not MAE itself; choose alpha using the task metric on validation. A pipeline ties the fitted scaler to the estimator, which avoids accidental refitting if used correctly. The capstone fits four candidates on the first 160 rows and chooses the lowest validation MAE on the next 60; tie-break by smaller alpha. It does not refit after selection. The final 60 stable rows and subsequent 40 shifted rows play no role in choosing hyperparameters. A median baseline ignores available features, so it is intentionally simple; a current-temperature persistence rule would be a useful stronger next comparison.
Reuse training scaling
train_mean, train_scale = 10, 2validation = [12, 16]print([(x-train_mean)/train_scale for x in validation])Expected output (locally tested): [1.0, 3.0]. The validation mean is not substituted for the training mean.
Common mistakes
Do not scale all partitions together or use the test set to choose alpha. Do not compare models on unequal target rows. Ridge optimizes a penalized squared loss even when selected with MAE.
Practice and next steps
Add an engineering persistence baseline using current_c on the same split in a new experiment with a new holdout. Explain why adding candidates after seeing test scores requires a fresh evaluation.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Baseline and feature pipeline — knowledge check
Apply baseline and feature pipeline to scenarios and small examples.
Which constant minimizes training MAE?
Where should scaler statistics be fitted?
What does Ridge penalize?
Where is alpha selected?
Which baseline improves this comparison?