-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolynomial.py
More file actions
42 lines (29 loc) · 863 Bytes
/
Polynomial.py
File metadata and controls
42 lines (29 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# -*- coding: utf-8 -*-
"""
Created on Mon May 20 22:44:20 2019
@author: suraj
"""
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
dataset=pd.read_csv('Position_Salaries.csv')
X=dataset.iloc[:,1:2].values
Y=dataset.iloc[:,2].values
from sklearn.linear_model import LinearRegression
linrreg=LinearRegression()
linrreg.fit(X,Y)
from sklearn.preprocessing import PolynomialFeatures
ployreg=PolynomialFeatures(degree=3)
x_poly=ployreg.fit_transform(X)
linreg2=LinearRegression()
linreg2.fit(x_poly,Y)
x_grid=np.arange(min(X),max(X),0.1)
x_grid=x_grid.reshape((len(x_grid),1))
plt.scatter(X,Y,color='red')
plt.plot(x_grid,linreg2.predict(ployreg.fit_transform(x_grid)),color='black')
plt.title('Salary vs Level')
plt.xlabel('Level')
plt.ylabel('Salary')
plt.show()
linrreg.predict(6.5)
linreg2.predict(ployreg.fit_transform(6.5))