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
It's obviously a better idea to just output the classification report as dict:
sklearn.metrics.classification_report(y_true, y_pred, output_dict=True)
But here's a function I made to convert all classes (only classes) results to a pandas dataframe.
def report_to_df(report):
report = [x.split(' ') for x in report.split('\n')]
header = ['Class Name']+[x for x in report[0] if x!='']
values = []
for row in report[1:-5]:
row = [value for value in row if value!='']
if row!=[]:
values.append(row)
df = pd.DataFrame(data = values, columns = header)
return df
Hope this works fine for you.