Regression: lesson 4 of 5
Regression
Multiple Linear Regression and Coefficients
Explain how several features contribute to a linear prediction and interpret coefficients responsibly.
Concept
Multiple linear regression predicts one numeric target from several features. Conceptually:
prediction = intercept + coefficient_1 * feature_1 + coefficient_2 * feature_2 + ...
Each feature contributes to the prediction through its coefficient. This lets a house-price model use size, bedrooms, and age together instead of pretending one feature explains everything.
Example: Several House Features
import pandas as pd
from sklearn.linear_model import LinearRegression
homes = pd.DataFrame({
"size_sqft": [900, 1200, 1500, 1800, 2100],
"bedrooms": [2, 2, 3, 3, 4],
"age_years": [25, 18, 12, 8, 3],
"price": [180000, 230000, 295000, 345000, 405000],
})
X = homes[["size_sqft", "bedrooms", "age_years"]]
y = homes["price"]
model = LinearRegression()
model.fit(X, y)
coefficients = pd.DataFrame({
"feature": X.columns,
"coefficient": model.coef_,
})
print(coefficients)
model.coef_ follows the same order as the columns in X. Creating a table prevents a common mistake: interpreting a coefficient without knowing which feature it belongs to.
Holding Other Included Features Constant
If a size coefficient is positive, the model raises its prediction as size increases while holding the other included features constant. That phrase means the equation changes one input and leaves its other model inputs fixed. It is useful for reading the equation, but it does not mean real houses can change size while every relevant property characteristic remains unchanged.
| Feature | Illustrative coefficient | Careful interpretation |
|---|---|---|
size_sqft | 160 | Within this model, one more square foot raises the prediction by about $160 when other included inputs are fixed. |
bedrooms | 8000 | Adding one bedroom raises the prediction by about $8,000 under the same condition. |
age_years | -1200 | One more year lowers the prediction by about $1,200 within this fitted relationship. |
The values are illustrative, not output from the tiny example. Their purpose is to show units and conditional interpretation.
Why Coefficients Can Be Misleading
Coefficient size is not automatic feature importance. A coefficient for income may look small only because income is measured in dollars while a binary feature changes from 0 to 1. Correlated features can make coefficients unstable: house size and bedrooms often move together, so the model may divide their shared pattern differently across training samples.
Omitted variables also matter. A large size coefficient may partly capture desirable location if location is missing from the model. This is why coefficients are not causal effects and why a predictive model should not be treated as an economic explanation.
When to Use It
Use multiple linear regression when several available features may jointly improve a numeric prediction and you want a transparent starting model. It is often useful as a baseline or for a first analysis, but it can underfit nonlinear relationships and requires careful validation.
Failure Signals
Common Mistakes
- Assuming the largest raw coefficient is the most important feature.
- Ignoring different feature units and scales.
- Reading coefficients as causal effects.
- Forgetting that coefficient order matches X column order.
- Using highly correlated inputs without checking interpretation stability.
Best Practices
Keep feature names beside coefficients, state their units, and inspect feature relationships before explaining results. Evaluate on held-out data and distinguish predictive usefulness from causal interpretation. Feature scaling, transformations, and formal importance methods appear later because they require additional care.
Interview Perspective
Question: What does a multiple-regression coefficient mean? Answer: it is the model's predicted target change for a one-unit feature change while other included features stay fixed. What the interviewer is testing: careful conditional interpretation and awareness of confounding or correlated inputs. Follow-up: why can correlated features make coefficients unstable?
Practice Questions
- Why does a multiple-regression X contain several columns but y remain one target column?
- Interpret an age coefficient of
-500in a price model. - Why is it unsafe to compare a coefficient measured per dollar with one measured per bedroom?
- How could correlated size and bedroom features complicate coefficient interpretation?
- Give one omitted variable that could make a size coefficient misleading.
Quick Quiz
- What stays fixed in the usual coefficient interpretation? Answer: the other included model features.
- Do coefficients prove causation? Answer: no.
- Why create a feature-coefficient table? Answer: to preserve the correct feature order and interpretation.
Key Takeaway
Key Takeaways
Multiple linear regression combines several inputs in one transparent equation. Coefficients describe the fitted predictive relationship conditionally, not feature importance or causal effects by default.
Next Lesson
Next, extend linear models for curved patterns and control unnecessary flexibility.
Finish this lesson on your terms
Mark it complete when you have worked through the material and are ready to move on.