Professional Documents
Culture Documents
19Z237 ML Lab Ex8
19Z237 ML Lab Ex8
Balasubramanian S
19Z237
Aim:
Use Scikit-learn to train in SVM, NB, MLP Models, and Predict their
accuracy
In [ ]: from sklearn import datasets
iris = datasets.load_iris()
iris
iris_data = iris.data
iris_label = iris.target
len(iris_data)
print(iris.feature_names)
['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)']
120
Out[ ]:
svm_pred = svm_model.predict(x_test)
print(svm_pred)
print(y_test)
[0 0 0 2 1 1 2 2 1 2 0 2 1 1 0 1 0 0 0 1 2 0 0 0 2 2 1 2 0 1]
[0 0 0 2 1 1 2 2 1 2 0 2 1 1 0 1 0 0 0 1 2 0 0 0 2 2 1 2 0 1]
Accuracy: 100.0 %
Precision: [1. 1. 1.]
F1: [1. 1. 1.]
mlp_pred = mlp_model.predict(x_test)
print(mlp_pred)
print(y_test)
[0 0 0 2 1 1 2 2 1 2 0 2 1 1 0 1 0 0 0 2 2 0 0 0 2 2 2 2 0 1]
[0 0 0 2 1 1 2 2 1 2 0 2 1 1 0 1 0 0 0 1 2 0 0 0 2 2 1 2 0 1]
Accuracy: 93.33333333333333 %
Precision: [1. 1. 0.81818182]
F1: [1. 0.875 0.9 ]
/Users/Balasubramanian/Desktop/ML/balasubramanian/lib/python3.9/site-packages/sklear
n/neural_network/_multilayer_perceptron.py:692: ConvergenceWarning: Stochastic Optimi
zer: Maximum iterations (200) reached and the optimization hasn't converged yet.
warnings.warn(
nb_pred = nb_model.predict(x_test)
print(nb_pred)
print(y_test)
[0 0 0 2 1 1 2 2 1 2 0 2 1 1 0 1 0 0 0 1 1 0 0 0 2 2 2 2 0 1]
[0 0 0 2 1 1 2 2 1 2 0 2 1 1 0 1 0 0 0 1 2 0 0 0 2 2 1 2 0 1]
Accuracy: 93.33333333333333 %
Precision: [1. 0.88888889 0.88888889]
F1: [1. 0.88888889 0.88888889]
Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/fontdata.js