Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

roc curve python

import sklearn.metrics as metrics
# calculate the fpr and tpr for all thresholds of the classification
probs = model.predict_proba(X_test)
preds = probs[:,1]
fpr, tpr, threshold = metrics.roc_curve(y_test, preds)
roc_auc = metrics.auc(fpr, tpr)

# method I: plt
import matplotlib.pyplot as plt
plt.title('Receiver Operating Characteristic')
plt.plot(fpr, tpr, 'b', label = 'AUC = %0.2f' % roc_auc)
plt.legend(loc = 'lower right')
plt.plot([0, 1], [0, 1],'r--')
plt.xlim([0, 1])
plt.ylim([0, 1])
plt.ylabel('True Positive Rate')
plt.xlabel('False Positive Rate')
plt.show()

# method II: ggplot
from ggplot import *
df = pd.DataFrame(dict(fpr = fpr, tpr = tpr))
ggplot(df, aes(x = 'fpr', y = 'tpr')) + geom_line() + geom_abline(linetype = 'dashed')
Comment

plotting roc curve

# Import necessary modules
from sklearn.metrics import roc_curve

# Compute predicted probabilities: y_pred_prob
y_pred_prob = logreg.predict_proba(X_test)[:,1]

# Generate ROC curve values: fpr, tpr, thresholds
fpr, tpr, thresholds = roc_curve(y_test, y_pred_prob)

# Plot ROC curve
plt.plot([0, 1], [0, 1], 'k--')
plt.plot(fpr, tpr)
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('ROC Curve')
plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: how to install flask module in vscode 
Python :: getting dummies and input them to pandas dataframe 
Python :: html to json python 
Python :: how to send whatsapp message with python 
Python :: check cuda version pytorch 
Python :: USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F) 
Python :: python how to make an array of ones 
Python :: sklearn minmaxscaler pandas 
Python :: python pi value 
Python :: python split range equally 
Python :: python read csv 
Python :: utf8 python encodage line 
Python :: time it in jupyter notebook 
Python :: py get days until date 
Python :: os get current directory 
Python :: python shuffle list 
Python :: python radians to degrees 
Python :: get current time in python with strftime 
Python :: how to open local html file in python 
Python :: run JupyterLab 
Python :: how to send get request python 
Python :: python conda how to see channels command 
Python :: how to get distinct value in a column dataframe in python 
Python :: plot categorical data matplotlib 
Python :: plotly plot size 
Python :: plt plot circle 
Python :: counter in sort python 
Python :: como eliminar palabras repetidos de una lista python 
Python :: import decisiontreeclassifier 
Python :: python randomized selection 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =