How to plot ROC curve in Python

后端 未结 11 2272
臣服心动
臣服心动 2020-11-29 16:15

I am trying to plot a ROC curve to evaluate the accuracy of a prediction model I developed in Python using logistic regression packages. I have computed the true positive ra

11条回答
  •  清歌不尽
    2020-11-29 16:27

    The previous answers assume that you indeed calculated TP/Sens yourself. It's a bad idea to do this manually, it's easy to make mistakes with the calculations, rather use a library function for all of this.

    the plot_roc function in scikit_lean does exactly what you need: http://scikit-learn.org/stable/auto_examples/model_selection/plot_roc.html

    The essential part of the code is:

      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])
    

提交回复
热议问题