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

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

    This is my code for 2 classes(pos,neg) classification

    report = metrics.precision_recall_fscore_support(true_labels,predicted_labels,labels=classes)
            rowDicionary["precision_pos"] = report[0][0]
            rowDicionary["recall_pos"] = report[1][0]
            rowDicionary["f1-score_pos"] = report[2][0]
            rowDicionary["support_pos"] = report[3][0]
            rowDicionary["precision_neg"] = report[0][1]
            rowDicionary["recall_neg"] = report[1][1]
            rowDicionary["f1-score_neg"] = report[2][1]
            rowDicionary["support_neg"] = report[3][1]
            writer = csv.DictWriter(file, fieldnames=fieldnames)
            writer.writerow(rowDicionary)
    

提交回复
热议问题