Created
December 26, 2019 22:02
-
-
Save egemenzeytinci/c3f464af37a4cd36046116b7bddc5bac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Report: | |
def __init__(self, X_test, y_test): | |
self.X = X_test | |
self.y = y_test | |
def metrics(self, model): | |
y_pred = model.predict(self.X) | |
print('Accuracy score:\n') | |
print(accuracy_score(self.y, y_pred)) | |
print('\nConfusion Matrix:\n') | |
print(confusion_matrix(self.y, y_pred)) | |
print('\nClassification Report:\n') | |
print(classification_report(self.y, y_pred)) | |
def plot_roc_curve(self, model, part='h1', save=False): | |
probs = model.predict_proba(self.X) | |
preds = probs[:, 1] | |
fpr, tpr, threshold = roc_curve(self.y, preds) | |
roc_auc = auc(fpr, tpr) | |
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') | |
if save: | |
name = model.__class__.__name__ | |
plt.savefig(f'./images/{name}_{part}.png') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment