Comments (3)
from python.
Because it is deprecated. Try to use sklearn.metrics.ConfusionMatrixDisplay.
Here is its document: ConfusionMatrixDisplay
from python.
You can use this code:
# Gaussian Naive Bayes Example
import time
from matplotlib import pyplot as plt
from sklearn.datasets import load_iris
from sklearn.metrics import accuracy_score, ConfusionMatrixDisplay, 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.
"""
# Load Iris dataset
iris = load_iris()
# Split dataset into train and test data
x = iris["data"] # features
y = iris["target"]
x_train, x_test, y_train, y_test = train_test_split(
x, y, test_size=0.3, random_state=1
)
# Gaussian Naive Bayes
nb_model = GaussianNB()
time.sleep(2.9)
model_fit = nb_model.fit(x_train, y_train)
y_pred = model_fit.predict(x_test) # Predictions on the test set
# Display Confusion Matrix
cm = confusion_matrix(y_test, y_pred, labels=nb_model.classes_)
ConfusionMatrixDisplay.from_estimator(nb_model, x_test, y_test)
plt.title("Normalized Confusion Matrix - IRIS Dataset")
plt.show()
time.sleep(1.8)
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()
from python.
Related Issues (20)
- Build Test Broken
- Learning Python HOT 1
- @Git~CDT Open Repo~Nomine'
- Adding Gaussian Error Linear Unit to neural network activation functions HOT 1
- Misformatted/linked wiki entry in python sorting
- Global variable should not using in class method HOT 3
- Broken Computer Vision README url
- attributeerror:'artistlist' object has no attribute 'remove' HOT 1
- Improve our test coverage HOT 1
- Adding Financial algorithms in Python HOT 3
- Haversine distance may be using the wrong phi1 and phi2 angle
- data_structures/trie/radix_tree.py wont really end up in 'case 1' for insert HOT 1
- TensorFlow in FINALLY compatible with Python 3.12
- Migrate to numpy 2.0 HOT 3
- Engineering HOT 5
- Failure when running pre-commit and try to fix errors.
- mimetypes can't get demo.js type HOT 4
- Implementation of the Knapsack Problem Solver
- aa
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python.