Experiment 14ml
Experiment 14ml
Experiment 14ml
import numpy as np
from sklearn import datasets, svm
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
def main():
# Import iris data
iris = datasets.load_iris()
x = iris.data[:, :2] # take the first two features.
y = iris.target # label
z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
z = z.reshape(xx.shape)
plt.subplot(3, 3, k)
title = 'C=' + str(i)
plt.title(title, fontsize=30)
plt.contourf(xx, yy, z, cmap=plt.get('Paired'), alpha=0.8)
plt.scatter(x_train[:, 0], x_train[:, 1], c=y_train,
cmap=plt.get('Paired'))
plt.xlim(xx.min(), xx.max())
k += 1
plt.show()
plt.close()
z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
z = z.reshape(xx.shape)
"""""
full_prediction = clf.predict(x_test)
print('[-] Number of mislabeled points out of a total %d points: %d'
% (len(y_test), (y_test != full_prediction).sum()))
print('[-] With an accuracy of %.3f%s'
% ((100 * (len(y_test) - (y_test != full_prediction).sum())) /
len(y_test), '%'))
"""
plt.show()
plt.close()
if __name__ == "__main__":
main()