Skip to content

Commit 9de5331

Browse files
authored
Update gaussian_naive_bayes.py
The algorithm section now provides a clear overview of the steps the program follows, making it easier to understand the flow of the code.
1 parent 40f65e8 commit 9de5331

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Diff for: machine_learning/gaussian_naive_bayes.py.broken.txt

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
# Gaussian Naive Bayes Example
22
import time
3-
43
from matplotlib import pyplot as plt
54
from sklearn.datasets import load_iris
65
from sklearn.metrics import accuracy_score, plot_confusion_matrix
76
from sklearn.model_selection import train_test_split
87
from sklearn.naive_bayes import GaussianNB
98

10-
119
def main():
12-
1310
"""
1411
Gaussian Naive Bayes Example using sklearn function.
1512
Iris type dataset is used to demonstrate algorithm.
13+
14+
Algorithm:
15+
1. Load Dataset: Import the Iris dataset.
16+
2. Data Preprocessing: Split dataset into features (X) and labels (y).
17+
3. Model Initialization: Initialize Gaussian Naive Bayes model.
18+
4. Model Training: Fit model using training data.
19+
5. Make Predictions: Predict labels for the test dataset.
20+
6. Evaluate Model: Calculate and display accuracy.
21+
7. Visualize Results: Generate and display a normalized confusion matrix.
1622
"""
1723

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

50-
5156
if __name__ == "__main__":
5257
main()

0 commit comments

Comments
 (0)