A numeric prediction report.
Fit a regression pipeline and report error in the target's unit beside a mean baseline.
Why this workflow exists.
A regression score is easier to interpret when the target has a unit and a simple comparison. This script creates an illustrative relationship between floor area and a price-like target measured in arbitrary units. It reserves a test set, fits a mean-only baseline, then fits a scaled Ridge regression model. Both are judged with mean absolute error, which remains in the target's unit.
The generated data contains noise so the fitted line cannot perfectly reproduce every target. The random generator seed keeps the example repeatable. Synthetic data is useful for understanding the pipeline, but it cannot prove anything about a real housing market.
Code context. Python 3 with scikit-learn installed. A reproducible synthetic dataset is generated locally.
The whole example.
import numpy as np
from sklearn.dummy import DummyRegressor
from sklearn.linear_model import Ridge
from sklearn.metrics import mean_absolute_error
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
rng = np.random.default_rng(8)
area = rng.uniform(40, 140, size=120)
price = 25 + 2.5 * area + rng.normal(0, 18, size=120)
X = area.reshape(-1, 1)
X_train, X_test, y_train, y_test = train_test_split(
X, price, test_size=0.25, random_state=8
)
baseline = DummyRegressor(strategy="mean").fit(X_train, y_train)
model = make_pipeline(StandardScaler(), Ridge(alpha=1.0))
model.fit(X_train, y_train)
for name, fitted in [("baseline", baseline), ("ridge", model)]:
errors = y_test - fitted.predict(X_test)
print(name, "MAE:", mean_absolute_error(y_test, fitted.predict(X_test)))
print(name, "mean residual:", errors.mean())What each stage does.
The generator creates 120 areas and a target with a linear tendency plus random variation. reshape makes X a two-dimensional feature table with one column. The split holds out 25% of rows. DummyRegressor learns only the training-target mean. The Ridge pipeline learns training-feature scaling and a regularized linear relationship.
The loop evaluates both fitted objects on identical test rows. MAE reports typical absolute error in the target unit. Mean residual indicates whether predictions are too low or too high on average, though positive and negative errors can cancel. A small mean residual does not imply small individual errors. The code computes both to make that distinction visible.
What the output means.
The Ridge model should have lower MAE than the mean baseline because the data-generating rule contains a strong area relationship. Exact values depend on the generated sample.
Where the example stops.
The data was generated from a simple linear rule. Real prices may depend on location, condition, time, and selection effects, so the example is about evaluation mechanics rather than a deployable predictor.