Lesson 8 of 18 · 2 min
When Linear Regression Fails
Linear regression assumes a straight-line relationship. It fails when:
- Data is curved (non-linear) — use polynomial regression or tree models
- Outliers are extreme — they pull the line significantly
- Features are highly correlated with each other (multicollinearity) — coefficients become unreliable
import matplotlib.pyplot as plt
# Check for multicollinearity — correlation between features
import seaborn as sns
corr = X.corr()
plt.figure(figsize=(10, 8))
sns.heatmap(corr, annot=True, cmap="coolwarm", fmt=".2f")
plt.title("Feature Correlation Matrix")
plt.show()
# If two features have correlation > 0.9 — consider dropping one
