write a program in python 2fr to demonstrate naive bayes classification

Solutions on MaxInterview for write a program in python 2fr to demonstrate naive bayes classification by the best coders in the world

showing results for - "write a program in python 2fr to demonstrate naive bayes classification"
Cat
29 Oct 2016
1>>> from sklearn.naive_bayes import GaussianNB
2>>> from sklearn.naive_bayes import MultinomialNB
3>>> from sklearn import datasets
4>>> from sklearn.metrics import confusion_matrix
5>>> from sklearn.model_selection import train_test_split
6
7>>> iris = datasets.load_iris()
8>>> X = iris.data
9>>> y = iris.target
10
11# Split the data into a training set and a test set
12>>> X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
13>>> gnb = GaussianNB()
14>>> mnb = MultinomialNB()
15
16>>> y_pred_gnb = gnb.fit(X_train, y_train).predict(X_test)
17>>> cnf_matrix_gnb = confusion_matrix(y_test, y_pred_gnb)
18
19>>> print(cnf_matrix_gnb)
20[[16 0 0]
21 [ 0 18 0]
22 [ 0 0 11]]
23
24>>> y_pred_mnb = mnb.fit(X_train, y_train).predict(X_test)
25>>> cnf_matrix_mnb = confusion_matrix(y_test, y_pred_mnb)
26
27>>> print(cnf_matrix_mnb)
28[[16 0 0]
29 [ 0 0 18]
30 [ 0 0 11]]Copy
queries leading to this page
python program to implement naive bayes classificationna c3 afve bayesian classification is called e2 80 9cna c3 afve e2 80 9d 3fnaive bayes function in sklearn library single choice 10 class naive bayes classifier using scikit learn 27snaive bayes classification python codehow to assess naive bayes classificationbuilding naive bayes with large categories pythonnaive bayes classification in rnaive bayes classification python code how to get probability from naive bayes in pythonnaive bayes classifier pythonnaive bayes algorithm code in pythonnaive bayes sklearn image classificationna c3 afve bayes classification in pythonnaive bayes classifier python code examplescikit accuracy score of your bayesian classifierpython naive bayes classifier examplesimple naive bayes classifier pythonna c3 afve bayes classification with an examplepython sklearn bayes reviewsnaive bayes classification pythonexplain naive bayes classification with an examplenaive bayes machine learning pythonhow to apply naive bayes for binary classificationencode categorical features python for naive bayesnaive bayes test with example sklearnusing naive bayes print evaluation metrics and classification resulthow to apply naive bayes classifier in pythonnaive bayes classification code in pythonsimple code based on navie bayes algorithmnaive bayes classifie accuracy python sklearnbayes classifier pythonpython bayesian classifierpython naive bayes classification examplepython naive bayes site 3adatacamp comperformed classification 3a na c3 afve bayes 2c based on the 70 2f30 split first naive bayes classification accuracy using scikit learnvariations of naive bayes algorithm in pythonnaive bayes classifier python code for numerical datasetwrite a program in python 2fr to demonstrate naive bayes classification