Hey,
I’m using fastai to for a text classification problem. I have 45 different classes and at first look, fastai seems to be quite good after only 10 epochs achieving 84.99% accuracy.
epoch | train_loss | valid_loss | accuracy | precision | recall | time |
---|---|---|---|---|---|---|
0 | 0.608150 | 0.563250 | 0.836928 | nan | 0.836928 | 00:51 |
1 | 0.537336 | 0.555584 | 0.842027 | nan | 0.842027 | 00:56 |
2 | 0.494744 | 0.542400 | 0.848295 | nan | 0.848295 | 00:53 |
3 | 0.438984 | 0.545793 | 0.849888 | nan | 0.849888 | 00:55 |
First question, I’m using the Precision() metric offered by the metrics module. Tried both micro and macro and both give nan. Any ideas why that is? It’s not too important because for the purpose of this specific task (single label, no threshold), the precision will always be the same as accuracy, but I’m curious why this happens.
My bigger question is that if I run the following :
preds, y = learn.get_preds(ds_type=DatasetType.Valid, ordered=True)
y = torch.argmax(preds, dim=1)
and I then use scikitlearn to get the predictions with:
accuracy_score(np.array(y), valid[['categoryid']].values.flatten())
I get an accuracy of 0.54127 which is very far from the fastai one.
This problem has been bugging me for a while now and I can’t seem to find an explanation.
Morever, if I analyse the results given by fastai further, I get results that should match the 84.9% accuracy.
interp = TextClassificationInterpretation.from_learner(learn)
x = interp.most_confused()
s = 0
for i in x:
s += i[2]
print("Total number of wrong classifications:", s)
acc = 1 - 1413/len(valid)
print("Accuracy based on this:", acc)
Prints out:
Total number of wrong classifications: 1413
Accuracy based on this: 0.8498884521406566
Any insights would be appreciated!