# Roll NO. : 057

# Importing libraries

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import datasets, preprocessing

# naive and gaussian model
from sklearn.naive_bayes import GaussianNB, MultinomialNB
from sklearn.model_selection import train_test_split

# for accuracy
from sklearn import metrics

# print precision and recall
from sklearn.metrics import precision_score
from sklearn.metrics import recall_score
from sklearn.datasets import load_digits

# Loading digits dataset from sklearn

main_data = load_digits()

plt.figure(figsize = (20, 20))

for i in range(20):
    plt.subplot(8, 8, i + 1)
    plt.imshow(main_data.images[i])

from sklearn import preprocessing

ohe = preprocessing.OneHotEncoder()

# Train Test Division : 65%-35% & Roll No. = 57

from sklearn.model_selection import train_test_split

X_train, X_test, Y_train, Y_test = train_test_split(main_data.data, main_data.target, test_size = 0.35, random_state = 57)


# Gaussina models

gnb = GaussianNB()

# train model

gnb.fit(X_train, Y_train)

# training completed

Y_predicted = gnb.predict(X_test)

print(f"Accuracy :- {metrics.accuracy_score(Y_test, Y_predicted)}")

main_data.images[3]

# True prediction

_, axes = plt.subplots(nrows=1, ncols=4, figsize=(10, 3))
for ax, image, prediction in zip(axes, X_test, Y_predicted):
    ax.set_axis_off()
    image = image.reshape(8, 8)
    ax.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
    ax.set_title(f'Prediction: {prediction}')

print(f"Classification report for classifier {gnb}:\n"
      f"{metrics.classification_report(Y_test, Y_predicted)}\n")

disp = metrics.plot_confusion_matrix(gnb, X_test, Y_test)
disp.figure_.suptitle("Confusion Matrix")
print(f"Confusion matrix:\n{disp.confusion_matrix}")

plt.show()


    
a3cd962e7fbf1127f6a4c0578b60933841b4cd2f
<mask token>

<mask token>
plt.figure(figsize=(20, 20))
for i in range(20):
    plt.subplot(8, 8, i + 1)
    plt.imshow(main_data.images[i])
<mask token>
gnb.fit(X_train, Y_train)
<mask token>
print(f'Accuracy :- {metrics.accuracy_score(Y_test, Y_predicted)}')
main_data.images[3]
<mask token>
for ax, image, prediction in zip(axes, X_test, Y_predicted):
    ax.set_axis_off()
    image = image.reshape(8, 8)
    ax.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
    ax.set_title(f'Prediction: {prediction}')
print(
    f"""Classification report for classifier {gnb}:
{metrics.classification_report(Y_test, Y_predicted)}
"""
    )
<mask token>
disp.figure_.suptitle('Confusion Matrix')
print(f"""Confusion matrix:
{disp.confusion_matrix}""")
plt.show()

<mask token>
main_data = load_digits()
plt.figure(figsize=(20, 20))
for i in range(20):
    plt.subplot(8, 8, i + 1)
    plt.imshow(main_data.images[i])
<mask token>
ohe = preprocessing.OneHotEncoder()
<mask token>
X_train, X_test, Y_train, Y_test = train_test_split(main_data.data,
    main_data.target, test_size=0.35, random_state=57)
gnb = GaussianNB()
gnb.fit(X_train, Y_train)
Y_predicted = gnb.predict(X_test)
print(f'Accuracy :- {metrics.accuracy_score(Y_test, Y_predicted)}')
main_data.images[3]
_, axes = plt.subplots(nrows=1, ncols=4, figsize=(10, 3))
for ax, image, prediction in zip(axes, X_test, Y_predicted):
    ax.set_axis_off()
    image = image.reshape(8, 8)
    ax.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
    ax.set_title(f'Prediction: {prediction}')
print(
    f"""Classification report for classifier {gnb}:
{metrics.classification_report(Y_test, Y_predicted)}
"""
    )
disp = metrics.plot_confusion_matrix(gnb, X_test, Y_test)
disp.figure_.suptitle('Confusion Matrix')
print(f"""Confusion matrix:
{disp.confusion_matrix}""")
plt.show()

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import datasets, preprocessing
from sklearn.naive_bayes import GaussianNB, MultinomialNB
from sklearn.model_selection import train_test_split
from sklearn import metrics
from sklearn.metrics import precision_score
from sklearn.metrics import recall_score
from sklearn.datasets import load_digits
main_data = load_digits()
plt.figure(figsize=(20, 20))
for i in range(20):
    plt.subplot(8, 8, i + 1)
    plt.imshow(main_data.images[i])
from sklearn import preprocessing
ohe = preprocessing.OneHotEncoder()
from sklearn.model_selection import train_test_split
X_train, X_test, Y_train, Y_test = train_test_split(main_data.data,
    main_data.target, test_size=0.35, random_state=57)
gnb = GaussianNB()
gnb.fit(X_train, Y_train)
Y_predicted = gnb.predict(X_test)
print(f'Accuracy :- {metrics.accuracy_score(Y_test, Y_predicted)}')
main_data.images[3]
_, axes = plt.subplots(nrows=1, ncols=4, figsize=(10, 3))
for ax, image, prediction in zip(axes, X_test, Y_predicted):
    ax.set_axis_off()
    image = image.reshape(8, 8)
    ax.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
    ax.set_title(f'Prediction: {prediction}')
print(
    f"""Classification report for classifier {gnb}:
{metrics.classification_report(Y_test, Y_predicted)}
"""
    )
disp = metrics.plot_confusion_matrix(gnb, X_test, Y_test)
disp.figure_.suptitle('Confusion Matrix')
print(f"""Confusion matrix:
{disp.confusion_matrix}""")
plt.show()

# Roll NO. : 057

# Importing libraries

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import datasets, preprocessing

# naive and gaussian model
from sklearn.naive_bayes import GaussianNB, MultinomialNB
from sklearn.model_selection import train_test_split

# for accuracy
from sklearn import metrics

# print precision and recall
from sklearn.metrics import precision_score
from sklearn.metrics import recall_score
from sklearn.datasets import load_digits

# Loading digits dataset from sklearn

main_data = load_digits()

plt.figure(figsize = (20, 20))

for i in range(20):
    plt.subplot(8, 8, i + 1)
    plt.imshow(main_data.images[i])

from sklearn import preprocessing

ohe = preprocessing.OneHotEncoder()

# Train Test Division : 65%-35% & Roll No. = 57

from sklearn.model_selection import train_test_split

X_train, X_test, Y_train, Y_test = train_test_split(main_data.data, main_data.target, test_size = 0.35, random_state = 57)


# Gaussina models

gnb = GaussianNB()

# train model

gnb.fit(X_train, Y_train)

# training completed

Y_predicted = gnb.predict(X_test)

print(f"Accuracy :- {metrics.accuracy_score(Y_test, Y_predicted)}")

main_data.images[3]

# True prediction

_, axes = plt.subplots(nrows=1, ncols=4, figsize=(10, 3))
for ax, image, prediction in zip(axes, X_test, Y_predicted):
    ax.set_axis_off()
    image = image.reshape(8, 8)
    ax.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
    ax.set_title(f'Prediction: {prediction}')

print(f"Classification report for classifier {gnb}:\n"
      f"{metrics.classification_report(Y_test, Y_predicted)}\n")

disp = metrics.plot_confusion_matrix(gnb, X_test, Y_test)
disp.figure_.suptitle("Confusion Matrix")
print(f"Confusion matrix:\n{disp.confusion_matrix}")

plt.show()


    