image_output_1.png
from matplotlib import pyplot

from numpy import argmax

from numpy import sqrt

from sklearn.linear_model import LogisticRegression

from sklearn.metrics import roc_curve

from sklearn.linear_model import LogisticRegression
classifier = LogisticRegression(random_state=0)
classifier.fit(X_train, y_train)
y_pred_lg = classifier.predict(X_test)

lr_probs = classifier.predict_proba(X_test)
lr_probs = lr_probs[:, 1]

from numpy import sqrt
from sklearn.metrics import roc_curve
from numpy import argmax
from matplotlib import pyplot
yhat_prob = classifier.predict_proba(X_test)
yhat = yhat_prob[:, 1]
fpr, tpr, thresholds = roc_curve(y_test, yhat)
gmeans = sqrt(tpr * (1 - fpr))
ix = argmax(gmeans)
print('Best Threshold=%f, G-Mean=%.3f' % (thresholds[ix], gmeans[ix]))
pyplot.plot([0, 1], [0, 1], linestyle='--', label='No Skill')
pyplot.plot(fpr, tpr, marker='.', label='Logistic')
pyplot.scatter(fpr[ix], tpr[ix], marker='o', color='black', label='Best')
pyplot.xlabel('False Positive Rate')
pyplot.ylabel('True Positive Rate')
pyplot.legend()
pyplot.show()