Skip to content

Instantly share code, notes, and snippets.

@slitayem
Created June 2, 2022 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slitayem/d60d688d65b4d50448d87c68e6820b27 to your computer and use it in GitHub Desktop.
Save slitayem/d60d688d65b4d50448d87c68e6820b27 to your computer and use it in GitHub Desktop.
Get the sklearn classification report as a DataFrame object
from sklearn import metrics
def get_classification_as_df(y_test: list, y_pred: list, sort_by: list =[])-> pd.DataFrame:
''' Get the classification report as a DataFrame'''
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=sort_by, ascending=False)
return df_classification_report
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment