K-fold Cross Validation Performance

조회 수: 5 (최근 30일)
Ahmad
Ahmad 2014년 12월 3일
답변: Greg Heath 2014년 12월 12일
Hello All, I am a newbie in Validating models, I am currently trying to make use of the MATLAB K-fold validation to assess the performance of my polynomial model that predicts house prices. I have 243 samples, i divided them into 10 groups, i then used 'for loop' to test 9 groups against 1 group (repeated X 10) My problem is storing the error rate (performance) for the 10 times i am making the prediction. How do i do that please? I tried making use of 'classperf' but i am getting the following error, Please see my code below;
Data set sample:
DateX: 10,20,30,40 ... PriceY: 200,250,300,400 ...
--------Code (MATLAB)-------
K = 10;
cvFolds = crossvalind('Kfold',DateX,K); %10-folds
cp = classperf(DateX); %To store (performance)
for i = 1:K
testIDx = (cvFolds == i);
trainIDx = ~testIDx;
model1 = polyfit(DateX(trainIDx),PriceY(trainIDx),2);
prediction1=model1(1)*DateX(testIDx).^2+model1(2)*DateX(testIDx)+model1(3);
cp = classperf(cp,prediction1,testIDx);
end
My Error Message;
Error using classperf (line 230) When the class labels of the CP object are numeric, the output of the classifier must be all non-negative integers or NaN's.
Is there any suggestions please on how i can store the performance of my model AND i would apperciate examples of other methods In MATLAB that i can apply to make predictions and validate performance (Neural networks, Classification e.t.c.)?? THANK YOU!

채택된 답변

Greg Heath
Greg Heath 2014년 12월 12일
I do not have the functions crossvalind and classperf.
Although I do have crossval and cvpartition, I favor my own code used in the following NEWSGROUP posts:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326830#898048
http://www.mathworks.com/matlabcentral/newsreader/view_thread/331830#911882
Hope this helps.
Thank you for formally accepting my answer
Greg

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Direct Forecasting에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by