0% found this document useful (0 votes)
21 views3 pages

Practical 9

The document describes a program to implement a support vector machine (SVM) classifier using a dataset. The program loads data, splits it into training and test sets, trains an SVM model on the training set, evaluates the model on the test set, makes predictions on new data, and plots the results. Key steps include loading data, splitting into train and test, training an SVM classifier, evaluating accuracy on test data, making predictions on new data, and plotting training and test values.

Uploaded by

Amandeep Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

Practical 9

The document describes a program to implement a support vector machine (SVM) classifier using a dataset. The program loads data, splits it into training and test sets, trains an SVM model on the training set, evaluates the model on the test set, makes predictions on new data, and plots the results. Key steps include loading data, splitting into train and test, training an SVM classifier, evaluating accuracy on test data, making predictions on new data, and plotting training and test values.

Uploaded by

Amandeep Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

VISHAL KUMAR 17MCA8247

Practical 9
Aim:- Write a program to implement Support Vector Machine using the dataset

Coding:-

import numpy as np

import matplotlib.pyplot as plt

import pandas as pd

df= pd.read_csv('data.csv')

print(df.head(10))

from sklearn.model_selection import train_test_split

x=df[["grade1","grade2"]]

y=df['label']

x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.35,random_state=4)

print(x_train.shape)

print(y_train.shape)

print(x_test.shape)

print(y_test.shape)

print(x_test.head())

from sklearn import svm

model=svm.SVC(gamma='auto')

model.fit(x_train,y_train)

#Getting model score

score=model.score(x_test,y_test)

print("Prediction Accuracy",score,"%")

UNIVERSITY INSTITUTE OF COMPUTING


VISHAL KUMAR 17MCA8247

f=np.array([60.6,60.9]).reshape(1,-1)

print(f)

res=model.predict(f)

print(res)

#plotting

yp=model.predict(x_test)

plt.plot(x_train['grade1'],y_train,'o',color='red')

plt.plot(x_test['grade1'],yp,'.',color='blue')

plt.legend(['Training Values' , 'Predicted Values'])

plt.title('support vector machine',color='blue')

Output:-

UNIVERSITY INSTITUTE OF COMPUTING


VISHAL KUMAR 17MCA8247

UNIVERSITY INSTITUTE OF COMPUTING

You might also like