The difference between linear regression and polynomial regression, and how to determine their usage scenarios

Regression is a method of supervised learning, in which a model is obtained from continuous data and then the model is used for prediction or classification.

Linear regression model

If the data is drawn like this, then it is suitable for linear regression.

This group of data does not belong to the normal distribution, but with linear regression, it can be a good fit, if you use polynomial regression, then the fit will be very poor.

Draw a fitted curve and observe, it is still a good fit. After linear regression, the first one is unprocessed, and the second one is processed. Observe what has changed.

Polynomial regression model

The decision is based on the trend of the data, and when it is too complex, then polynomial regression is not suitable for the data set.

Polynomial regression models generally deal with normally distributed data, and the code for polynomial regression has one more line than that for linear regression.

polynomial = PolynomialFeatures(degree=2) 
# 构建多项式回归器对象 
# degree是多项式的次数,此处初步的设置为2

If he is this kind of data, then polynomial regression is suitable for this data set.

Draw a fit curve to see how well he fits the data set. It is obvious that the fit is very good. You can observe these two pictures, after polynomial regression, the first one is untreated. The second one is after the treatment and observe what has changed.

Leave a Reply