SVR Technique
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 30 13:27:39 2023
@author: Syed Kamran Bukhari
"""
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
#Import CSV File
dataset = pd.read_csv('Position_Salaries.csv')
X= dataset.iloc[:,1:2].values
Y=dataset.iloc[:, -1].values
from sklearn.preprocessing import StandardScaler
sc_x = StandardScaler()
X= sc_x.fit_transform(X)
sc_y = StandardScaler()
Y=Y.reshape(len(Y),1)
Y= sc_y.fit_transform(Y)
from sklearn.svm import SVR
regressor= SVR(kernel='rbf')
Y=Y.reshape(len(Y),)
regressor.fit(X,Y)
Y_pred=regressor.predict(sc_x.transform([[6.5]]))
print('The Predicted value of Y is = ',Y_pred)
Y_pred=Y_pred.reshape(len(Y_pred), 1)
Y_pred= sc_y.inverse_transform(Y_pred)
print('The New Predicted value of Y is = ',Y_pred)
Y=Y.reshape(len(Y),1)
ya = regressor.predict(X)
ya = ya.reshape(len(ya),1)
plt.scatter(sc_x.inverse_transform(X), sc_y.inverse_transform(Y), color='red')
plt.plot(sc_x.inverse_transform(X), sc_y.inverse_transform(ya), color='blue')
plt.title('Position vs Salary')
plt.xlabel('Position')
plt.ylabel('Salary')
plt.show()
X_grid = np.arange(min(X),max(X), 0.1)
X_grid= X_grid.reshape(len(X_grid),1)
yaa = regressor.predict(X_grid)
yaa=yaa.reshape(len(yaa),1)
plt.scatter(sc_x.inverse_transform(X), sc_y.inverse_transform(Y), color='red')
plt.plot(sc_x.inverse_transform(X), sc_y.inverse_transform(ya), color='blue')
plt.title('Position vs Salary')
plt.xlabel('Position')
plt.ylabel('Salary')
plt.show()
Comments
Post a Comment