ThisCalculator

Everyday

Online Polynomial Regression Calculator

Updated · Standard formula, shown below

The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.

An online polynomial regression calculator fits a polynomial curve (linear, quadratic, cubic, etc.) to a set of (x, y) data points you provide, returning the equation coefficients and goodness-of-fit statistics like R². You enter paired x and y values, choose the polynomial degree, and the calculator outputs the fitted equation, predicted values, and often a graph.

Formula

The calculator uses the method of least squares to find coefficients \(a_0, a_1, \dots, a_d\) that minimize the sum of squared residuals:

\(\text{minimize } \sum_{i=1}^{n} \left( y_i – (a_0 + a_1 x_i + a_2 x_i^2 + \dots + a_d x_i^d) \right)^2\)

Where:

  • \(x_i, y_i\) – your data points (i = 1 to n)
  • \(d\) – degree of the polynomial (1 = linear, 2 = quadratic, 3 = cubic, etc.)
  • \(a_0, a_1, \dots, a_d\) – coefficients to be determined

The coefficients are found by solving a system of linear equations (the normal equations) using matrix algebra. The calculator also computes R², the coefficient of determination, which tells you how well the polynomial fits the data (1.0 = perfect fit).

Worked Example

Using the default inputs: x = 1, 2, 3, 4, 5 and y = 2.1, 3.9, 9.2, 16.8, 26.1, degree = 2.

We want a quadratic fit: \(y = a_0 + a_1 x + a_2 x^2\). The least-squares solution gives:

  • \(a_2 = 1.9\)
  • \(a_1 = -1.1\)
  • \(a_0 = 1.3\)

So the equation is: \(y = 1.3 – 1.1x + 1.9x^2\).

R² = 0.9999, indicating an almost perfect fit.

Predicted y at x=6: \(1.3 – 1.1(6) + 1.9(36) = 1.3 – 6.6 + 68.4 = 63.1\).

This matches the calculator output.

When to Use Polynomial Regression

Polynomial regression is useful when your data shows a curved relationship that a straight line cannot capture. Common applications include:

  • Modeling growth rates (e.g., population, revenue) that accelerate or decelerate
  • Physics experiments with quadratic motion (e.g., free fall)
  • Economics where marginal effects change (e.g., diminishing returns)
  • Biology for dose-response curves

It is a special case of multiple linear regression where the predictors are powers of x. You should use it when you have a reason to believe the relationship is polynomial, not just because you want a higher R².

How to Choose the Degree

The degree is the highest power of x in the equation. Choosing it involves a trade-off:

  • Degree 1 (linear) – best for straight-line trends.
  • Degree 2 (quadratic) – one curve (U or inverted U).
  • Degree 3 (cubic) – can have an S-shape or two bends.
  • Higher degrees – more flexible, but risk overfitting.

A good rule: start with degree 2, then increase only if the fit improves significantly and the pattern makes sense. If you use a degree equal to n-1 (where n is the number of points), the polynomial will pass through every point exactly – but that is usually overfitting.

Common Mistakes and Limitations

  • Overfitting: A high-degree polynomial may fit the training data perfectly but fail to predict new data. Always check R² on a holdout set or use adjusted R².
  • Extrapolation: Polynomials can behave wildly outside the range of your data. Never predict far beyond the observed x values.
  • Unit consistency: Ensure x and y are in consistent units. If x is in meters and y in seconds, the coefficients will have odd units.
  • Data entry errors: A single typo in a y value can drastically change the curve. Always plot the data first.
  • Ill-conditioning: For large x values or high degrees, numerical errors can occur. Centering x (subtracting the mean) helps.

The formula assumes the relationship is exactly polynomial, which is rarely true in practice. It also assumes the variance of errors is constant (homoscedasticity).

Comparing to Other Regression Types

Polynomial regression is not the only option for curved data:

  • Linear regression: Only for straight lines; simplest.
  • Logarithmic regression: \(y = a + b \ln(x)\) – good for data that increases quickly then levels off.
  • Exponential regression: \(y = a e^{bx}\) – for constant percentage growth.
  • Power regression: \(y = a x^b\) – for data that follows a power law.
  • Loess / spline: Non-parametric, more flexible, but no simple equation.

Polynomial regression is a good middle ground: it gives an equation you can use for prediction and interpretation, while still capturing curvature.

Frequently Asked Questions

What is the difference between polynomial regression and multiple linear regression?

Multiple linear regression uses several independent variables (x1, x2, …). Polynomial regression uses powers of a single variable (x, x², x³, …). Mathematically, polynomial regression is a special case of multiple linear regression where the predictors are x, x², x³, etc. The fitting method is identical.

How do I know if my polynomial fit is good?

Look at R² (close to 1 is better) and also plot the residuals (differences between actual and predicted y). If residuals show a pattern, the model is missing something. Also compare adjusted R², which penalizes extra terms, to avoid overfitting.

Can I use polynomial regression for time series data?

Yes, you can use time as the x variable, but be careful: time series often have autocorrelation, which violates the independence assumption. For forecasting, consider ARIMA or other time series methods. Polynomial regression can still be used for trend analysis.

What does the coefficient of determination (R²) actually mean?

R² is the proportion of variance in y that is explained by the polynomial model. An R² of 0.95 means 95% of the variation in y is captured by the model. However, it does not tell you if the model is appropriate – a high R² can also occur with overfitting.

Why does my high-degree polynomial give crazy predictions outside the data range?

Because high-degree polynomials have large derivatives; they can swing wildly between points and especially beyond the edges. This is why extrapolation with polynomials is risky. Stick to low degrees and avoid predicting far outside your data.

Can I fit a polynomial if I have only a few points?

Yes, but the fit will be less reliable. With n points, you can fit a polynomial of degree up to n-1, but that will pass through every point exactly – likely overfitting. With only 3 points, a quadratic is the highest degree you can fit, and you have no degrees of freedom left to estimate error.

Related

Formula used
in x | x values | - | 1, 2, 3, 4, 5 | 0
in y | y values | - | 2.1, 3.9, 9.2, 16.8, 26.1 | 0
in d | Degree | - | 2 | 1
out eq | Polynomial equation | - | polyfit(x, y, d) | 4
out r2 | R-squared | - | rsq(x, y, d) | 4
out pred | Predicted y at x=6 | - | polyval(x, y, d, 6) | 4

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.