ML - Lab-7.ipynb - Colab
ML - Lab-7.ipynb - Colab
Program to implement K-nearest neighbour algorithm to classify the iris dataset. Print both Correct and wrong predictions
#NAIVE BAYE
import numpy as nm
import matplotlib.pyplot as mtp
import pandas as pd
# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.3, random_state = 0)
# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
x_train = sc.fit_transform(x_train)
x_test = sc.transform(x_test)
# Fitting Naive Bayes to the Training set
from sklearn.naive_bayes import GaussianNB
classifier = GaussianNB()
classifier.fit(x_train, y_train)
# Predicting the Test set results
y_pred = classifier.predict(x_test)
# Making the Confusion Matrix
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)
print(cm)
from sklearn.metrics import accuracy_score
accuracy_score(y_test, y_pred)
## classification report
from sklearn.metrics import classification_report
class_report=classification_report(y_test, y_pred)
print("Classification Report:\n",class_report)
[[74 5]
[ 8 33]]
Classification Report:
precision recall f1-score support