김태오

Polynomial Regression 본문

ML

Polynomial Regression

ystc1247 2023. 4. 23. 01:07

Polynomial:  a mathematical expression consisting of variables (usually represented by x), coefficients, and exponents (powers) that are combined using arithmetic operations such as addition, subtraction, multiplication, and division.

 

Polynomial Regression : a type of regression analysis in which the relationship between the independent variable (x) and the dependent variable (y) is modeled as an nth degree polynomial. In other words, it is a curve fitting technique that allows us to model non-linear relationships between the input and output variables.

Polynomial Regression -> Linear Regression

[the reasons for the transformation]

Simplification: Linear regression is a simpler and more computationally efficient method than polynomial regression, especially when dealing with large datasets. By transforming a polynomial regression problem into a linear regression problem, we can simplify the problem and reduce the computational complexity.

Interpretation: Linear regression is a more interpretable method than polynomial regression, as the coefficients of the linear model have a clear and direct relationship with the input features. In contrast, the coefficients of a polynomial regression model can be more difficult to interpret, as they depend on the degree of the polynomial and the interaction between the input features.

Regularization: Linear regression can be more easily regularized than polynomial regression. Regularization methods, such as Ridge regression and Lasso regression, can help prevent overfitting by adding a penalty term to the objective function that penalizes large coefficients. These methods are more effective in linear regression than in polynomial regression, as they can reduce the number of features and prevent the model from fitting noise in the data.

Flexibility: By transforming a polynomial regression problem into a linear regression problem, we can use a wider range of linear regression techniques, such as logistic regression, Poisson regression, and linear mixed-effects models, that are not directly applicable to polynomial regression.

Conversion process

To convert a polynomial regression problem into a linear regression problem, we can use a technique called "polynomial expansion." The basic idea is to transform the input data by creating new features that are powers of the original input features, and then use linear regression to fit a linear function to the transformed data.

Here are the general steps to perform polynomial expansion:

1. Collect the input data (x) and output data (y).
2. Create new features by taking the powers of the original input features up to the desired degree. For example, if we want to create quadratic features, we can add a new feature x^2 for each original feature x.
3, Construct a matrix X that contains the new features as columns and a vector y that contains the output values.
4. Fit a linear regression model to the transformed data by solving the normal equations or using gradient descent.
5. Use the fitted model to make predictions on new input data.

 

Here's an example of how to perform polynomial expansion for a quadratic regression problem with one input feature:

Suppose we have the following input data:

x = [1, 2, 3, 4, 5]
y = [4, 7, 12, 19, 28]

To perform quadratic regression, we need to create new features x^2 and xy (where y is the output variable):

x^2 = [1, 4, 9, 16, 25]
xy = [4, 14, 36, 76, 140]

We can then construct the matrix X and vector y as follows:

X = [1 1 4; 1 2 14; 1 3 36; 1 4 76; 1 5 140]
y = [4; 7; 12; 19; 28]

Notice that X now has three columns: one for the intercept term (always set to 1), one for the original input feature x, and one for the new feature x^2.

We can then use linear regression to fit a linear function to the transformed data by solving the normal equations or using gradient descent. Once we have the fitted model, we can use it to make predictions on new input data by applying the same polynomial expansion transformation to the input data and using the fitted model to predict the output values.

 

When converting polynomial regressions to linear regressions, it is important to understand Feature Scaling , which I will write in the next post.

 

'ML' 카테고리의 다른 글

Learning Rate  (0) 2023.04.23
Feature Scaling  (0) 2023.04.23
Gradient Descent vs. Normal Equation  (0) 2023.04.23
Learning Modes in ML  (0) 2023.04.22
Linear Regression  (0) 2023.04.22