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 :: ggplot2 histogram 
Python :: pandas remove time from datetime 
Python :: write dataframe to csv python 
Python :: python sendmessage whatsapp 
Python :: how to sort a list by the second element in tuple python 
Python :: prettytable python 
Python :: extract ints from strings in Pandas 
Python :: insertion sort python 
Python :: python find files recursive 
Python :: py get mouse coordinates 
Python :: python sleep milliseconds 
Python :: python utf 8 encoding 
Python :: python get file extension from path 
Python :: matplotlib insert text 
Python :: py sleep function 
Python :: python print float with 2 decimals 
Python :: python how much memory does a variable need 
Python :: python import from other folder outside folder 
Python :: rename multiple pandas columns with list 
Python :: save images cv2 
Python :: pandas has no attribute scatter_matrix 
Python :: python system arguments 
Python :: docker python 3.8 ubuntu 
Python :: get size of window tkinter 
Python :: version of scikit learn 
Python :: draw circles matplotlib 
Python :: seaborn pairplot set title 
Python :: django foreign key field on delete do nothing 
Python :: decisiontreeclassifier sklearn 
Python :: calculate euclidian distance python 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =