Day-2 of #100DaysOfMLCode

Today we will code Support Vector Regression (SVR)

Check this out on Google Colab Notebook.

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Importing the data set
dataSet = pd.read_csv('Position_Salaries.csv')
x = dataSet.iloc[:, 1:2].values
y = dataSet.iloc[:, 2].values

# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc_x = StandardScaler()
x = sc_x.fit_transform(x)
sc_y = StandardScaler()
y = sc_y.fit_transform(y.reshape(10,1))

# Fitting SVR into the dataset
from sklearn.svm import SVR
regressor = SVM(kernel = 'rbf')
regressor.fit(x,y)

# Predicting the new results
y_pred = sc_y.inverse_transform(regressor.predict(sc_x.transform(np.array([[6.5]]))))

# Visualizing the SVM results
plt.scatter(x, y, color='red')
plt.plot(x, regressor.predict(x), color='blue')
plt.title('SVM')
plt.xlabel('Position levels')
plt.ylabel('Salaries')
plt.show()

Data-set is available here.

NOTE: Detailed explanation will be coming soon.

Leave a Reply

Close Menu