Baseline and first estimator
Quick answer
A baseline is a deliberately simple comparison model. For absolute error, a constant training median minimizes the training sum of absolute deviations. A linear regression estimator instead learns an intercept and slope that minimize squared residuals. We compare both on the same validation rows using mean absolute error (MAE); ordinary least squares is a candidate model, not a guarantee of lower MAE. Examples use local Python 3.13.5 and scikit-learn 1.8.0 where imported. All fixtures are synthetic; ByteMind library execution is unverified.
Fit a median baseline
Predict processing time without using job size. A DummyRegressor with strategy="median" estimates the constant from training labels only.
from sklearn.dummy import DummyRegressorbaseline = DummyRegressor(strategy='median')baseline.fit([[1],[2],[3],[4]], [3,5,7,9])print(baseline.predict([[2],[5]]).tolist())Expected output:
[6.0, 6.0]The median of the four training durations is 6 seconds. Every new row receives the same prediction.
Fit a preprocessing and regression pipeline
make_pipeline joins a scaler and estimator. fit learns scaling and then fits regression on transformed training features. predict applies the stored transformations and model.
from sklearn.pipeline import make_pipelinefrom sklearn.preprocessing import StandardScalerfrom sklearn.linear_model import LinearRegressionmodel = make_pipeline(StandardScaler(), LinearRegression())model.fit([[1],[2],[3],[4]], [3,5,7,9])print(model.predict([[2],[5]]).round(6).tolist())Expected output:
[5.0, 11.0]The training pattern corresponds to y = 2x + 1 in the original feature units. The model extrapolates for size 5; the output is a prediction, not a known outcome.
Common mistakes
Do not compare training error from one model to validation error from another. A mean or median baseline must be fitted on training targets, never validation or test targets. Pipeline coefficients operate on transformed features; do not read them as raw-unit slopes without conversion. More complexity can hurt generalization.
Practice and next steps
Predict the baseline output when training labels are [1, 3, 100]. Explain why the median is less sensitive to the outlier than the mean. Try the constant baseline exercise. The separate pure-Python exercise assesses the underlying calculation, not library execution.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Baseline and first estimator — knowledge check
Apply experiment design and evaluation reasoning to synthetic examples.
Median of [1,3,100]?
What does a median dummy regressor use to predict?
What does ordinary linear regression minimize?
What does pipeline predict do?
Why compare with a baseline?