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

Model - Ipynb - Colaboratory

The document loads the iris dataset, splits it into training and test sets, trains a Gaussian Naive Bayes model on the training set, and evaluates the model's performance on the test set. The model achieves 100% accuracy, precision, and recall on the test set. The document then uses the trained model to make predictions on new flower data and evaluates those predictions.
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)
30 views3 pages

Model - Ipynb - Colaboratory

The document loads the iris dataset, splits it into training and test sets, trains a Gaussian Naive Bayes model on the training set, and evaluates the model's performance on the test set. The model achieves 100% accuracy, precision, and recall on the test set. The document then uses the trained model to make predictions on new flower data and evaluates those predictions.
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

Model.ipynb - Colaboratory https://colab.research.google.com/drive/1KxUpkQiYh...

import seaborn as sns
iris=sns.load_dataset('iris')

iris.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 150 entries, 0 to 149
Data columns (total 5 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 sepal_length 150 non-null float64
1 sepal_width 150 non-null float64
2 petal_length 150 non-null float64
3 petal_width 150 non-null float64
4 species 150 non-null object
dtypes: float64(4), object(1)
memory usage: 6.0+ KB

iris.describe()

sepal_length sepal_width petal_length petal_width

count 150.000000 150.000000 150.000000 150.000000

mean 5.843333 3.057333 3.758000 1.199333

std 0.828066 0.435866 1.765298 0.762238

min 4.300000 2.000000 1.000000 0.100000

25% 5.100000 2.800000 1.600000 0.300000

50% 5.800000 3.000000 4.350000 1.300000

75% 6.400000 3.300000 5.100000 1.800000

max 7.900000 4.400000 6.900000 2.500000

iris['species'].unique()

array(['setosa', 'versicolor', 'virginica'], dtype=object)

from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB

x =iris.drop(columns='species')
y=iris['species']

x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2)

model1=GaussianNB()

1 of 3 08/05/23, 10:03
Model.ipynb - Colaboratory https://colab.research.google.com/drive/1KxUpkQiYh...

 0s completed at 10:02 AM
NB_model =model1.fit(x_train,y_train)
y_pred=NB_model.predict(x_test)

y_pred

array(['setosa', 'versicolor', 'versicolor', 'virginica', 'setosa',


'virginica', 'virginica', 'setosa', 'virginica', 'virginica',
'versicolor', 'versicolor', 'setosa', 'virginica', 'setosa',
'setosa', 'setosa', 'setosa', 'versicolor', 'setosa', 'setosa',
'setosa', 'setosa', 'virginica', 'versicolor', 'versicolor',
'setosa', 'virginica', 'virginica', 'virginica'], dtype='<U10')

from sklearn.metrics import accuracy_score

print("Accuracy =",accuracy_score(y_test,y_pred))

Accuracy = 1.0

from sklearn.metrics import recall_score,precision_score

print("Precision =",precision_score(y_test,y_pred,average='micro'))

Precision = 1.0

from sklearn.metrics import classification_report

print(classification_report(y_test,y_pred))

precision recall f1-score support

setosa 1.00 1.00 1.00 13


versicolor 1.00 1.00 1.00 7
virginica 1.00 1.00 1.00 10

accuracy 1.00 30
macro avg 1.00 1.00 1.00 30
weighted avg 1.00 1.00 1.00 30

new_data =[[5.5,4.3,5.1,0.2],[4.5,2.3,2.1,0.2],[3.3,2.1,3.1,0.8]]

new_pred=NB_model.predict(new_data)

/usr/local/lib/python3.10/dist-packages/sklearn/base.py:439: UserWarning: X does n


warnings.warn(

new_pred

2 of 3 08/05/23, 10:03
Model.ipynb - Colaboratory https://colab.research.google.com/drive/1KxUpkQiYh...

array(['virginica', 'setosa', 'versicolor'], dtype='<U10')

new_data1 =[[5.5,4.3,5.1,0.2]]

new_pred1=NB_model.predict(new_data1)
new_pred1

/usr/local/lib/python3.10/dist-packages/sklearn/base.py:439: UserWarning: X does n


warnings.warn(
array(['virginica'], dtype='<U10')

new_pred1

array(['virginica'], dtype='<U10')

Colab paid products - Cancel contracts here

3 of 3 08/05/23, 10:03

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy