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

PDF Split

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

PDF Split

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/ 3

from sklearn import datasets, svm

iris = datasets.load_iris()
def visualize_sepal_data():
X = iris.data[:, :2]
y = iris.target
plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.coolwarm)
plt.xlabel('Sepal length')
plt.ylabel('Sepal width')
plt.title('Sepal Width & Length')
plt.show()
def visualize_petal_data():
X = iris.data[:, 2:]
y = iris.target
plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.coolwarm)
plt.xlabel('Petal length')
plt.ylabel('Petal width')
plt.title('Petal Width & Length')
plt.show()

X = iris.data[:, :2]
y = iris.target
C = 1.0

svc = svm.SVC(kernel='linear', C=C).fit(X, y)

lin_svc = svm.LinearSVC(C=C).fit(X, y)

rbf_svc = svm.SVC(kernel='rbf', gamma=0.7, C=C).fit(X, y)

poly_svc = svm.SVC(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 = np.meshgrid(np.arange(x_min, x_max, h),
np.arange(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)):

https://colab.research.google.com/drive/13oTpQmuxdl-qr9HHkOClyK7IY5L-laNc#scrollTo=WVG8_Jx4OPEy 06/11/24, 10 02 AM
Page 39 of 56
:
for i, clf in enumerate((svc, lin_svc, rbf_svc, poly_svc)):
plt.subplot(2, 2, i + 1)
plt.subplots_adjust(wspace=0.4, hspace=0.4)

Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])

Z = Z.reshape(xx.shape)

plt.contourf(xx, yy, Z, cmap=plt.cm.coolwarm, alpha=0.8)

plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.coolwarm)

plt.xlabel('Sepal length')
plt.ylabel('Sepal width')
plt.xlabel('Petal length')
plt.ylabel('Petal width')

plt.xlim(xx.min(), xx.max())
plt.ylim(yy.min(), yy.max())

plt.xticks(())
plt.yticks(())

plt.title(titles[i])

plt.show()

https://colab.research.google.com/drive/13oTpQmuxdl-qr9HHkOClyK7IY5L-laNc#scrollTo=WVG8_Jx4OPEy 06/11/24, 10 02 AM
Page 40 of 56
:
Exp 10

import numpy as np

input_data = np.array([[1, 0, 1, 0], [1, 0, 1, 1], [0, 1, 0, 1]])


output_data = np.array([[1], [1], [0]])

def sigmoid(x):
return 1 / (1 + np.exp(-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

https://colab.research.google.com/drive/13oTpQmuxdl-qr9HHkOClyK7IY5L-laNc#scrollTo=WVG8_Jx4OPEy 06/11/24, 10 02 AM
Page 41 of 56
:

You might also like