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
Just import pandas as pd
and make sure that you set the output_dict
parameter which by default is False
to True
when computing the classification_report
. This will result in an classification_report dictionary
which you can then pass to a pandas DataFrame
method. You may want to transpose
the resulting DataFrame
to fit the fit the output format that you want. The resulting DataFrame
may then be written to a csv
file as you wish.
clsf_report = pd.DataFrame(classification_report(y_true = your_y_true, y_pred = your_y_preds5, output_dict=True)).transpose()
clsf_report.to_csv('Your Classification Report Name.csv', index= True)
I hope this helps.