Using Cross Validation for regression

5 views (last 30 days)
Can Lo
Can Lo on 13 Apr 2016
Commented: Can Lo on 14 Apr 2016
hello, i have a dataset which has inputs 5x100 real numbers called "input" and i have 1x100 real numbers target called"output", and i need to use 10 fold crossvalidation but i m new in matlab and my dataset is not classification , it is for regression, and i cant use command " crossvalind=('Kfold',groups,k) because i dont have any groups,what should i do ? i have 100 samples and i have to use 90 of them for train,other 10 for test and i have to do this for 10 time for all datas and all datas must be used.

Answers (1)

Ahmet Cecen
Ahmet Cecen on 14 Apr 2016
I would do something along the lines of:
Randomize = randperm(length(input));
inputRandom = input(Randomize);
outputRandom = output(Randomize);
for i=1:10
Xtest = inputRandom(((i-1)*10+1):i*10);
ytest = outputRandom(((i-1)*10+1):i*10);
Xtrain = inputRandom; Xtrain(((i-1)*10+1):i*10) = [];
ytrain = outputRandom; ytrain(((i-1)*10+1):i*10) = [];
[b,bint,r,rint,stats] = regress(ytrain,Xtrain);
YCrossValidated = Xtest*b;
crossValidateResiduals = YCrossValidated - Ytest;
% Calculate any fit statistics HERE and STORE anything you need.
end
  1 Comment
Can Lo
Can Lo on 14 Apr 2016
thank you so much for your help sir, i really appreciate it ! i didnt use this exactly but it gave me the idea :) but how can i use 10 fold crossvalidation for my situation ? or cross validation is only used for classification problems ?

Sign in to comment.

Categories

Find more on Statistics and Machine Learning Toolbox 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!