Using 5-fold cross validation with neural networks

7 views (last 30 days)
I am trying to use k-fold with my neural networks to compare them with their 3 way split equivalents. I have a 150x4 dataset and since it is a very small amount I am trying to see whether 5-fold would allow the ANN to give better results since if I understood correctly Matlab will then pass 2 training sets 2 testing and a validation containing the respective number of rows after sorting the data randomly.
I have been going through some code examples however every time I try and implement a different example (from matlab or other websites) I either get an error using horzcat "Dimensions of matrices being concatenated are not consistent." or it doesn't work, which isn't making any sense since all 4 inputs and the output have 150x1 structure. I have tried applying k-fold to the individual columns (imported as a numeric matrix) and also as a collective matrix however all I get in the workspace are a testIdxs, a trainIdxs a and a k and an "Index exceeds matrix dimensions" in the command window
Can anyone explain how this needs to be done or share a link where k-fold is done on a dataset and then passed to a neural network for training?

Accepted Answer

Greg Heath
Greg Heath on 30 Apr 2015
I just wrote a tutorial in the NEWSGROUP
Hope this helps.
Thank you for formally accepting my answer
Greg

More Answers (1)

Greg Heath
Greg Heath on 27 Apr 2015
You probably just need to transpose your input and target matrices. However, to check previous posts consider
ANSWERS Hits
greg neural crossvalidation 36
greg neural cross-validation 61
greg neural cross validation 67
NEWSGROUP Hits
greg neural crossvalidation 32
greg neural cross-validation 55
greg neural cross validation 72
Additional references can be obtained by removing one or both of the leading search words
Hope this helps.
Greg
  2 Comments
Anthony Scicluna
Anthony Scicluna on 4 May 2015
Edited: Walter Roberson on 21 Jun 2016
Thanks for the replies, I transposed the data and tried the following code:
k = 5;
cv = cvpartition(length(Temperature),'kfold',k);
for i=1:k
trainIdxs{i} = find(training(cv,i));
testIdxs{i} = find(test(cv,i));
trainMatrix{i} = [Temperature(trainIdxs{i}) HeartRate(trainIdxs{i}) Gender(trainIdxs{i}) Age(trainIdxs{i}) targets(trainIdxs{i})];
validMatrix{i} = [Temperature(testIdxs{i}) HeartRate(testIdxs{i}) Gender(testIdxs{i}) Age(testIdxs{i}) targets(testIdxs{i})];
end
However I'm not sure if it has worked properly and how I would pass the information to the neural network.
the trainMatrix variable in the workspace is 1x5 cell comprising 1x600 and the validMatrix variable is also a 1x5 cell and comprises 1x150. As I said before though I think it isn't working properly since when I view the data all the five rows (four inputs and target) are placed in the same row.

Sign in to comment.

Categories

Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!