Polynomial fit calculator
Fitting a polynomial to data finds the curve that best follows a set of measured points, the heart of regression and trend analysis. This calculator fits the most common case, a degree-one polynomial, the least-squares straight line of best fit, to five data points. You enter the x and y value of each point, and it returns the slope and intercept of the line that minimizes the total squared vertical distance from the points, along with the coefficient of determination, R-squared, which measures how much of the variation in y the line explains. The slope and intercept come from the standard normal equations, built from the sums of x, of y, of x times y and of x squared across the points. R-squared runs from 0, where the line explains none of the variation, to 1, a perfect fit. A line of best fit is the workhorse of forecasting, calibration and experimental science. Enter your own points to fit a trend, calibrate an instrument or check an exercise. Every figure here is computed deterministically from the least-squares normal equations, shown in full below with a worked example that reconciles exactly to the calculator so you can follow each step.
The least-squares line has slope (n sum xy minus sum x sum y) / (n sum x squared minus (sum x) squared) and intercept (sum y minus slope times sum x) / n. For the points (1,2), (2,3), (3,5), (4,4), (5,6) the best-fit line is y = 0.90 x + 1.30 with R-squared 0.81.
Least-squares line of best fit
slope m = ( n sum(xy) - sum(x) sum(y) ) / ( n sum(x^2) - (sum x)^2 )
intercept c = ( sum(y) - m sum(x) ) / n
line: y = m x + c
R^2 = 1 - SS_residual / SS_total
n = number of points
The normal equations choose the slope and intercept that make the sum of squared vertical gaps between the points and the line as small as possible. R-squared compares the leftover scatter around the line to the total scatter around the mean, giving the share of variation the line explains.
Worked example
Fit a line to the five points (1, 2), (2, 3), (3, 5), (4, 4) and (5, 6).
- Sums: sum x = 15, sum y = 20, sum xy = 69, sum x^2 = 55, n = 5
- Slope = (5 x 69 - 15 x 20) / (5 x 55 - 15^2) = (345 - 300) / (275 - 225) = 45 / 50 = 0.90
- Intercept = (20 - 0.90 x 15) / 5 = (20 - 13.5) / 5 = 6.5 / 5 = 1.30
- Line of best fit: y = 0.90 x + 1.30
- R-squared works out to 0.81, so the line explains 81% of the variation
The best-fit line is y = 0.90 x + 1.30 with an R-squared of 0.81. These are the calculator's default inputs, so the results above match the widget exactly.
Polynomial fit calculator: frequently asked questions
What is a least-squares fit?
A least-squares fit is the line, or curve, that minimizes the sum of the squared vertical distances between the data points and the fitted line. Squaring the gaps penalizes large misses and gives a single best line. It is the standard method for regression and trend fitting.
What do the slope and intercept tell me?
The slope is how much y changes for each one-unit increase in x, the steepness and direction of the trend. The intercept is the predicted value of y when x is zero, where the line crosses the vertical axis. Together they define the predictive rule y equals slope times x plus intercept.
What is R-squared?
R-squared, the coefficient of determination, is the fraction of the variation in y that the fitted line explains, from 0 to 1. A value of 0.81 means the line accounts for 81 percent of the variation, with the rest being scatter the straight line does not capture. Higher is a closer fit.
Why a degree-one polynomial?
A degree-one polynomial is a straight line, the simplest and most common fit, and it is robust against overfitting. Higher-degree polynomials can follow curved data but risk chasing noise. This calculator fits the straight line, which is the right starting point for most trend analysis.
How many points can I use?
This calculator fits five points. You need at least two distinct x values for a line to be defined, and more points give a more reliable trend. The normal equations handle any of the five points you enter, and the computation is deterministic, so the worked example reconciles exactly to the calculator.
Official sources
- Statistics and reference algorithm definitions: US National Institute of Standards and Technology (NIST). As at 25 June 2026.
Reviewed by the CalculatorHub team, edited by James Graham, 25 June 2026. See our methodology. This is general information, not financial, tax, legal or investment advice.