Polynomial Regression (Curve Fitting)

Fit relationships that a straight line cannot describe - for example strength that drops when the temperature is either too low or too high. The points where the derivative of the equation is 0 are calculated to show the optimal condition right away.

1Data Table

Paste a table copied from Excel into a cell (Ctrl+V). Click a column header (A, B…) before pasting to use the first line as column names. Double-click a header to rename it, right-click to insert/delete rows and columns, and formulas such as =A1*2 work too.

2Polynomial Regression Options

How to run a polynomial regression

  1. Copy the predictor X column and the response Y column with their headers.
  2. Choose Y and X and set the polynomial degree (2-6). If the higher-order terms are strongly correlated, turn on Center X.
  3. Click Analyze and check the critical points, the curve and the residuals.

Worked example with sample data

The example data are 17 bond strength (N) measurements taken while changing the curing temperature from 110 °C to 190 °C in 5 °C steps. Curing temperature is X, bond strength is Y, and the default degree 2 is fitted.

Quadratic regression curve of curing temperature and bond strength - with the 95% confidence and prediction bands; the peak is the optimal temperature
Quadratic regression curve of curing temperature and bond strength - with the 95% confidence and prediction bands; the peak is the optimal temperature

The quadratic equation is Bond strength = -0.01255·temp² + 3.974·temp - 256.6. The negative X² coefficient means the curve opens downward, and R²=0.9768 and RMSE=1.302 show a good fit.

According to the critical points table, the bond strength reaches its maximum of 58.07 N at a curing temperature of 158.4 °C. The strength drops at lower or higher temperatures.

The residuals are slightly skewed to the right (skewness 1.20), and the normality test p=0.01252 weakly rejects normality. Raising the degree to 3 barely increases R² (0.9788) and the cubic term is not significant (p=0.281), so degree 2 is enough.

How it is calculated

Y = b₀ + b₁X + b₂X² + … + b_dX^d is fitted with statsmodels OLS. RMSE = √(mean of squared residuals).

Critical points are the real roots (numpy roots) of the derivative of the equation, shown with the predicted value at that X. With Center X on, the model is fitted on X_c = X - mean and the critical points are converted back to the original X.

What the results show

Coefficients, the model summary (R², adjusted R², RMSE, F test), critical points, a scatter plot with the polynomial curve and confidence/prediction bands (equation in the side panel), residuals vs fitted and a residual QQ plot.

Interpreting the polynomial regression

  • In a quadratic, a negative X² coefficient means the curve opens downward (a maximum) and a positive one means it opens upward (a minimum); the critical point is the optimal condition.
  • Raising the degree increases R² but also the risk of overfitting. Compare adjusted R² and the residuals and choose the simplest adequate degree.
  • A critical point outside the data range is an extrapolation and should not be trusted as is.

Frequently asked questions

What degree should I use?

Degree 2 or 3 is usually enough. High degrees make the curve swing strongly near the ends of the data, so predictions become unstable.

What does centering X do?

It subtracts the mean from X before fitting to reduce the correlation between X and its higher powers. Predictions and R² stay the same; only the coefficients change.

The critical point says 'None'.

If the derivative has no real root, the curve only increases or only decreases over the whole range.

Other chart tools