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

Visualizing Iris Dataset with SVM

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)
42 views3 pages

Visualizing Iris Dataset with SVM

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

from sklearn import datasets, svm

iris = datasets.load_iris()
def visualize_sepal_data():
X = [Link][:, :2]
y = [Link]
[Link](X[:, 0], X[:, 1], c=y, cmap=[Link])
[Link]('Sepal length')
[Link]('Sepal width')
[Link]('Sepal Width & Length')
[Link]()
def visualize_petal_data():
X = [Link][:, 2:]
y = [Link]
[Link](X[:, 0], X[:, 1], c=y, cmap=[Link])
[Link]('Petal length')
[Link]('Petal width')
[Link]('Petal Width & Length')
[Link]()

X = [Link][:, :2]
y = [Link]
C = 1.0

svc = [Link](kernel='linear', C=C).fit(X, y)

lin_svc = [Link](C=C).fit(X, y)

rbf_svc = [Link](kernel='rbf', gamma=0.7, C=C).fit(X, y)

poly_svc = [Link](kernel='poly', degree=3, C=C).fit(X, y)

h = 0.02

x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1


y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
xx, yy = [Link]([Link](x_min, x_max, h),
[Link](y_min, y_max, h))

titles = ['SVC with linear kernel',


'LinearSVC (linear kernel)',
'SVC with RBF kernel',
'SVC with polynomial (degree 3) kernel']

for i, clf in enumerate((svc, lin_svc, rbf_svc, poly_svc)):

[Link] 06/11/24, 10 02 AM
Page 39 of 56
:
for i, clf in enumerate((svc, lin_svc, rbf_svc, poly_svc)):
[Link](2, 2, i + 1)
plt.subplots_adjust(wspace=0.4, hspace=0.4)

Z = [Link](np.c_[[Link](), [Link]()])

Z = [Link]([Link])

[Link](xx, yy, Z, cmap=[Link], alpha=0.8)

[Link](X[:, 0], X[:, 1], c=y, cmap=[Link])

[Link]('Sepal length')
[Link]('Sepal width')
[Link]('Petal length')
[Link]('Petal width')

[Link]([Link](), [Link]())
[Link]([Link](), [Link]())

[Link](())
[Link](())

[Link](titles[i])

[Link]()

[Link] 06/11/24, 10 02 AM
Page 40 of 56
:
Exp 10

import numpy as np

input_data = [Link]([[1, 0, 1, 0], [1, 0, 1, 1], [0, 1, 0, 1]])


output_data = [Link]([[1], [1], [0]])

def sigmoid(x):
return 1 / (1 + [Link](-x))

def sigmoid_derivative(x):
return x * (1 - x)

epochs = 5000
learning_rate = 0.1

input_neurons = input_data.shape[1]
hidden_neurons = 3
output_neurons = 1

[Link] 06/11/24, 10 02 AM
Page 41 of 56
:

You might also like