Alexander Veheecke
Alexander Veheecke

Reputation: 47

Table summary for sklearn classification report

I have quite a few model classification reports which I developed using sklearn

===== SGD_TWEETEVAL=====

              precision    recall  f1-score   support

    Negative       0.64      0.56      0.60      1010
     Neutral       0.62      0.73      0.67      1476
    Positive       0.64      0.49      0.55       584

    accuracy                           0.63      3070
   macro avg       0.63      0.59      0.61      3070
weighted avg       0.63      0.63      0.63      3070

=====LINEAR SVC_TWEETEVAL=====

              precision    recall  f1-score   support

    Negative       0.62      0.59      0.60      1010
     Neutral       0.62      0.68      0.65      1476
    Positive       0.61      0.52      0.56       584

    accuracy                           0.62      3070
   macro avg       0.62      0.60      0.60      3070
weighted avg       0.62      0.62      0.62      3070

=====Bernoulli NB_TWEETEVAL=====

              precision    recall  f1-score   support

    Negative       0.63      0.64      0.63      1010
     Neutral       0.64      0.62      0.63      1476
    Positive       0.54      0.56      0.55       584

    accuracy                           0.62      3070
   macro avg       0.60      0.61      0.60      3070
weighted avg       0.62      0.62      0.62      3070

=====Multinominal NB_TWEETEVAL=====

              precision    recall  f1-score   support

    Negative       0.65      0.57      0.60      1010
     Neutral       0.61      0.74      0.67      1476
    Positive       0.63      0.42      0.51       584

    accuracy                           0.62      3070
   macro avg       0.63      0.58      0.59      3070
weighted avg       0.63      0.62      0.62      3070

I would like to summaries them in a table like the following:

Here

I could do it myself using LaTeX, but I am wondering if there is a quicker way to do so. sklearn does not seem to provide a table functionality.

Upvotes: 1

Views: 1635

Answers (1)

Kraigolas
Kraigolas

Reputation: 5560

sklearn.metrics.classification_report takes the argument output_dict. If you write output_dict=True, the result will not be a string table, but will instead be a dictionary. You can easily call pd.DataFrame on the resulting dictionary and manipulate / concatenate dataframes until you have your desired format. Then, use the .to_latex functionality of pd.DataFrames.

Upvotes: 1

Related Questions