How to get ROC curve for decision tree?

Viewed 18701

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?

2 Answers

Think that for a decision tree you can use .predict_proba() instead of .decision_function() so you will get something as below:

y_score = classifier.fit(X_train, y_train).predict_proba(X_test)

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.

Related