How to find the corresponding class in clf.predict_proba()

前端 未结 3 1032
感动是毒
感动是毒 2020-12-23 19:14

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\',\'         


        
相关标签:
3条回答
  • 2020-12-23 19:51

    As a rule, any attribute in a learner that ends with _ is a learned one. In your case you're looking for clf.classes_.

    Generally in Python, you can use the dir function to find out which attributes an object has.

    0 讨论(0)
  • 2020-12-23 20:09
    import pandas as pd
    test = [[0,1,1,0],[1,1,1,0]]
    pd.DataFrame(clf.predict_proba(test), columns=clf.classes_)
    
    Out[2]:
             one       three         two
    0   0.542815    0.361876    0.095309
    1   0.306431    0.612863    0.080706
    
    0 讨论(0)
  • 2020-12-23 20:10

    Just use the .classes_ attribute of the classifier to recover the mapping. In your example that gives:

    >>> clf.classes_
    array(['one', 'three', 'two'], 
          dtype='|S5')
    

    And thanks for putting a minimalistic reproduction script in your question, it makes answering really easy by just copy and pasting in a IPython shell :)

    0 讨论(0)
提交回复
热议问题