Bias of linear regression
Under classical Gauss-Markov assumptions where the true relationship is linear and correctly specified, ordinary least squares (OLS) is statistically unbiased. However, linear regression carries strong inductive bias by restricting hypotheses to linear hyperplanes, causing high approximation bias and systematic underfitting whenever the true target function is non-linear or omits key interaction terms.
Study Card: Bias of linear regression
Direct Answer
When discussing the “bias” of linear regression, it is important to distinguish statistical estimator bias from inductive (approximation) bias. Under the Gauss-Markov assumptions—specifically when the true data-generating process is linear ( with ) and features have full column rank—the ordinary least squares (OLS) estimator is unbiased (). However, because linear regression assumes an affine relationship , it has strong inductive bias: whenever the true underlying pattern is non-linear or depends on unmodeled feature interactions, the model exhibits high approximation bias, leading to systematic prediction errors and underfitting.
Key Terms
- Approximation (Inductive) Bias: Systematic error introduced by restricting a model family to a linear function when the real-world relationship is non-linear.
- Estimator Unbiasedness: Under correct linear specification and exogeneity, .
- Intercept (“Bias” Term ): The constant offset parameter allowing the hyperplane not to pass through the origin—distinct from statistical bias.
- Underfitting: Failure to capture the true underlying trend, producing high error on both training and test data.
- Irreducible Error: Intrinsic noise in the target that cannot be removed by adding features or increasing model flexibility.
Example
Imagine fitting a straight line to data following a U-shaped quadratic relationship on . Because the left half decreases and the right half increases symmetrically around , OLS fits a nearly flat horizontal line at the average . It systematically underpredicts near and and overpredicts near . Even with infinite training data, this structural error persists unless we engineer non-linear features (e.g., ) or adopt a non-linear model.
Code Implementation
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
# Generate non-monotonic quadratic data where a straight line cannot fit the curvature
np.random.seed(0)
X = np.linspace(0, 10, 100).reshape(-1, 1)
y = (X.ravel() - 5) ** 2 + np.random.normal(0, 2.5, 100)
# Fit linear regression
model = LinearRegression()
model.fit(X, y)
y_pred = model.predict(X)
# Plot actual vs linear fit
plt.scatter(X, y, label='Actual Data')
plt.plot(X, y_pred, color='red', linewidth=2, label='Linear Regression Fit')
plt.xlabel("X")
plt.ylabel("y")
plt.title("Linear Regression Underfitting Non-Linear Data")
plt.legend()
plt.show()
# R-squared is near 0 because a straight line cannot capture the symmetric U-shape
print(f"R-squared: {model.score(X, y):.4f}")
Related Concepts
- Gauss-Markov Theorem: States that when linearity, strict exogeneity, homoscedasticity, and no autocorrelation hold, OLS is the Best Linear Unbiased Estimator (BLUE) with minimum variance among linear unbiased estimators.
- Polynomial & Basis Expansions: Adding non-linear basis terms (e.g., , splines, or interaction features) lowers approximation bias while keeping the model linear in parameters .
- Regularization (Ridge / Lasso): Intentionally introduces small estimator bias () in exchange for reduced variance and improved generalization under collinearity or high dimensionality.
- Residual Diagnostics: Plotting residuals against predictions reveals non-random curvature when linearity assumptions are violated.