Skip to content

Instantly share code, notes, and snippets.

@fclesio
Created March 4, 2020 12:21
Show Gist options
  • Save fclesio/bb5871281debc07d75127552c56b08b5 to your computer and use it in GitHub Desktop.
Save fclesio/bb5871281debc07d75127552c56b08b5 to your computer and use it in GitHub Desktop.
Scikit Learn Classification Report in Dataframe
def get_classification_report(y_test, y_pred):
'''Source: https://stackoverflow.com/questions/39662398/scikit-learn-output-metrics-classification-report-into-csv-tab-delimited-format'''
from sklearn import metrics
report = metrics.classification_report(y_test, y_pred, output_dict=True)
df_classification_report = pd.DataFrame(report).transpose()
df_classification_report = df_classification_report.sort_values(by=['f1-score'], ascending=False)
return df_classification_report
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment