I am trying to use the mean average accuracy as the metric, instead of accuracy. And I find there is a metric name ‘Precision’ seems doing the work. But when I use
metric=Precision in create_cnn,
it has the following error,
AttributeError: ‘Precision’ object has no attribute ‘detach’
What else should I do if I wish to use Precision?
I also try to add a mean_acc below, but the value is always nan. Do not know the reason yet.
def mean_accuracy(input:Tensor, targs:Tensor)->Rank0Tensor:
“Compute mean accuracy with targs when input is bs * n_classes.”
preds = input.argmax(-1).view(-1).cpu()
targs = targs.cpu()
You have to instantiate a class to get an object of that class, so here you need to pass Precision() (or as @AlisonDavey pointed out Precision(average='macro') to get the average you want).
Precision is a little complicated because you shouldn’t simply take the average over the batches. Fortunately, we have Precision() so don’t need to rewrite this.
Thank you so much @AlisonDavey. It is much clearer now. By the way, there is another metric class named ‘KappaScore’ , which seem doing similar like ‘Precision’. What are the pros/cons of ‘KappaScore’ compared with Precision?