Member-only story

Polynomial Regression in R — when to use and how to use

Rabin Poudyal
2 min readDec 26, 2019

( Sometimes tweaking linear model by few parameters make your model more accurate)

Let’s say we want to perform regression analysis on the non-linear dataset. For example, we can take a look at the level of an employee vs. salary offered dataset available here. You are free to use your own dataset for the problem, the requirement is only that the data should be non-linear. If it is linear, simple linear regression will work just fine. If you are interested in linear regression as well check out my linear regression for busy data scientists tutorial here. The data looks like the following:

data for poly regression — salary given by level of employee

Let’s create a linear plot for our data using linear regression. The tutorial for performing simple linear regression is here.

linear regression plot of non-linear data

Now it is clear that regression is not doing good in our data, so we need some kind of non-linear model.

So now let’s create additional features for polynomial regression.

> data$Level1 = data$Level^2

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Rabin Poudyal
Rabin Poudyal

Written by Rabin Poudyal

Software Engineer, Data Science Practitioner. Say "Hi!" via email: rabinpoudyal1995@gmail.com or visit my website https://rabinpoudyal.com.np

No responses yet

Write a response