🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Machine Learning Notes
Topic #95

Linear Regression Assumptions

Linear regression's coefficients and confidence intervals are only trustworthy if certain assumptions about the data roughly hold. Violating them doesn't necessarily break the model outright, but it does undermine exactly how much you should trust its numbers.

The Five Assumptions

AssumptionMeaningHow to Check
LinearityThe relationship between features and target is genuinely linearScatter plots, residual plots
IndependenceResiduals aren't correlated with each otherEspecially relevant for time-series data (autocorrelation)
HomoscedasticityResidual variance is roughly constant across all predicted valuesResidual plot — should look like a random, even scatter
Normality of residualsResiduals are roughly normally distributedHistogram or Q-Q plot of residuals
No multicollinearityFeatures aren't highly correlated with each otherCorrelation matrix between features

Reading a Residual Plot — The Single Most Useful Diagnostic

Good — random scatter Bad — funnel (heteroscedasticity) Bad — curved (non-linearity)

Plot residuals against predicted values: random scatter around zero is healthy; a funnel or curve signals an assumption violation.

Checking Assumptions in Python

import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
import numpy as np

model = LinearRegression().fit(X_train, y_train)
predictions = model.predict(X_train)
residuals = y_train - predictions

# Homoscedasticity / non-linearity check
plt.scatter(predictions, residuals, alpha=0.6)
plt.axhline(0, color="red", linestyle="--")
plt.xlabel("Predicted values"); plt.ylabel("Residuals")
plt.show()

# Normality check
plt.hist(residuals, bins=20)
plt.show()

# Multicollinearity check
import pandas as pd
print(pd.DataFrame(X_train).corr())

What to Actually Do When an Assumption Is Violated

ViolationCommon Fix
Non-linearityAdd polynomial features, or switch to a non-linear model
HeteroscedasticityTransform the target (e.g. log), or use a model less sensitive to this assumption
Non-normal residualsOften tolerable in practice for prediction; matters more for statistical inference (confidence intervals, p-values)
MulticollinearityDrop or combine correlated features, or use L2 regularization

Why These Assumptions Matter Less for Pure Prediction, More for Inference

If your only goal is prediction accuracy, moderate assumption violations often matter less than you'd expect — the model can still produce reasonably useful predictions. But if you intend to interpret the coefficients (e.g. "this feature increases price by X, with 95% confidence it's between Y and Z"), assumption violations directly undermine how trustworthy those specific numbers are.

Common Mistakes

  • Never checking a residual plot at all — this is the fastest, highest-value diagnostic and is skipped surprisingly often.
  • Treating a mild assumption violation as disqualifying, when in practice linear regression is often reasonably robust to small violations for prediction purposes.
  • Checking multicollinearity only via a correlation matrix, missing more subtle multi-feature collinearity that a single pairwise check wouldn't reveal.

Interview Relevance

Q: "What does a funnel-shaped residual plot indicate, and why does it matter?" Heteroscedasticity — the model's errors get larger (or smaller) as predicted values change, violating the constant-variance assumption; this undermines the validity of the model's confidence intervals and statistical significance tests, even if raw prediction accuracy is still reasonable.

Practice Question

You plot residuals vs predicted values and see a clear upward curve (not random scatter). Which assumption is violated, and what's a common fix?

Want to go beyond the notes?

Join CodingNow 2.0's Machine Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Linear Regression Assumptions – FAQs

Quick answers about learning Linear Regression Assumptions in Machine Learning.

This free note from CodingNow 2.0 explains Linear Regression Assumptions in Machine Learning — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Machine Learning topic on CodingNow 2.0, including Linear Regression Assumptions, is 100% free with no signup required.
With focused practice, most students grasp Linear Regression Assumptions in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now