PML Ex4
PML Ex4
PML Ex4
DATE:
Aim:
Description:
SVM:
In machine learning, support vector machines (SVMs, also support vector networks) are supervised
learning models with associated learning algorithms that analyze data used for classification and
regression analysis. A Support Vector Machine (SVM) is a discriminative classifier formally defined
by a separating hyperplane.
Pyplot:
Most of the Matplotlib utilities lies under the pyplot submodule, and are usually imported under
the plt alias:
import matplotlib.pyplot as plt
scatter():
The scatter() function plots one dot for each observation. It needs two arrays of the same length, one for
the values of the x-axis, and one for values on the y-axis
sklearn. preprocessing:
The sklearn. preprocessing package provides several common utility functions and transformer classes
to change raw feature vectors into a representation that is more suitable for the downstream estimators.
Sklearn. metrics:
The sklearn. metrics module implements several loss, score, and utility functions to measure
classification performance. Some metrics might require probability estimates of the positive class,
confidence values, or binary decision values.
Sklearn. model_selection:
Model_selection is a method for setting a blueprint to analyze data and then using it to measure new
data. Selecting a proper model allows you to generate accurate results when making a prediction.
Sklearn. svm:
The implementation is based on libsvm. The fit time scales at least quadratically with the number of
samples and may be impractical beyond tens of thousands of samples. For large datasets consider
using LinearSVC or SGDClassifier instead, possibly after a Nystroem transformer or other Kernel
Approximation.
Methods:
IMPLEMENTATION:
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn.metrics import confusion_matrix
from sklearn.preprocessing import LabelEncoder
data = pd.read_csv('https://raw.githubusercontent.com/SnehaShukla937/SupportVectorMachine/’)
training_set,test_set = train_test_split(data,test_size=0.25,random_state=1)
x_train = training_set.iloc[:,0:2].values
y_train = training_set.iloc[:,2].values
x_test = test_set.iloc[:,0:2].values
y_test = test_set.iloc[:,2].values
classifier = SVC(kernel='rbf',random_state=1,C=1,gamma='auto')
classifier.fit(x_train,y_train)
SVC(C=1, gamma='auto', random_state=1)
y_pred = classifier.predict(x_test)
cm = confusion_matrix(y_test,y_pred)
print(cm)
accuracy = float(cm.diagonal().sum())/len(y_test)
print('model accuracy is:',accuracy*100,'%')
[[4 0]
[1 5]]
model accuracy is: 90.0 %
RESULT:
Thus the SVM classification using Python programming has been understood and executed
successfully.