Is it possible to implement cross-validation in fastai?

(guitar) #1

I tried to implement cross-validation in fastai, but I failed.

1 Like

(Esteban J Guillen) #2

I have used sklearn to help generate the folds, then train a fastai classifier on each train and validation dataset combination.


(guitar) #3

Can you tell me in more detail? I divided the data set into 5 folds to train, and when I did the second iteration, I got an error.


(Esteban J Guillen) #4

Here is how I iterate over my folds

I save off the results after each learner is trained

1 Like

(Fernando A.) #5

This my way to implement Stratified K Fold cross validation with and scikitlearn

I think that is ok and easy but I’m a newbie


How does get_transforms work?

have u ever raise an error : out of memory? thanks for advance!



I guess probably you can reduce the batch_size to avoid that error.

1 Like


I was just asking myself: which is the purpose of cross-validation in this situation? My guess: to get a better estimate of the accuracy of the model in the test_set?

Also what about early stopping if error starts increasing in the validation set, how can we do it?

1 Like


Regarding your second question you should probably have a look at the EarlyStoppingCallback in the docs.

1 Like

(Mohamed Aymane Ahajjam) #10

Is the y in df[‘y’] the tags/label column in the df?


(Zachary Mueller) #11

Yes, it is :slight_smile:

1 Like

(Mohamed Aymane Ahajjam) #12

Thank you muellerzr!