GithubHelp home page GithubHelp logo

Comments (3)

zaynaab avatar zaynaab commented on May 19, 2024 1

from python.

seyyedmsl82 avatar seyyedmsl82 commented on May 19, 2024

Because it is deprecated. Try to use sklearn.metrics.ConfusionMatrixDisplay.

Here is its document: ConfusionMatrixDisplay

from python.

seyyedmsl82 avatar seyyedmsl82 commented on May 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.