Polynomial Regression Calculator

Polynomial Regression Calculator

Fit a polynomial of degree 1 to 6 to your data and compare how well each degree fits, with the equation, R², adjusted R², a chart and predictions.

y = b₀ + b₁x + b₂x² + … + bₖxᵏ

Choose a degree and enter your X and Y values

What is Polynomial Regression?

Polynomial regression fits a curve made of powers of x (x, x², x³ and so on) to data that a straight line can't follow. The degree is the highest power used, and each extra degree lets the curve bend once more.

Degree 1 is an ordinary straight line, 2 a parabola and 3 an S-bend. Higher degrees can follow almost any wiggle, which is both their power and their danger: past a point they start fitting the noise instead of the pattern.

The practical skill is choosing the degree. Look for the lowest degree after which adjusted R² stops improving and the curve still looks sensible between the data points.

Polynomial Regression Formula

Least squares as in the NIST/SEMATECH e-Handbook, section 4.4.3, and Montgomery, Peck and Vining, chapter 7. See Sources.

1. The model

ŷ = b₀ + b₁x + b₂x² + … + bₖxᵏ

2. Least squares in matrix form

b = (XᵀX)⁻¹ Xᵀy, where X has columns 1, x, x², …, xᵏ

The calculator centres and scales x before solving, which keeps high powers numerically stable.

3. Judging the degree

Adjusted R² = 1 − (1 − R²)(n − 1) ÷ (n − k − 1)

Worked Example: A Year of Temperatures

Given:
Average daily highs (°C) for months 1–12 in a temperate city: 8, 9, 12, 15, 18, 21, 23, 23, 20, 16, 11, 9.
Step 1:
A straight line misses the summer peak:
degree 1: R² = 0.05
Step 2:
A parabola captures the hump:
y = −0.465x² + 6.388x − 0.932 · R² = 0.891
Step 3:
Higher degrees keep helping, then level off:
adjusted R²: degree 2 0.866 · degree 4 0.98 · degree 6 0.997
Result:
Degree 4 fits to within about 0.78 °C

The parabola peaks at 21 °C, short of the real 23 °C, because a year of temperatures is flatter at the ends than a parabola. Degree 4 fixes most of that; degrees 5 and 6 squeeze out a little more but start chasing month-to-month noise. For long-run data, a sine curve is the physically sensible model.

Choosing the Degree for the Temperature Data

R² always rises with the degree. Adjusted R² and the typical error show when the extra bends stop paying their way.

Fit statistics by polynomial degree
DegreeR²Adjusted R²RSE (°C)
10.05-0.0455.708
20.89080.86652.04
30.93870.91581.621
40.98750.98040.782
50.99810.99650.332
60.99880.99740.285

Common Polynomial Regression Mistakes

  • Overfitting. A degree-6 curve through 8 points wiggles wildly between them. Prefer the lowest degree that fits.
  • Picking the degree by R². R² never falls as the degree rises, so it always "prefers" the most complex model.
  • Extrapolating. High powers explode outside the data. A degree-4 fit to 12 months says nothing sensible about month 20.
  • Using raw large X values. Years such as 2024 raised to the 5th power lose precision in many tools. Centre X first (this calculator does it for you).

Polynomial Regression FAQs

How do I choose the degree?

Start low. Increase it while adjusted R² improves noticeably and the curve stays sensible. Stop when the gains become tiny.

How many points do I need for degree k?

At least k + 1, but realistically several times that so the fit can be judged.

Why is degree 1 included?

It’s the ordinary straight-line fit, the natural baseline to compare curves against.

Is polynomial regression linear regression?

Yes, in the sense that it’s linear in the coefficients. It uses the same least-squares machinery with x, x², x³ … as predictors.

What’s the difference from spline regression?

Splines join several low-degree polynomials smoothly, so they bend where needed without the wild swings of one high-degree polynomial.

How do I do this in Excel?

Add a polynomial trendline (up to order 6) to a scatter chart, or use =LINEST(y, x^{1,2,…,k}).

Why does adjusted R² go down sometimes?

Because the extra coefficient improved the fit by less than you’d expect from adding a random variable. It’s a sign to stop.

Can I see the separate quadratic and cubic tools?

Yes: the quadratic regression calculator finds the vertex, and the cubic one the turning and inflection points.

Sources

Related Tools