4-Support Vector Machine Code

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 5

Machine Learning

19ME 3220
III/IV B.Tech
Odd Sem
for the Academic Year 2021-21

Sesion-36
Support Vector Machine
S. Ramesh Kumar
Course Co-ordinator
Support Vector Machine
User ID Gender Age Est-Salary Purchase

Import numpy as np 0 15624510 Male 19 19000 0


1 Import matplotlib.pyplot as plt
1 15810944 Male 35 20000 0
Import pandas as pd
2 15668575 Female 26 43000 0

df = pd.read_csv(‘Social_Network_Ads.csv’)
3 15603246 Female 27 57000 0
2 df.head()
4 15804002 Male 19 76000 0

x = df.iloc[:, [2, 3]].values


3 y = df.iloc[:, -1].values

Splitting the data set into training and test set


from sklearn.model_selection import train_test_split
4 x_train, x_test, y_train, y_test = train_test_split(x, y, text_size = 0.25,
random_state = 0)
Support Vector Machine
Feature Scaling
from sklearn.preprocessing import StandardScaler
5 sc = StandardScaler()
x_train = sc.fit_transform(x_train)
x_test = sc.transform(x_test)

Training the Kernel SVM model on the training set


from sklearn.svm import SVC
6 classifier = SVC(kernel = ‘linear’, random_state = 0)
classifier.fit(x_train, y_train) Init signature:
SVC( *, C=1.0,
Kernel=‘rbf’
Predicting the Test set results Degree=3
Gamma=‘scale’
y_pred = classifier.predict(x_test)
7 Coef0=0.0,
Shrinking=True,
Probability=False,
Support Vector Machine
Predicting the Test set results

8 y_pred = classifier.predict(x_test)

Making the Confusion Matrix


66 2
9 from sklearn.metrics import confusion matrix
8 24
cm = confusion matrix(y_test, y_pred)
print(cm)

Making the Confusion Matrix


10 from sklearn.metrics import confusion matrix
cm = confusion matrix(y_test, y_pred)
print(cm)
Support Vector Machine

You might also like