Issue
I'm currently working on a multi-label classification problem using scikit-learn
, and I'm having a bit of trouble learning how to get the predicted probabilities for each class/label - similar to what scikit-learn's .predict_proba()
method does on binary classification tasks.
My y
is a 100x10 2d array, having 10 unique classes, and I'm using scikit-learn's ensemble.RandomForestClassifier()
as my classifier.
What I would like to do is just predict the probability that a set of given features belongs to one of the classes (noted below as cl_
) in y
. So basically I'm imagining an output similar to this:
cl_1 | cl_2 | cl_3 | cl_4 | cl_5 | cl_6 | cl_7 | cl_8 | cl_9 | cl_10
---------------------------------------------------------------------
0.0 | 0.0 | 0.0 | 0.1 | 0.3 | 0.0 | 0.0 | 0.0 | 0.6 | 0.0
NOTE: I have fit the Random Forest classifier to the dataset and the .predict()
method works as expected. However, the .predict_proba()
method returns probabilities in the shape of C x M, where C is the number of unique classes, and M is the number of instances in the dataset.
Clarification/Update: Here's an actual y
instance from my dataset:
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0]
Using the .predict_proba()
on X_test
returns a 2d-array of shape 39 x 848,048 (where 39 is the number of unique classes and 848,048 is the number of instances).
So in layman's terms, what I'm asking is: How do I make since of what .predict_proba()
returns (insofar as the little chart above is concerned).
NOTE: This:
y_hat_proba = clf.predict_proba(X_test)
print(y_hat_proba[0][1])
returns [ 1. 0.]
Solution
You can use .predict_proba(X_test)
to get the probability per class on a new set of points. If you need a prediction for a single point, just make sure X_test
has a single row.
The shape of the output should be in the shape [n_samples, n_classes] (in the test set). You can see the function's documentation.
Answered By - Dimosthenis
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.