ITKeyword,专注技术干货聚合推荐

注册 | 登录

how to create leave one out cross validation in matlab?

itPublisher 分享于

2020腾讯云双十一活动,全年最低!!!(领取3500元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1073

【阿里云】双十一活动,全年抄底价,限时3天!(老用户也有),
入口地址https://www.aliyun.com/1111/home

推荐:交叉验证代码(matlab code of cross validation)

%说明:下面是我自己写的matlab代码,其实matlab有自带的交叉验证代码crossvalind, 见Chunhou Zheng师兄的Metasample Based Sparse Representation for Tumor提

This question already has an answer here:

I am still confused with my code. I tried to implement leave one out cross validation in matlab for classification. so in here . I take out one data from training become testing data. I already make a code in matlab. but Iam not sure it's correct because the result is wrong. can someone help me to correct it?? thank you very much.

this is my code :

clc    
[C,F] = train('D:\fp\',...
    'D:\tp\');


for i=size(F,1)
testVal = i;      
trainingSet = setdiff(1:numel(C), testVal); % use the rest for training

Ctrain = C(trainingSet,:);
Ftrain = F(trainingSet,:);
test= F(testVal,:);
svmStruct = svmtrain(Ftrain,Ctrain,'showplot',true,'Kernel_Function','rbf');
result_class(i)= svmclassify(svmStruct,test,'showplot',true);
ax(i)=result_class;
i=i+1;
end
matlab cross-validation
|
  this question
edited Mar 16 '13 at 16:58 Parag S. Chandakkar 5,583 1 16 46 asked Mar 16 '13 at 15:55 user2157806 139 2 6 15

marked as duplicate by Shai, Charles Menguy, Stony, nsgulliver, Mia Clarke Mar 17 '13 at 11:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



 | 

1 Answers
1

This is what I usually use to create leave one out cross-validation.

[Train, Test] = crossvalind('LeaveMOut', N, M)

Here, N will be the number of total samples you have in your training+testing set. M=1 in your case. You can put this in a for loop.

Also, you can use random number generation to perform leave-one out crossvalidation without using predefined function.


|
  this answer
answered Mar 16 '13 at 16:57 Parag S. Chandakkar 5,583 1 16 46

 | 

Not the answer you're looking for? Browse other questions tagged matlab cross-validation or ask your own question.


相关阅读排行


相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱

如果您没有收到激活邮件,请注意检查垃圾箱。