2

I'm currently struggling plotting a ROC curve for a LinearSVC model. Since LinearSVC models can only call decision_function() to calculate the y_score (as opposed to the usual predict_proba()), I find it diffcult to compute fpr and tpr for each class. When trying

for i in range(n_classes):
    fpr[i], tpr[i], _ = roc_curve(y_test[:, i], y_score[:, i])
    roc_auc[i] = auc(fpr[i], tpr[i])

I get IndexError: too many indices for array. Switching to the solution provided in this answer would imply binarising the labels, which I would like to avoid. A normal SVC model with linear kernel wouldn't allow me to set an l1 penalty for l1-based feature selection, so that's to be avoided as well.

Any ideas on how to solve this?

Ionut Deaconu
  • 153
  • 10
  • The definition of ROC curve itself states that it plots the characteristics for a **binary classifier**. If you want to extend this to a multi-class problem the obvious approach is to use a `OneVsRestClassifier` as mentioned in that answer. Is there any specific reason why you don't want to use this approach? – panktijk Mar 05 '19 at 23:03
  • 1
    @panktijk I am not the OP but facing the same problem. The problem is not the multi classes, but rather the fact that the classifier does not return probabilities, but rather only the final classification results. It seems sclearn's functions can't handle those. Is there a nice build in way? – Gulzar Dec 07 '19 at 15:46
  • @panktijk my own question about that https://stackoverflow.com/questions/59227176/how-to-plot-roc-and-calculate-auc-for-binary-classifier-with-no-probabilities-s?noredirect=1#comment104668366_59227176 – Gulzar Dec 07 '19 at 15:47

0 Answers0