# Load libraries
from sklearn.datasets import make_classification
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import roc_curve, roc_auc_score
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt

"""
Explanation: Title: Plot The Receiving Operating Characteristic Curve
Slug: plot_the_receiving_operating_characteristic_curve
Summary: How to plot the receiving operating characteristic curve in scikit-learn for machine learning in Python.  
Date: 2017-09-15 12:00
Category: Machine Learning
Tags: Model Evaluation 
Authors: Chris Albon
<a alt="ROC Curve" href="https://machinelearningflashcards.com">
    <img src="plot_the_receiving_operating_characteristic_curve/Receiver_Operating_Characteristic_print.png" class="flashcard center-block">
</a>
Preliminaries
End of explanation
"""


# Create feature matrix and target vector
X, y = make_classification(n_samples=10000, 
                           n_features=10, 
                           n_classes=2, 
                           n_informative=3,
                           random_state=3)

"""
Explanation: Generate Features And Target
End of explanation
"""


# Split into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=1)

"""
Explanation: Split Data Intro Training And Test Sets
End of explanation
"""


# Create classifier
clf = LogisticRegression()

# Train model
clf.fit(X_train, y_train)

"""
Explanation: Training Binary Classifier
End of explanation
"""


# Get predicted probabilities
y_score = clf.predict_proba(X_test)[:,1]

"""
Explanation: Create Predicted Probabilities
End of explanation
"""


# Create true and false positive rates
false_positive_rate, true_positive_rate, threshold = roc_curve(y_test, y_score)

# Plot ROC curve
plt.title('Receiver Operating Characteristic')
plt.plot(false_positive_rate, true_positive_rate)
plt.plot([0, 1], ls="--")
plt.plot([0, 0], [1, 0] , c=".7"), plt.plot([1, 1] , c=".7")
plt.ylabel('True Positive Rate')
plt.xlabel('False Positive Rate')
plt.show()

"""
Explanation: Plot Receiving Operating Characteristic Curve
End of explanation
"""


