In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
In [2]:
dataset = pd.read_csv('Position_Salaries.csv')
dataset.head(2)
Out[2]:
In [3]:
x = dataset.iloc[:,1:2].values
y = dataset.iloc[:,2].values
type(x)
Out[3]:
In [4]:
#before feature scaling of x and y
from sklearn.svm import SVR
reg = SVR(kernel = "rbf")
reg.fit(x,y)
y_pred = reg.predict(6.5)
print(y_pred)
plt.scatter(x,y)
plt.plot(x,reg.predict(x))
Out[4]:
In [5]:
#feature scaling
from sklearn.preprocessing import StandardScaler
sc_x = StandardScaler()
sc_y = StandardScaler()
x = sc_x.fit_transform(x)
y = sc_y.fit_transform(y)
from sklearn.svm import SVR
reg = SVR(kernel = "rbf")
reg.fit(x,y)
y_pred = sc_y.inverse_transform(reg.predict(sc_x.transform(np.array([[6.5]]))))
print(y_pred)
plt.scatter(x,y,color = 'r')
plt.plot(x,reg.predict(x))
Out[5]:
In [ ]:
In [ ]:
Comments
Post a Comment