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

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

    def to_table(report):
        report = report.splitlines()
        res = []
        res.append(['']+report[0].split())
        for row in report[2:-2]:
           res.append(row.split())
        lr = report[-1].split()
        res.append([' '.join(lr[:3])]+lr[3:])
        return np.array(res)
    

    returns a numpy array which can be turned to pandas dataframe or just be saved as csv file.

提交回复
热议问题