Mark Keane
Mark Keane

Reputation: 1044

In sklearn is there a way to test the confidence of a prediction made my a DecisionTreeClassifier Model?

I am succesfully using the sklearn library in python and really enjoying it.

I am able to create and fit a model of the DecisionTreeClassifierType with the following code:

clf = tree.DecisionTreeClassifier()

clf = clf.fit(features, labels)

I can then use the model to predict the class of new inputs like so:

clf.predict([[20, 50, 10]])

The above line will return a 0 or a 1 depending on which class the model predicts this data will have.I was wondering if there is some way to get the confidence/probability the model has for a prediction?

So if it predicts the classification for the input to be 1, the probabiliy/confidence would be a decimal like 0.8 or a percent like 80%. Any ideas on if this is compatible/possible with sklearn's DecisionTreeClassifier?

Upvotes: 3

Views: 2767

Answers (1)

maxymoo
maxymoo

Reputation: 36545

This is done in sklearn.tree.DecisionTreeClassifier.predict_proba:

Predict class probabilities of the input samples X. The predicted class probability is the fraction of samples of the same class in a leaf.

Upvotes: 5

Related Questions