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

后端 未结 17 2175
青春惊慌失措
青春惊慌失措 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:13

    As of scikit-learn v0.20, the easiest way to convert a classification report to a pandas Dataframe is by simply having the report returned as a dict:

    report = classification_report(y_test, y_pred, output_dict=True)
    

    and then construct a Dataframe and transpose it:

    df = pandas.DataFrame(report).transpose()
    

    From here on, you are free to use the standard pandas methods to generate your desired output formats (CSV, HTML, LaTeX, ...).

    See also the documentation at https://scikit-learn.org/0.20/modules/generated/sklearn.metrics.classification_report.html

提交回复
热议问题