Polynomial regression is a machine learning algorithm that is used to train a linear model on non-linear data. Sometimes your data is much more complex than a straight line, in such cases, it is not a good option to train a linear model like a linear regression algorithm, but surprisingly, we can use the polynomial regression algorithm to add the powers of each feature as the new features and then train a linear model on the extended set of features. This is how this algorithm works. To make you better understand, in this article, I will introduce you to the polynomial regression in machine learning and its implementation using Python.

## Polynomial Regression in Machine Learning

In machine learning, the polynomial regression algorithm allows you to use a linear model even when the data has very strong nonlinearities. It works by adding additional features to the data by understanding existing features.

To implement this algorithm, you have to first train a linear model on a non-linear dataset, letâ€™s say we want to train a ** linear regression algorithm** on non-linear data which will be giving us bad results. So in such cases, we need to add some new features by understanding the existing features to make our dataset linear. For this task, we need to use the polynomial regression algorithm which transforms the data into an expanded one and then if we will use the linear regression algorithm again on the newly transformed data it will give us the perfect results.

## Polynomial Regression using Python

To implement this algorithm using Python, I will start by importing all the necessary Python libraries and the dataset that we need for this task:

Now letâ€™s split the data and train a linear regression algorithm to see what score we get before adding the new features to this non-linear dataset:

0.7748474495826966

As the dataset that we are using is non-linear data, so we are getting a score of 0.77 which is quite low, now letâ€™s see what score we get after training a linear regression algorithm on a newly transformed dataset using polynomial regression:

0.9176770693517695

So after training the same model on the extended features we are getting a score of 0.91 which is not bad.

### Summary

So this is how adding new polynomial features helps in transforming the existing non-linear data into a linear one. I hope you liked this article on an introduction to the Polynomial regression algorithm in machine learning and its implementation using Python. Feel free to ask your valuable questions in the comments section below.