Polynomial Regression

The following two tabs change content below.
Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

Latest posts by Prasad Kharkar (see all)

We learned about multiple linear regression and backward elimination in previous articles. Now we will learn about another form of regression, i.e. polynomial regression. we will take a look at it to solve an interesting problem.

Polynomial Regression:

Before we go into details of polynomial regression, let us consider our case study first.

Problem Statement:

Consider our company wants to recruit certain people for certain positions. They have found a potential employee who is currently working as a vice president for last 2 years. He is expecting a salary of 190000 for his 2 years experience as vice president.

Now the question is, does his demand fit into our company’s salary structure? If his demand fits, how much can we really offer him?

Our company’s salary and position data:

The company has approximate salaries according to positions as below.

Position Level Salary
Software Engineer 1 22000
Sr. Software Engineer 2 24000
Technology Lead 3 30000
Team Leader 4 38000
Manager 5 50000
Senior Manager 6 75000
Associate Vice President 7 110000
Vice President 8 170000
President 9 260000
CEO 10 480000

Usually in our company, an employee can rise from Vice President to President level in 6 years, so we will predict salary for 8.3 level, because the employee has worked one third of tenure to become President.

Why to use Polynomial Regression?

Let us understand why we are using polynomial regression instead of linear regression. Looking at the dataset, it does not seem linear. As higher positions are concerned, salaries are changing non linearly. Let us first check whether linear regression is providing any good predictions.

Note the graph plotted:

linear regression results
linear regression results

Note that red dots are actual salaries plotted against position levels. for position 8.3, our model has predicted a salary of approximately 239851, which is way more than potential employee wanted.

Blue line is regression line and its predictions are far from the reality in most of the cases. We can have a different model to consider and hence we can look into polynomial regression.

Polynomial Regression Model:

Equation of polynomial regression model is

y = b0 + b1x1 + b2x12 + b3x13 + … + bnx1n

We will give polynomial powers to existing positions dataset.

  • import PolynomialFeatures class from sklearn.preprocessing.
  • create poly_reg object with 4th degree Polynomial features. i.e. for our case, equation will become y = b0 + b1x1 + b2x12 + b3x13 + b4x14
  • X_poly = poly_reg.fit_transform(X), will expand x matrix into X_poly where each column will contain values of powers of x.
    X_Poly matrix
    X_Poly matrix


  • lin_reg_2.fit(X_poly, y) fits transformed X_poly matrix and salary data. Note that each column is power of x in increasing order

Now, note the graph plotted by polynomial regression

polynomial regression results
polynomial regression results

Salary predicted by polynomial regression is approximately 189117 which is quite close to what he was asking for and it fits our company salary model.

Our company can hire the new vice president and he will happily come to us :



Share Button

Prasad Kharkar

Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

One thought on “Polynomial Regression

Leave a Reply

Your email address will not be published. Required fields are marked *