Polynomial Regression Calculator

Fit a least-squares polynomial to your (x, y) data and get the equation, its coefficients, and the R² goodness of fit.

Quick Facts

Method
Ordinary least squares via the normal equations
Minimizes the sum of squared vertical residuals; needs at least degree + 1 distinct x-values.

Your Results

Calculated
Fitted equation
-
y as a function of x
R² (goodness of fit)
-
Fraction of variance explained
Coefficients
-
a0, a1, a2, …
Predicted y
-
Value at your chosen x

Ready

Enter your x and y values, pick a degree, and calculate.

What polynomial regression does

Polynomial regression fits a curve of the form y = a₀ + a₁x + a₂x² + … + aₙxⁿ to a set of observed (x, y) points. It is an extension of simple linear regression: instead of forcing a straight line through the data, it allows the relationship to bend. A degree-1 polynomial is an ordinary straight line, degree 2 is a parabola, degree 3 (cubic) can have one inflection, and higher degrees can follow more wiggles. The calculator above finds the coefficients that best fit your data and reports the R² goodness of fit.

How the coefficients are found

The fit uses ordinary least squares: it chooses the coefficients that minimize the sum of squared vertical residuals, Σ(yᵢ − ŷᵢ)². Although the curve is nonlinear in x, it is linear in the coefficients, so the solution comes from a system of linear equations called the normal equations. For a degree-n fit you build an (n+1)×(n+1) matrix from the sums Σxᵏ (for k up to 2n) and a right-hand side from the sums Σyxᵏ, then solve for the coefficient vector. This calculator solves that system by Gaussian elimination with partial pivoting, the same result you would get from a spreadsheet's LINEST or NumPy's polyfit.

Reading R²

R² = 1 − SSres/SStot, where SSres = Σ(yᵢ − ŷᵢ)² is the leftover error and SStot = Σ(yᵢ − ȳ)² is the total variance around the mean. R² of 1 means the curve passes through every point; 0 means it does no better than a flat line at the average. A key caveat: adding degree can only raise R², never lower it, so a high R² from a degree-5 fit on six points is meaningless — it is interpolating, not modeling.

When to use it

Polynomial regression is useful when a scatter plot shows clear curvature: an object's height under gravity (quadratic in time), a dose–response curve that levels off, a cost curve with diminishing returns, or a calibration curve for an instrument. It is a poor choice for extrapolation — polynomials shoot off to ±∞ outside the data range — and for data that is genuinely linear or better described by an exponential, logarithmic, or logistic model.

Frequently Asked Questions

What degree should I choose?
Start with the lowest degree that captures the shape you see in a scatter plot. If the points bend once, try degree 2; if they have an S-shape, try degree 3. Increasing the degree always improves the in-sample R², but each extra degree adds a coefficient that can chase noise instead of signal. A good rule: prefer the simplest curve whose residuals look randomly scattered around zero, and be suspicious of any fit where the number of coefficients approaches the number of data points.
Why is my R² exactly 1?
If the number of coefficients (degree + 1) equals the number of distinct data points, the polynomial can pass exactly through every point, forcing R² = 1 regardless of whether there is any real relationship. That is interpolation, not regression. To get a meaningful fit you need more data points than coefficients — ideally several times as many.
Does polynomial regression prove causation?
No. Like any regression, it only describes the association between x and y in your sample. A well-fitting curve does not establish that x causes y, and it should not be used to predict outside the range of your x-values, because polynomials diverge rapidly beyond the observed data.