Skip to content
E
Educatum

Pros and Cons of Linear Regression

Curated by Educatum AI teamLast updated:
Basic Concepts
Direct Answer

Linear regression offers simplicity, high interpretability via direct coefficient weights, low variance, and an exact closed-form Ordinary Least Squares solution. Its primary drawbacks are the assumption of a linear relationship in features, strong sensitivity to outliers under squared error loss, coefficient instability under multicollinearity, and unreliable extrapolation beyond the training range.

Study Card: Pros and Cons of Linear Regression

Direct Answer

Linear regression fits a linear function y^=Xβ\hat{y} = X\beta by minimizing the sum of squared residuals, admitting a closed-form Ordinary Least Squares (OLS) solution when XTXX^T X is invertible:

β^=(XTX)−1XTy\hat{\beta} = (X^T X)^{-1} X^T y

Pros:

  • Simplicity & Speed: Fast to fit (O(nd2+d3)O(n d^2 + d^3) exact solution or O(nd)O(n d) per gradient descent step) with low variance.
  • Interpretability: Each coefficient βj\beta_j quantifies the marginal effect of feature xjx_j on the target holding other features constant.
  • Baseline & Statistical Inference: Supports hypothesis tests and confidence intervals under classical regression assumptions.

Cons:

  • Linearity Assumption: Underfits complex non-linear patterns and feature interactions unless explicit basis/polynomial features are engineered.
  • Outlier Sensitivity: Squared error penalizes large residuals quadratically, allowing extreme outliers to pull the fitted line strongly.
  • Multicollinearity: Highly correlated features make XTXX^T X ill-conditioned or singular, inflating coefficient variance and flipping signs.
  • Poor Extrapolation: Linear trends can produce implausible predictions far outside the observed feature domain.

Key Terms

  • Linearity: Assumption that the expected target is linear in the model parameters β\beta (i.e., E[y∣X]=XβE[y \mid X] = X\beta).
  • Independent Variables (Features): Input predictors XX used to explain or forecast the target.
  • Dependent Variable (Target): Continuous outcome variable yy being predicted.
  • Coefficients (β\beta): Weights multiplying each feature, representing its marginal rate of change on y^\hat{y}.
  • Intercept (β0\beta_0): Expected output when all feature values equal zero.

Example

Consider predicting house prices from square footage. When price scales roughly linearly with size inside a single neighborhood, linear regression provides a transparent baseline where β1\beta_1 directly measures price per square foot. However, if neighborhood effects, property age curves (e.g., historic vs. brand-new), and non-linear luxury interactions strongly influence price, plain linear regression underfits without feature engineering or non-linear models, and a single ultra-luxury mansion outlier can skew the slope for typical homes.

Code Implementation

import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error

# Generate sample data with a linear relationship + noise
np.random.seed(0)
X = np.random.rand(100, 1) * 10
y = 2 * X + 1 + np.random.randn(100, 1)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Fit linear regression
model = LinearRegression()
model.fit(X_train, y_train)

# Predict and evaluate on test set
y_pred = model.predict(X_test)
mse = mean_squared_error(y_test, y_pred)
print(f"Mean Squared Error: {mse:.4f}")
print(f"Coefficients: {model.coef_}")
print(f"Intercept: {model.intercept_}")

# Sort test points before plotting the regression line cleanly
order = np.argsort(X_test[:, 0])
plt.scatter(X, y, label="Data")
plt.plot(X_test[order], y_pred[order], color='red', label="Regression Line")
plt.xlabel("House Size")
plt.ylabel("House Price")
plt.title("Linear Regression Example")
plt.legend()
plt.show()
  • Polynomial & Basis Regression: Adds non-linear feature transformations (polynomials, splines) while keeping the model linear in β\beta; high-degree polynomials risk severe overfitting and Runge oscillations.
  • Regularization (L1, L2): Ridge (L2L_2) stabilizes ill-conditioned XTXX^T X matrices via (XTX+λI)−1XTy(X^T X + \lambda I)^{-1} X^T y; Lasso (L1L_1) performs feature selection.
  • Robust Regression: Huber loss or RANSAC mitigates sensitivity to outliers compared to OLS squared error.
  • Gauss-Markov Assumptions: Under linearity, zero conditional error mean, independence, and homoscedasticity (constant error variance), OLS is the Best Linear Unbiased Estimator (BLUE) without requiring Gaussian errors; error normality is additionally assumed for exact finite-sample t/Ft/F-tests, confidence intervals, and MLE equivalence.
  • Multicollinearity Diagnostics: Variance Inflation Factor (VIF) and condition numbers detect correlated predictors, addressable via feature removal, PCA, or Ridge regularization.
View all →

Try keywords like RoPE, FlashAttention, DPO, or Blind 75.