Skip to content
C.W.K.
Stream
Lesson 01 of 05 · published

What Regression Means

~24 min · regression, framing

Level 0Scout
0 XP0/48 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

Regression predicts magnitude

Regression estimates a continuous value or count: price, demand, latency, revenue, or days until churn. Unlike classification, the distance and direction of an error matter. Predicting 101 instead of 100 is not the same failure as predicting 1,000.

Contract the unit and horizon

State whether revenue is dollars or won, latency is an average or 99th percentile, and demand is daily or weekly. Name the prediction time, horizon, and decision owner. The same target name with a different aggregation window is a different problem and needs a different evaluation.

Draw the cost of error

Ask what errors of size 1 and 10 cost in both directions. Cost may grow linearly, quadratically, or asymmetrically. That shape should choose MAE, RMSE, quantile loss, or a custom business-cost metric rather than convenience.

Respect natural bounds

Counts are non-negative and probabilities live in [0, 1]. An unconstrained linear model may produce negative demand or 130 percent. Consider a suitable target transformation, link function, or distribution rather than hiding the issue by clipping every output.

The log transform changes differences into ratios

When the target spans orders of magnitude, as revenue, traffic, and latency often do, predict log1p(target). Equal errors in log space correspond roughly to equal ratios in original units, preventing a few giant examples from dominating. Use expm1 to invert when zeros are possible.

Evaluate again after inversion

A mean in log space does not invert to an unbiased mean in the original space. Recompute MAE, residual plots, and important segment errors in the units the user sees. Decide whether the product needs an uncertainty interval rather than only a point estimate.

Build the baseline in original units

Predict the training-set mean or median for every case before fitting a complex model. Compare the candidate on the same split and in the units used by the decision maker. Even after a target transformation, justify improvement through the benefit visible in the original problem.

Code

Predict log-target when the scale is multiplicative·python
import numpy as np
from sklearn.linear_model import Ridge
from sklearn.compose import TransformedTargetRegressor

model = TransformedTargetRegressor(
    regressor=Ridge(alpha=1.0),
    func=np.log1p,
    inverse_func=np.expm1,
).fit(X_train, y_train)
Bounded targets need bounded models·python
# For non-negative targets, use Poisson or Tweedie regression
from sklearn.linear_model import PoissonRegressor

model = PoissonRegressor(alpha=1.0).fit(X_train, y_train_counts)

External links

Exercise

For one regression problem, sketch the cost of an error of size 1 and an error of size 10. Decide whether the cost is linear, quadratic, or asymmetric. Pick the matching loss (MAE, MSE, quantile, custom).

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.