I'm using FastText and to evaluate the results of my classification (binary classification) and I would like to print the Clasisfication Score. Actually as output I'm having the Precision and Recall. Here my code:
train_file = 'train.csv'
test_file = 'test.csv'
print("training model...")
model = fasttext.train_supervised(input=train_file,
lr=1.0, epoch=100,
wordNgrams=2,
bucket=200000,
dim=50,
loss='hs')
def print_results(N, p, r):
print("N\t" + str(N))
print("P@{}\t{:.3f}".format(1, p))
print("R@{}\t{:.3f}".format(1, r))
result = model.test(test_file)
print_results(*result)
I was reading the documentation here and checking also some tutorials but I did not understand yet how to define the classification report. I think that a loop through the test_file
should be defined but in this case, which parameters I have to use in?
Desired output:
precision recall f1-score support
0 0.832 0.824 0.828 9093
1 0.861 0.867 0.864 11399
accuracy 0.848 20492
macro avg 0.846 0.846 0.846 20492
weighted avg 0.848 0.848 0.848 20492
Thanks,
Why don't you deal with metrics
library from scikit-learn
, maybe is a better choice.
F1 Code example:
f1_score('your_test', 'your_predict', average='macro')
In your case I think should be:
f1_score(test_file, result, average='macro')
Now you can make a table with all scores you want.
You just have to import them, for example:
from sklearn.metrics import f1_score, precision_score, recall_score, accuracy_score
And you can even add more things, for the example 'confusion matrix':
from sklearn.metrics import confusion_matrix
Code example:
confusion_matrix(test_file, result)
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.