Trining a neural network with leave one out crossval method

6 次查看(过去 30 天)
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.

回答(1 个)

Jalaj Gambhir
Jalaj Gambhir 2020-2-25
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 个评论
Juan Manuel Miguel
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Deep Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by