Polynomial Regression › Formula
Machine Learning from ScratchAll chapters Polynomial Regression › FormulaOne section · Sections in this chapter2 / 8 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
The polynomial regression model extends linear regression by including polynomial terms of the independent variable. For a single variable , the polynomial regression model of degree is:
where:
- is the dependent variable (response variable we want to predict)
- is the independent variable (predictor or feature)
- is the intercept (the value of when )
- are the regression coefficients for the polynomial terms
- is the error term (random noise, assumed to be normally distributed with mean 0 and constant variance )
- is the degree of the polynomial (the highest power of in the model)
Matrix Notation
The polynomial regression model can be written in matrix form as:
where:
-
is the vector of response values (observed outcomes)
-
is the design matrix containing polynomial features up to degree
-
is the vector of coefficients to be estimated
-
is the vector of error terms (assumed to be i.i.d. with mean 0 and constant variance )
Multiple Variables
When you have more than one independent variable (feature), polynomial regression expands to include powers of each variable along with all possible products (interactions) between variables up to the chosen degree. This allows the model to capture much more complex relationships between your predictors and the response.
Suppose you have independent variables: . The general form of a polynomial regression model of degree is:
where:
- is the response variable
- is the number of predictor variables
- is the -th predictor variable
- is the intercept term
- are coefficients for linear terms
- are coefficients for quadratic terms and two-way interactions
- are coefficients for cubic terms and three-way interactions
- is the error term
Let's break down what this means:
- Linear terms: Each variable appears by itself, just like in standard linear regression. For example, , , ..., .
- Quadratic terms: These include both squared terms (like , ) and products of two different variables (like ). The coefficients for these are for squares and for interactions where .
- Cubic and higher-order terms: These are all possible products of three or more variables, such as , , etc., up to the chosen degree .
- Interaction terms: Any term that involves the product of two or more different variables (e.g., ) is called an interaction term. These allow the effect of one variable to depend on the value of another.
Example: Two Variables, Degree 2
If you have two variables ( and ) and use a quadratic (degree 2) polynomial, your model will look like:
where:
- is the intercept
- and are coefficients for the linear terms and
- and are coefficients for the squared terms and
- is the coefficient for the interaction term
- is the error term
Here, you have a total of 6 terms (including the intercept):
- Two linear terms: ,
- Two quadratic (squared) terms: ,
- One interaction term:
General Structure
In general, for variables and degree , the number of terms in the model (including the intercept) is given by the binomial coefficient:
where:
- is the number of predictor variables
- is the polynomial degree
- is the binomial coefficient (also written as "p+d choose d")
- The formula counts all possible combinations of variables multiplied together up to degree , including the intercept
For example, with variables and degree: terms (which matches our example above: intercept, , , , , ).
This rapid combinatorial growth is why polynomial regression with multiple variables can quickly become computationally expensive and prone to overfitting.

Summary Table of Terms
| Degree | Example Terms (for , ) | Description |
|---|---|---|
| 1 | , | Linear |
| 2 | , , | Quadratic & Interactions |
| 3 | , , , | Cubic & Higher Interactions |
In Summary, with multiple variables, polynomial regression models include all combinations of variables multiplied together up to the specified degree. This flexibility allows you to model complex, non-linear relationships, but it also means the number of terms can grow very quickly as you add more variables or increase the degree.

Mathematical Properties
The polynomial regression model maintains several important mathematical properties from linear regression. You can estimate the coefficients using the least squares method, which minimizes the sum of squared residuals:
where:
- is the residual sum of squares (the objective function to minimize)
- is the observed response value for observation
- is the predicted response value for observation
- is the number of observations
- is the polynomial degree
- is the coefficient for the -th power term
- is the predictor value for observation
The solution to this minimization problem is given by the normal equation:
where:
- is the vector of estimated coefficients
- is the transpose of the design matrix
- is the inverse of the Gram matrix
- is the vector of observed response values
The model maintains the Gauss-Markov theorem properties when the error terms satisfy the standard assumptions (zero mean, constant variance, and uncorrelated errors), making the least squares estimator the best linear unbiased estimator (BLUE).
The matrix calculations shown in the example above are simplified for educational purposes. In practice, with larger datasets or higher polynomial degrees, the matrix inversion can become numerically unstable. Modern implementations use more stable numerical methods like QR decomposition or singular value decomposition (SVD) to solve the least squares problem.