交叉驗證代碼(matlab code of cross validation)

來源:互聯網
上載者:User

%說明:下面是我自己寫的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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.