Trining a neural network with leave one out crossval method

조회 수: 11 (최근 30일)
Basavraj Hadare
Basavraj Hadare 2020년 2월 22일
댓글: Juan Manuel Miguel 2020년 8월 6일
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
Juan Manuel Miguel 2020년 8월 6일
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에서 Model Building and Assessment에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by