简体   繁体   English

在 FastText 文本分类输出中打印分类报告

[英]Printing Classification Report in FastText Text Classification output

I want to print classification report and F1 score by using sklearn.metrics library but it needs the predicted labels.我想使用 sklearn.metrics 库打印分类报告和 F1 分数,但它需要预测的标签。 Fasttext gives only the output in fig2, so I wonder is there any easy way to get these labels and print classification report? Fasttext 仅给出 fig2 中的输出,所以我想知道有没有简单的方法来获取这些标签并打印分类报告?

def train():
    self.model = fasttext.train_supervised(input='train.txt', wordNgrams=2, lr=1.0, epoch=10,
                                           bucket=200000, dim=300, loss='hs', pretrainedVectors='../cc.tr.300.vec')
    predict = self.model.test('test.txt')

    print(predict)

Fasttext Train and Test Fasttext 训练和测试

Output Format输出格式

Instead of giving test.txt to the model.test, get all sentences one by one in a loop and predict each one and insert to the list.不是将 test.txt 提供给 model.test,而是在循环中一一获取所有句子并预测每个句子并插入到列表中。

self.pred = []
for sentence in self.sentences:
    self.pred.append(self.model.predict(sentence)[0][0].replace('__label__',''))

classification_report(y_true=self.real_tags, y_pred=self.pred, zero_division=0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM