scikit learn output metrics.classification_report into CSV/tab-delimited format

后端 未结 17 2177
青春惊慌失措
青春惊慌失措 2021-01-31 03:08

I\'m doing a multiclass text classification in Scikit-Learn. The dataset is being trained using the Multinomial Naive Bayes classifier having hundreds of labels. Here\'s an extr

17条回答
  •  走了就别回头了
    2021-01-31 04:05

    I also found some of the answers a bit verbose. Here is my three line solution, using precision_recall_fscore_support as others have suggested.

    import pandas as pd
    from sklearn.metrics import precision_recall_fscore_support
    
    report = pd.DataFrame(list(precision_recall_fscore_support(y_true, y_pred)),
                index=['Precision', 'Recall', 'F1-score', 'Support']).T
    
    # Now add the 'Avg/Total' row
    report.loc['Avg/Total', :] = precision_recall_fscore_support(y_true, y_test,
        average='weighted')
    report.loc['Avg/Total', 'Support'] = report['Support'].sum()
    

提交回复
热议问题