Skip to content

Update gaussian_naive_bayes.py #11718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions machine_learning/gaussian_naive_bayes.py.broken.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
# Gaussian Naive Bayes Example
import time

from matplotlib import pyplot as plt
from sklearn.datasets import load_iris
from sklearn.metrics import accuracy_score, plot_confusion_matrix
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB


def main():

"""
Gaussian Naive Bayes Example using sklearn function.
Iris type dataset is used to demonstrate algorithm.

Algorithm:
1. Load Dataset: Import the Iris dataset.
2. Data Preprocessing: Split dataset into features (X) and labels (y).
3. Model Initialization: Initialize Gaussian Naive Bayes model.
4. Model Training: Fit model using training data.
5. Make Predictions: Predict labels for the test dataset.
6. Evaluate Model: Calculate and display accuracy.
7. Visualize Results: Generate and display a normalized confusion matrix.
"""

# Load Iris dataset
Expand All @@ -37,7 +43,7 @@ def main():
x_test,
y_test,
display_labels=iris["target_names"],
cmap="Blues", # although, Greys_r has a better contrast...
cmap="Blues", # although Greys_r has better contrast...
normalize="true",
)
plt.title("Normalized Confusion Matrix - IRIS Dataset")
Expand All @@ -47,6 +53,5 @@ def main():
final_accuracy = 100 * accuracy_score(y_true=y_test, y_pred=y_pred)
print(f"The overall accuracy of the model is: {round(final_accuracy, 2)}%")


if __name__ == "__main__":
main()