Regression: lesson 4 of 5

Regression

PATH 02MODULE 02LESSON 04 OF 05Next: Extending and Controlling Linear Models

Multiple Linear Regression and Coefficients

Explain how several features contribute to a linear prediction and interpret coefficients responsibly.

Intermediate17 min readmachine-learningregressioncoefficientsmultiple-features

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.

FeatureIllustrative coefficientCareful interpretation
size_sqft160Within this model, one more square foot raises the prediction by about $160 when other included inputs are fixed.
bedrooms8000Adding one bedroom raises the prediction by about $8,000 under the same condition.
age_years-1200One 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

  1. Assuming the largest raw coefficient is the most important feature.
  2. Ignoring different feature units and scales.
  3. Reading coefficients as causal effects.
  4. Forgetting that coefficient order matches X column order.
  5. 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

  1. Why does a multiple-regression X contain several columns but y remain one target column?
  2. Interpret an age coefficient of -500 in a price model.
  3. Why is it unsafe to compare a coefficient measured per dollar with one measured per bedroom?
  4. How could correlated size and bedroom features complicate coefficient interpretation?
  5. Give one omitted variable that could make a size coefficient misleading.

Quick Quiz

  1. What stays fixed in the usual coefficient interpretation? Answer: the other included model features.
  2. Do coefficients prove causation? Answer: no.
  3. 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.