교차 인증 코드 (matlab code of cross validation)

% 설명: 다음은 제 가 직접 쓴 matlab 코드 입 니 다. 사실 matlab 는 자체 적 으로 가지 고 있 는 교차 검증 코드 crossvalind 가 있 습 니 다. Chunhou Zheng 사형 의 Metasample Based Sparse Representation for Tumor 가 제공 하 는 코드 를 보십시오.
% 설명: LibSVM 은 이 걸 사용 할 필요 가 없습니다. '- v' 가 실현 되 기 때 문 입 니 다.http://www.cppblog.com/guijie/archive/2013/09/05/169034.html
% 설명: Maingene10FOLD_1. m 있 습 니 다. 용법 이 매우 간단 합 니 다. 크로스 밸 린 드 를 사용 하 는 것 이 좋 습 니 다. 제 프로그램 은 각종 견본 수가 다 를 때 고려 하지 않 았 을 수도 있 습 니 다.구체 적 인 사용 방법: 내 컴퓨터 참조: cite NIPS 2010 \ DLSR \ 코드 \ LSR \ \ TestUministLSRCross Validation. m,
이렇게 쓰 는 게 맞 아. 다 시 는 있 지 마. "
"crossvalind 는 어떻게 사용 합 니까?"
이 위 에 시간 낭비 야.
아래 의 예 는 보지 않 아 도 된다.
crossvalind 프로그램 에서 가 져 온 예% Create a 10 - fold cross - validation to compute classification error. load fisheriris% 이 데 이 터 는 150 개의 견본 indices = crossvalind ('Kfold', species, 10) 가 있 습 니 다.%species 는 견본 의 표지 이 고 indices 는 견본 수 와 같은 벡터 이 며 안의 요 소 는 1 에서 10cp = classperf (species) 이다.Evaluate performance of classifier
for i = 1:10     
test = (indices == i);
train = ~test;
class = classify(meas(test,:),meas(train,:),species(train,:));
classperf(cp,class,test)
end
size(test)
size(train)
size(meas(test,:),1)
size(meas(train,:),1)
cp.ErrorRate
% 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:
%
% If you used my matlab code, we appreciate it very much if you can cite our following papers:
% Jie Gui et al., "Group sparse multiview patch alignment framework with view consistency for image classification", IEEE Transactions on Image Processing (Accepted)
% Jie Gui et al., "How to estimate the regularization parameter for spectral regression
% discriminant analysis and its kernel version?", IEEE Transactions on Circuits and 
% Systems for Video Technology, vol. 24, no. 2, pp. 211-223, 2014
% Jie Gui, Zhenan Sun, Wei Jia, Rongxiang Hu, Yingke Lei and Shuiwang Ji, "Discriminant
% Sparse Neighborhood Preserving Embedding for Face Recognition", Pattern Recognition, 
% vol. 45, no.8, pp. 2884–2893, 2012
% Jie Gui, Wei Jia, Ling Zhu, Shuling Wang and Deshuang Huang, 
% "Locality Preserving Discriminant Projections for Face and Palmprint Recognition," 
% Neurocomputing, vol. 73, no.13-15, pp. 2696-2707, 2010
% Jie Gui et al., "Semi-supervised learning with local and global consistency", 
% International Journal of Computer Mathematics (Accepted)
% Jie Gui, Shu-Lin Wang, and Ying-ke Lei, "Multi-step Dimensionality Reduction and 
% Semi-Supervised Graph-Based Tumor Classification Using Gene Expression Data," 
% Artificial Intelligence in Medicine, vol. 50, no.3, pp. 181-191, 2010
% 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

좋은 웹페이지 즐겨찾기