[go: up one dir, main page]

0% found this document useful (0 votes)
18 views2 pages

Iris Classification with Bayes

The iris dataset is classified using a Gaussian Naive Bayes classifier, with an 80:20 training to testing split. The training accuracy is 95% and the testing accuracy is approximately 96.67%. Confusion matrices are displayed for both training and testing predictions.

Uploaded by

premiumapk321
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)
18 views2 pages

Iris Classification with Bayes

The iris dataset is classified using a Gaussian Naive Bayes classifier, with an 80:20 training to testing split. The training accuracy is 95% and the testing accuracy is approximately 96.67%. Confusion matrices are displayed for both training and testing predictions.

Uploaded by

premiumapk321
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/ 2

Classify the iris dataset using a Bayes classifier.

Divide the dataset into training and testing in the ratio 80:20. Use the functions from the
sklearn package. Assume the data follows a gaussian distribution. Display the training and testing accuracy, confusion matrix.

import pandas as pd
import numpy as np
from sklearn.datasets import load_iris
from sklearn.naive_bayes import GaussianNB
from sklearn.model_selection import train_test_split
from sklearn.metrics import ConfusionMatrixDisplay, accuracy_score

X, y=load_iris(return_X_y=True, as_frame=True)
X_train, X_test, y_train, y_test=train_test_split(X, y, test_size=0.2, random_state=0)

clsf=GaussianNB()
clsf.fit(X_train, y_train)

▾ GaussianNB

GaussianNB()

train_predictions=clsf.predict(X_train)
test_predictions=clsf.predict(X_test)

accuracy_score(y_train, train_predictions)

0.95

ConfusionMatrixDisplay.from_predictions(y_train, train_predictions, display_labels=clsf.classes_);

accuracy_score(y_test, test_predictions)

0.9666666666666667

ConfusionMatrixDisplay.from_predictions(y_test, test_predictions, display_labels=clsf.classes_);


Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/fontdata.js

You might also like