I am trying to find ROC curve and AUROC curve for decision tree. My code was something like
clf.fit(x,y)
y_score = clf.fit(x,y).decision_function(test[col])
pred = clf.predict_proba(test[col])
print(sklearn.metrics.roc_auc_score(actual,y_score))
fpr,tpr,thre = sklearn.metrics.roc_curve(actual,y_score)
output:
Error()
'DecisionTreeClassifier' object has no attribute 'decision_function'
basically, the error is coming up while finding the y_score
. Please explain what is y_score
and how to solve this problem?
First of all, the
DecisionTreeClassifier
has no attributedecision_function
.If I guess from the structure of your code , you saw this example
In this case the classifier is not the decision tree but it is the OneVsRestClassifier that supports the decision_function method.
You can see the available attributes of
DecisionTreeClassifier
hereA possible way to do it is to binarize the classes and then compute the auc for each class:
Example:
Result
Think that for a decision tree you can use .predict_proba() instead of .decision_function() so you will get something as below:
Then, the rest of the code will be the same. In fact, the roc_curve function from scikit learn can take two types of input: "Target scores, can either be probability estimates of the positive class, confidence values, or non-thresholded measure of decisions (as returned by “decision_function” on some classifiers)." See here for more details.