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

Linear Regression Intuition

~28 min · linear, regression

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

The geometry

With one feature, linear regression fits a line through a cloud of points; with more features it fits a hyperplane. A prediction is the intercept plus the sum of each feature multiplied by its coefficient. That additive structure makes the path from inputs to output comparatively easy to inspect.

Read coefficients in units

A coefficient is the change in predicted target for a one-unit feature increase while the other included features are held constant. Dollars and millions of dollars produce different coefficient numbers for the same predictions. Standardized coefficients are easier to compare, but translate them back to original units for a business explanation.

Interpret the intercept within the data

The intercept is the prediction when every feature is zero. That point may be impossible, such as age zero and income zero. Centering numeric features makes the intercept closer to the prediction for an average input. Always include category reference levels and transformations when explaining it.

Why it still matters

Linear regression is a fast baseline, easy to explain, stable on small and medium data, and cheap to serve. Treat it as the floor: a fancier model must beat it on the metric you care about by a margin that justifies additional memory, latency, monitoring, and explanation cost.

Inspect the residual shape

A linear model assumes the useful relationship can be represented additively after sensible transformations. Plot residuals against predictions and important features. Curves, fans, and group-specific bands reveal missing nonlinearities, changing variance, or interactions before you reach for a larger model.

Reading coefficients honestly

Coefficients are correlational, not causal. A positive coefficient on "days_since_signup" does not mean making customers older causes them to churn. Omitted variables, selection, and reverse causality can all create the association.

Multicollinearity destabilizes stories

Strongly related features can divide credit in many ways. Predictions may remain stable while individual signs and magnitudes wobble across samples. Inspect correlations and coefficient stability, combine redundant features when explanation matters, and use regularization.

Code

Plain linear regression and inspecting coefficients·python
from sklearn.linear_model import LinearRegression
import pandas as pd

lr = LinearRegression().fit(X_train, y_train)
coefs = pd.Series(lr.coef_, index=X_train.columns).sort_values(key=abs, ascending=False)
print(coefs.head(10))
print("intercept:", lr.intercept_)
Standardize before comparing coefficient magnitudes·python
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LinearRegression

pipe = Pipeline([("scale", StandardScaler()), ("lr", LinearRegression())]).fit(X_train, y_train)
# Now coef magnitudes are comparable across features

External links

Exercise

Train a standardized linear regression on your dataset. Print the top-10 features by absolute coefficient. For each, write one sentence about whether the sign and magnitude match your prior. Investigate any surprises.

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.