Are the learner metrics calculated on training or validation set?


#1

On initialising the metrics for the learner object, what dataset (training or validation) are the values calculated on?

Basically what I’m asking is when I see these training statistics as below …

Epoch      trn_loss   val_loss   accuracy   precision  recall                    
    0      1.06871    3.607499  0.432395   0.113374   0.316821  
Epoch: 100%|██████████████████████████████████████| 1/1 [00:13<00:00, 13.81s/it]
Epoch:   0%|                                      | 0/1 [00:00<?, ?it/sepoch      
           trn_loss   val_loss   accuracy   precision  recall                    
    0      0.887629   1.399241  0.582809   0.22717    0.390596 

… are the accuracy, precision and recall on the validation set?

Secondly, whichever set it is on is there a feature to also evaluate these statistics on the other set?


(Martin) #2

I am unsure but you should be able to find out by inspecting and understanding the fit function.

The fit function is in fastai/model.py. Use ??fit

You can also change the code of fit or use callbacks to “evaluate these statistics on the other set”.


#3

I think the metrics are on validation set because print_stats is called with vals.

That is the first thing I tried but there’s a lot of clutter and a lot of unexplained usage. This library could really benefit from a good documentation.

Like what is all_val, what is the reason for assigning a default to it instead of adding it to the list of arguments? Why is there a validate and a validate_next?


(Martin) #4

It is pretty messy!

You can test your hypothesis that “the metrics are on validation set” by:

Make your validation set only one image (or whatever your data is like). Then look at the accuracy when training. If the hypothesis is correct you should only see either 100% accuracy or 0% (1. or 0.).

To change whether valid or train the statistics are evaluated on, I would rather implement my own fit function because fit really is messy. But if anyone can help you with that then that would work too.

In one of the lessons, I am sure we implemented our own fit function. Just copy that then edit it so it does what you want. I do realize this is a lot of work :slight_smile: so if anyone knows a better solution do tell @aayushy