Matlab: Creating folds

2 views
Skip to first unread message

Per Berglund

unread,
Jan 25, 2012, 12:18:34 PM1/25/12
to ml_chalmers
Hi,

I'm new to Matlab and i'm having some trouble with creating the folds
for the cross-validations. I use the function 'crossvalind('Kfold',
sampleSize, 10)' to generate indicies. Then I put each sample in x
into matrices 'test' or 'train' depending on the value in the array of
indicies. The problem i'm having is that its extremely slow to do
this. The only hint that matlab has given me to increase the
performance is to pre-allocate memory for the matrices 'test' and
'train', but when I do this (using 'zeros(sampleSize, dataDim)') it
takes even longer time somehow.

Could anyone just give me some hint of a faster way to do this?

/Per

Vinay Jethava

unread,
Jan 26, 2012, 6:44:46 AM1/26/12
to ml_chalmers
Are you using for loops for putting data into test and train? Usually,
that might cause some problems - one solution is to use direct
indexing

test_data = data(test_idx, :);
train_data = data(train_idx, :);

Not sure what else might be causing problems. You can of course
generate the indices manually (using either rand() or even simpler by
just dividing the dataset into k equal parts).

Hope this helps,

Vinay
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages