Dear all,
I got the following error when using crossval.
Error using crossval>evalFun (line 488)The function '@(Xtr,Ytr,Xte)predict(fitlm(Xtr,Ytr(:,2)),Xte)' generated the following error:Index in position 2 exceeds array bounds (must not exceed 1).Error in crossval>getLossVal (line 525)funResult = evalFun(funorStr,arg(1:end-1));Error in crossval (line 424) [funResult,outarg] = getLossVal(i, nData, cvp, data, predfun);
This is my code. The X and Y are stored in the attached .mat file.
%% Cross validation
hpartition = cvpartition(81,'Holdout',0.2);idxTrain = training(hpartition);Xtr = X(idxTrain,:);Ytr = Y(idxTrain,:);idxNew = test(hpartition);Xte = X(idxNew,:);for i = 1:2 for j = 1:3 fcn{i,1} = @(Xtr, Ytr, Xte) predict(fitlm(Xtr,Ytr(:,i)), Xte); fcn{i,2} = @(Xtr, Ytr, Xte) predict(fitrsvm(Xtr,Ytr(:,i)), Xte); fcn{i,3} = @(Xtr, Ytr, Xte) predict(fitrgp(Xtr,Ytr(:,i)), Xte); mse(i,j) = crossval('mse', X, Y(:,i),'Predfun',fcn{i,j}, 'kfold',10); endend
Best Answer