03 A Polynomial Linear Regression
03 A Polynomial Linear Regression
- if the dataset look like this type then we are doesnot use Linear Regression
In this case we are use Polynomial regresion or other Type of regression techinque like (Decision
tree,naive Bayes etc)
In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
In [2]:
dataset = pd.read_csv('data/Position_Salaries.csv')
In [3]:
dataset.head(10)
Out[3]:
3 Manager 4 80000
6 Partner 7 200000
8 C-level 9 500000
9 CEO 10 1000000
In [4]:
dataset = dataset.drop(['Position'],axis=True)
In [5]:
dataset.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 10 entries, 0 to 9
Data columns (total 2 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Level 10 non-null int64
1 Salary 10 non-null int64
dtypes: int64(2)
memory usage: 288.0 bytes
In [6]:
sns.pairplot(dataset)
Out[6]:
<seaborn.axisgrid.PairGrid at 0x2870ff66c08>
In [7]:
X = dataset.drop(['Salary'],axis=True)
y = dataset['Salary']
In [8]:
In [9]:
X_train.shape,X_test.shape,y_train.shape,y_test.shape
Out[9]:
Out[10]:
LinearRegression()
In [11]:
See in above that when i apply only Linear Regression On this data accuracy is not good, but When i apply
polynomial regression then the accuracy is very high.
- So i hope Now you understood when we apply Linear Regression and when
we apply Polynomial Regression
In [14]: