简体   繁体   中英

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. Fasttext gives only the output in fig2, so I wonder is there any easy way to get these labels and print classification report?

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

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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