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 rate as well as the false positive rate; however, I am unable to figure out how to plot these correctly using matplotlib
and calculate the AUC value. How could I do that?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
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:
Here are two ways you may try, assuming your
model
is an sklearn predictor:or try
It is not at all clear what the problem is here, but if you have an array
true_positive_rate
and an arrayfalse_positive_rate
, then plotting the ROC curve and getting the AUC is as simple as:AUC curve For Binary Classification using matplotlib
Load Breast Cancer Dataset
Split the Dataset
Model
Accuracy
AUC Curve
Here is a python code :
More reference