Trining a neural network with leave one out crossval method

8 visualizzazioni (ultimi 30 giorni)
Hello there,
I am new at neural networks and matlab. I am tring to train a network but i have less data available with me, so I am trying with leave-one-out method. But i am unable to find a way. Is there any direct method of training with leave-one-out training in matlab environment or what way should i follow. Thank you.

Risposte (1)

Jalaj Gambhir
Jalaj Gambhir il 25 Feb 2020
Hi,
'Leave-one-out' is a cross validation method. You can generate cross validation indices for train and test set using cvpartition, specifying 'LeaveOut' parameter. This would generate partitions of n-1 training samples and 1 test sample.
>> load fisheriris;
>> x = meas;
>> y = species;
>> c = cvpartition(y,'LeaveOut')
This generates
c =
Leave-one-out cross validation partition
NumObservations: 150
NumTestSets: 150
TrainSize: 149 149 149 149 149 149 149 149 149 149 ...
TestSize: 1 1 1 1 1 1 1 1 1 1 ...
For each partition 'i', you can generate train and test samples as:
>> x_train = x(training(c,i),:);
>> y_train = y(training(c,i),:); % You might want to convert this to one-hot-encoded vectors
>> x_test = x(test(c,i),:);
>> y_test = y(test(c,2),:); % You might want to convert this to one-hot-encoded vectors
Then you can use this train and test data to train a neural network using tools like nnstart which are perfect for beginners. Look at an example here.
  1 Commento
Juan Manuel Miguel
Juan Manuel Miguel il 6 Ago 2020
Thank you Jalaj, it was very useful for me. I think you meant y_test = y(test(c,i),:); instead of y_test = y(test(c,2),:); didn't you?
Thank you

Accedi per commentare.

Categorie

Scopri di più su Deep Learning Toolbox in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by