Multiple regression and intercept
Quick answer
Multiple linear regression predicts a numerical target using several features: yhat = b + w1x1 + ... + wpxp. The coefficient for a feature is the fitted change when that feature increases by one unit and the others are held fixed. The intercept is a separate constant term, not another observed feature. All code examples run locally in Python 3.13.5; library examples use scikit-learn 1.8.0 or NumPy 2.3.5. ByteMind package execution is unverified.
Predict with two features
b=5; w=[2,-1]X=[[4,3],[4,5],[0,0]]print([b+sum(a*c for a,c in zip(row,w)) for row in X])Expected output:
[10, 8, 5]Only changing the second feature from 3 to 5 reduces the prediction by 2.
How it works
For n observations and p features, X has shape (n,p), w has p coefficients, and y has n entries for one target. To solve with a matrix method, prepend a column of ones to X to obtain A of shape (n,p+1); beta=[b,w1,...,wp]. Then predictions are A @ beta. In scikit-learn LinearRegression(fit_intercept=True) handles the constant internally, so do not also add a ones column unless deliberately studying redundant parameterizations. fit_intercept=False constrains b to zero; it is not simply a faster equivalent fit. With an explicit intercept column, unique OLS coefficients require full column rank. Correlated predictors can make coefficients unstable; identical predictors can make them nonunique. A coefficient holds other modeled features fixed algebraically, not experimentally. Confounding, selection bias and measurement error can prevent causal interpretation. Keep feature order and units identical at inference.
Recover coefficients from a full-rank fixture
from sklearn.linear_model import LinearRegressionX=[[0,0],[1,0],[0,1],[1,1]]y=[5,7,4,6]m=LinearRegression().fit(X,y)print([round(float(v),2) for v in m.coef_],round(float(m.intercept_),2))print(round(float(m.predict([[4,3]])[0]),2))Expected output:
[2.0, -1.0] 5.010.0The two independent features and constant term recover the synthetic data rule.
Common mistakes
Do not confuse a large coefficient with feature importance when features have different units. Do not use fit_intercept=False merely because training features were centered: the target may still have a nonzero mean.
Practice and next steps
Use b=5 and coefficients [2,-1] to predict for [4,3]. Change only the second feature by two units and explain the difference. Complete the chapter knowledge check and coding exercise. Next: QR and SVD solvers.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Multiple regression and intercept — knowledge check
Apply multiple regression and intercept to small regression fixtures.
For 20 rows and 3 features, what is X shape?
What explicit column encodes an intercept in a design matrix?
b=1, w=[2,3], x=[4,5]: prediction?
What does fit_intercept=False do?
Does a fitted coefficient establish causation?