Fitting Lines, Parabolas, and Planes
Least squares shines when fitting curves to data. Given data points , we want a polynomial that fits them best. Writing out for all gives the overdetermined system .
The matrix is the Vandermonde matrix: row is . Solving the normal equations gives the polynomial with the minimum total squared error.
For a line (): has columns and . The normal equations solve for the slope and intercept of the least squares line.
For a plane fitting 3D data: we have two input variables, so rows of become and we solve for the coefficients of . The same normal equations apply — the geometry generalizes seamlessly to higher dimensions.
Formal View
Why This Matters
Polynomial curve fitting is the simplest form of supervised machine learning and underpins everything from trend analysis to scientific modeling.
- Data science: fitting trend lines and polynomial models in regression
- Physics: fitting calibration curves for sensors and instruments
- Finance: polynomial trend fitting for time series analysis
- Biology: fitting dose-response curves in pharmacology
Quiz
When fitting a degree-1 polynomial (line) to points, the matrix has how many columns?
Fitting a degree- polynomial to distinct points always gives zero residual.
The Vandermonde matrix for fitting a degree-2 polynomial to 5 data points has shape:
Common Mistakes
- Using too high a polynomial degree — the fit looks perfect in-sample but generalizes poorly (overfitting).
- Forgetting the constant column of ones in the Vandermonde matrix — omitting it forces the fitted polynomial through the origin.
- Confusing interpolation (exact fit, ) with regression (best fit, small ) — they solve different problems.