Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Machine Learning by (19k points)

I have a number of classes and corresponding feature vectors, and when I run predict_proba() I will get this:

classes = ['one','two','three','one','three']

feature = [[0,1,1,0],[0,1,0,1],[1,1,0,0],[0,0,0,0],[0,1,1,1]]

from sklearn.naive_bayes import BernoulliNB

clf = BernoulliNB()

clf.fit(feature,classes)

clf.predict_proba([0,1,1,0])

>> array([[ 0.48247836,  0.40709111, 0.11043053]])

I would like to get what probability that corresponds to what class. On this page it says that they are ordered by arithmetical order, I'm not 100% sure of what that means: http://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html#sklearn.svm.SVC.predict_proba

Does it mean that I have gone through my training examples assign the corresponding index to the first encounter of a class, or is there a command like

clf.getClasses() = ['one','two','three']

1 Answer

0 votes
by (33.1k points)

You can simply use .classes_ attributes of the classifier to recover the mapping of classes. 

For example:

>>> clf.classes_

array(['one', 'three', 'two'], 

      dtype='|S5')

Your short and optimal question helped me answer faster.

Hope this answer helps.

Learn Machine Learning with the help of this Machine Learning Tutorial.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...