matlab 交叉验证 代码,交叉验证代码(matlab code of cross validation) | 学步园

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

%说明:Main_gene10FOLD_1.m有,用法非常简单,和自己编写的实现的是同样的功能

% 10-fold cross validation

%This code is written by Gui Jie in the afternoon 2009/06/08.

%If you have find some bugs in the codes, feel free to contract me

% Reference:

%1. Algorithm 2 of "Shuiwang Ji and Jieping Ye. Generalized Linear Discriminant Analysis: A

%  Unified Framework and Efficient Model Selection. IEEE Transactions on Neural Networks.

%  Vol. 19, No. 10, pp. 1768-1782, 2008."

%2.Foot note 4 of "F.Wang,et al.,marginFace:A novel face recognition method by average neighborhood

%  margin maximization,Pattern Recognition (2009)"

v=10;% If v=4,it means 4-fold cross validation.

step=floor(size(fea_train,1)/v);

for j =1:v

if j~= v

startpoint=(j-1)*step+1;

endpoint=(j)*step;

else

startpoint=(j-1)*step+1;

endpoint=size(fea_train,1);

end

cv_p=startpoint:endpoint; %%%% test set position

%%%%%%%%%%%%%% test set

Test_data=fea_train(cv_p,:);

Test_lab=gnd_train(cv_p,:);  %%%%label

%%%%%%%%%%%%%% training data

Train_data=fea_train;

Train_data(cv_p,:)='';

Train_lab=gnd_train;

Train_lab(cv_p,:)='';

end

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值