Created
May 9, 2020 12:52
-
-
Save VincentTatan/f9184450e70d357a2454858968323b9b 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
def generate_logs_from_classifiers(classifiers): | |
log_cols=["Classifier", "Accuracy", "Log Loss"] | |
log = pd.DataFrame(columns=log_cols) | |
for clf in classifiers: | |
name = clf.__class__.__name__ | |
print('Processing {} classifier'.format(name)) | |
clf.fit(X_train, y_train) | |
train_predictions = clf.predict(X_test) | |
train_predictions_proba = clf.predict_proba(X_test) | |
acc = accuracy_score(y_test, train_predictions) | |
ll = log_loss(y_test, train_predictions_proba) | |
log_entry = pd.DataFrame([[name, acc*100, ll]], columns=log_cols) | |
log = log.append(log_entry) | |
visualize_log(log) | |
return log | |
def visualize_log(log): | |
sns.set_color_codes("muted") | |
sns.barplot(x='Accuracy', y='Classifier', data=log, color="b") | |
plt.xlabel('Accuracy %') | |
plt.title('Classifier Accuracy') | |
plt.show() | |
sns.set_color_codes("muted") | |
sns.barplot(x='Log Loss', y='Classifier', data=log, color="g") | |
plt.xlabel('Log Loss') | |
plt.title('Classifier Log Loss') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment