This interactive demo helps you understand how linear regression works with different loss functions. Adjust the sliders to modify the regression line and observe how it affects both MSE (Mean Squared Error) and MAE (Mean Absolute Error) in real-time.
As seen in Demo 1, every point in parameter space (w₀, w₁) corresponds to a line in feature space. The optimal parameters are found at the lowest point of the loss surface.
Each point on the parameter space surfaces represents a possible model with specific slope and intercept values. The height of the surface shows the loss value for that model. The MSE surface is smooth and bowl-shaped with a unique minimum, while the MAE surface has sharper edges and can have multiple optimal solutions along a line.
Linear regression finds a linear relationship between variables: \( \hat{y} = w_0 + w_1 x \), where \(w_0\) is the intercept and \(w_1\) is the slope.
MSE squares the errors, giving more weight to large errors. It produces a smooth, bowl-shaped loss surface with a unique global minimum.
The analytical solution for minimizing MSE is:
MAE uses the absolute value of errors, treating all error magnitudes more uniformly. It produces a more angular loss surface and is more robust to outliers.
The solution for minimizing MAE often involves:
Aspect | MSE | MAE |
---|---|---|
Sensitivity to Outliers | High (squares errors) | Low (linear penalty) |
Loss Surface | Smooth, differentiable everywhere | Angular, not differentiable at zero error |
Computational Complexity | Simple closed-form solution | Requires median calculations |
Optimal Solution | Mean-centered | Median-centered |