write a Program in Python/R to Demonstrate naive bayes classification

>>> from sklearn.naive_bayes import GaussianNB
>>> from sklearn.naive_bayes import MultinomialNB
>>> from sklearn import datasets
>>> from sklearn.metrics import confusion_matrix
>>> from sklearn.model_selection import train_test_split

>>> iris = datasets.load_iris()
>>> X = iris.data
>>> y = iris.target

# Split the data into a training set and a test set
>>> X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
>>> gnb = GaussianNB()
>>> mnb = MultinomialNB()

>>> y_pred_gnb = gnb.fit(X_train, y_train).predict(X_test)
>>> cnf_matrix_gnb = confusion_matrix(y_test, y_pred_gnb)

>>> print(cnf_matrix_gnb)
[[16 0 0]
 [ 0 18 0]
 [ 0 0 11]]

>>> y_pred_mnb = mnb.fit(X_train, y_train).predict(X_test)
>>> cnf_matrix_mnb = confusion_matrix(y_test, y_pred_mnb)

>>> print(cnf_matrix_mnb)
[[16 0 0]
 [ 0 0 18]
 [ 0 0 11]]Copy

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
naive bayes classification python python naive bayes classification example naive bayes classification python code Naïve Bayes Classification in python naive bayes classification code in python python program to implement naive bayes classification naive bayes classification in r scikit accuracy score of your Bayesian classifier python naive bayes site:datacamp.com naïve Bayesian classification is called “naïve”? variations of naive bayes algorithm in python python sklearn bayes reviews Naive Bayes classifier python code for numerical dataset how to assess naive bayes classification Naive Bayes function in sklearn library. Single choice. python bayesian classifier bayes classifier python naive bayes classifier python naive bayes machine learning python naive bayes classification accuracy using scikit-learn naive bayes classifie accuracy python sklearn naive bayes test with example sklearn how to get probability from naive bayes in python simple code based on navie bayes algorithm naive bayes algorithm code in python naive bayes sklearn image classification python naive bayes classifier example 10-class Naive Bayes classifier using scikit-learn's using naive bayes print evaluation metrics and classification result naive bayes classifier python code example how to apply naive bayes for binary classification how to apply naive bayes classifier in python building naive bayes with large categories python encode categorical features python for naive bayes Performed classification: Naïve Bayes, based on the 70/30 split first. simple naive bayes classifier python
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source