Polynomial Regression Calculator

JJ Ben-Joseph headshot JJ Ben-Joseph

Introduction: Fitting a polynomial regression curve to your data

Polynomial regression is useful when a straight line misses the bend in your data. This calculator takes paired x and y values, fits a polynomial of the degree you choose by least squares, and then shows the coefficients, fitted values, and residuals so you can see how closely the curve follows the observations.

It is a practical way to test whether a gentle curve, a sharper bend, or a slightly higher-order polynomial explains the pattern in your measurements better than a linear trend alone.

How to enter data for a polynomial regression fit

After you compute the fit, the calculator solves the least squares problem for the selected degree and reports the polynomial alongside a residual for every data pair.

Polynomial regression in a nutshell

Polynomial regression extends ordinary linear regression by letting the model use powers of x instead of stopping at a single slope term. That extra flexibility is what lets the fitted curve bend when the data call for it.

Instead of limiting the relationship to

y ≈ b₀ + b₁ x

we allow higher powers of x up to some degree d:

y ≈ a₀ + a₁ x + a₂ x² + ⋯ + a_d x^d.

In compact mathematical notation, the fitted polynomial is

P(x) = Σ (from j = 0 to d) a_j x^j,

where the coefficients a₀, a₁, …, a_d are chosen so the curve follows the overall shape of your data as closely as possible without forcing it through every point.

Least squares objective for a polynomial fit

For polynomial regression, the residual at each observation is the observed value minus the fitted value at the same x. Least squares chooses the coefficients that make those residuals collectively as small as possible.

Suppose you have n observations (x₁, y₁), …, (xₙ, yₙ). For a given set of coefficients, the prediction at xᵢ is P(xᵢ) and the residual is

rᵢ = yᵢ − P(xᵢ).

Least squares regression chooses the coefficients that minimize the sum of squared residuals:

S(a₀, …, a_d) = Σ (from i = 1 to n) (yᵢ − P(xᵢ))².

Squaring the residuals puts more weight on larger misses and turns the coefficient search into a smooth optimization problem that linear algebra can solve efficiently.

Vandermonde design matrix for polynomial regression

To build the fit, the calculator turns your x values into a matrix whose columns contain 1, x, , and so on up to the chosen degree. That matrix is what lets the polynomial coefficients be solved with linear algebra rather than by trial and error.

[ 1   x₁   x₁²   …   x₁^d ]
[ 1   x₂   x₂²   …   x₂^d ]
[ ⋮    ⋮    ⋮         ⋮   ]
[ 1   xₙ   xₙ²   …   xₙ^d ]
  

If we denote this matrix by X, the coefficient vector by a, and the vector of observed y-values by y, we can write the model compactly as

y ≈ X a.

Normal equations for the fitted coefficients

Once the design matrix is built, the calculator forms the normal equations and solves them for the coefficient vector. This is the step that turns your raw data into the polynomial reported in the results panel.

The least squares solution is found by solving the normal equations

(Xᵀ X) a = Xᵀ y.

Here Xᵀ is the transpose of X. The calculator forms these matrices and solves the resulting linear system to obtain the coefficients.

Formula: Polynomial regression normal equations in MathML

The same relationship can be expressed using MathML as

( X T X ) a = X T y

Solving this equation gives the coefficient vector a, which defines the fitted polynomial.

Interpreting the output from a polynomial regression fit

After the calculation finishes, the results tell you more than just the polynomial itself. The coefficient list shows the shape of the curve, the predicted values show how the model lands at each input, and the residuals show where the fit misses or stays close.

You can use these outputs to judge how well the polynomial captures the trend in the data. Residuals that are small in magnitude and do not show a repeating pattern when you compare them across x usually point to a reasonable model for the degree you chose. If the residuals stay lopsided or swing in a regular pattern, the degree may be too low or the relationship may not be well described by a polynomial at all.

Worked example: fitting a quadratic curve to a curved dataset

Imagine a small data set where the response rises faster as x gets larger. A quadratic fit is a natural first test because the squared term can capture that bend without forcing the curve to wiggle unnecessarily.

The calculator builds a matrix that includes 1, x, and for each point, then solves for the intercept, slope, and curvature term that best match the data.

X =
[ 1   x₁   x₁² ]
[ 1   x₂   x₂² ]
[ 1   x₃   x₃² ]
[ 1   x₄   x₄² ]
  

When the fit is finished, the residuals help you see where the curve hugs the data and where it misses. Endpoints often show the largest mismatch when the degree is too simple, while a better-matched quadratic usually leaves the middle points close to the curve.

A qualitative summary of the output might look like this:

Part of the fit What the calculator is checking What you look for
Coefficient list How much intercept, slope, and squared curvature the data support A curved series usually needs a meaningful higher-order term
Predicted values Where the fitted polynomial lands at each input x The predictions should track the broad trend without drifting far away
Residuals The gap between each observed point and the fitted curve Small, unsystematic gaps are better than a repeating pattern

This kind of example is less about memorizing one "correct" answer and more about learning what a polynomial regression result is trying to tell you: whether the added curvature is genuinely useful or just making the curve chase the noise.

Choosing the polynomial degree for polynomial regression

The degree you choose controls how much curvature the regression is allowed to use. In polynomial regression, a low degree is easier to interpret, while a higher degree can follow a bend more closely but may also start fitting small fluctuations that do not matter.

Degree Model form Flexibility Typical use
1 a₀ + a₁ x Low Approximately linear trends
2 a₀ + a₁ x + a₂ x² Moderate Single bend (U-shaped or inverted U curves)
3 a₀ + a₁ x + a₂ x² + a₃ x³ Higher More complex curvature with up to two bends
4–5 Includes terms up to x⁴ or x⁵ High Exploratory fitting on small to medium datasets; can capture wiggly patterns but more prone to overfitting

A good starting strategy is to begin with degree 1 or 2, then move up only if the residuals still show a pattern that the simpler fit cannot absorb.

Assumptions and limitations for polynomial regression fits

Polynomial regression is flexible, but it still works best when the data support the shape you are asking it to fit. Keep the following limits in mind when you read the results.

Within those limits, polynomial regression is best treated as an exploratory curve-fitting tool. Use the residuals, the degree choice, and your domain knowledge together before treating the fit as a real model.

How to use this polynomial regression calculator

  1. Enter x values (comma-separated) exactly as they appear in your measurement or time series.
  2. Enter y values (comma-separated) on the same scale and in the same order.
  3. Choose degree to control how much curvature the polynomial regression is allowed to use.
  4. Run the fit and review the coefficients, predictions, and residuals to make sure the curve is describing the data rather than merely chasing noise.
Enter matching x and y values, then choose a polynomial degree.

Arcade Mini-Game: Polynomial Regression Curve Check

This quick arcade run keeps the focus on curve-fitting judgment: catch the details that belong in a polynomial regression and avoid the ones that would skew the fit.

Score: 0 Timer: 30s Best: 0

Start the game, then use your pointer or arrow keys to catch useful regression inputs and avoid distracting assumptions.