简体   繁体   中英

sci-kit learn output interpretation

When using sklearn, I sometimes have issues correctly assigning the output to the right label. When calling different methods on the result of a fit, sklearn only returns numpy arrays with no further labeling. For example, fitting a simple LDA that is trying to classify into two different groups will give me this output.

result = sklearn_lda.fit(X_train, y_train)

print "Prior probabilities are: \n", result.priors_
print "Group means are: \n", result.means_

Output

Prior probabilities are: 
[0.49198397 0.50801603]

Group means are: 
[[ 0.04279022  0.03389409]
 [-0.03954635 -0.03132544]]

How do I know which prior probability is associated with which class label? Same with the group means. For coefficients I know that sklearn outputs them in the same order as they are put in. In this case I am a little confused.

Use result.classes_ to get the array of classes seen by the model. All other attributes will be in the order of this array.

Most probably this will be alphabetically sorted. So if you have classes A and B, then the order will be:

['A', 'B']

Please see the documentation for available attributes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM