0% found this document useful (0 votes)
12 views2 pages

SVM Ass

Uploaded by

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

SVM Ass

Uploaded by

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

9/24/24, 12:03 PM SVM Code - Jupyter Notebook

In [36]: import numpy as np


import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC

In [37]: iris = datasets.load_iris()


X = iris.data
y = iris.target

In [38]: X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random


In [39]: clf = SVC(kernel='linear')


clf.fit(X_train, y_train)

Out[39]: SVC(kernel='linear')

In [40]: y_pred = clf.predict(X_test)

In [41]: from sklearn.metrics import accuracy_score


print("Accuracy:", accuracy_score(y_test, y_pred))

Accuracy: 1.0

In [47]: X_train_reduced = X_train[:, :2]


clf.fit(X_train_reduced, y_train)
plot_decision_boundary(X_test[:, :2], y_test, clf)

localhost:8888/notebooks/SVM Code.ipynb# 1/2


9/24/24, 12:03 PM SVM Code - Jupyter Notebook

localhost:8888/notebooks/SVM Code.ipynb# 2/2

You might also like