Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
365 views
in Technique[技术] by (71.8m points)

libsvm - How to label the training projections obtained by PCA to use for training SVM for classification? MATLAB

I have a "training set" of images. I have formed the 'Eigenspace'. Now i need to label the projections to train the SVM. The projections of "face 1" to the Eigenspace has to be labelled +1 and the projections of all the other faces to the Eigenspace has to be labelled -1.

I don't know how to do this.Any suggestions would be really helpful!

I formed the eigenspace using the following :

    function [signals,V] = pca2(data)
    [M,N] = size(data); 
    data = reshape(data, M*N,1); % subtract off the mean for each dimension 
    mn = mean(data,2); 
    data = bsxfun(@minus, data, mean(data,1)); 
    % construct the matrix Y 
    Y = data'*data / (M*N-1); 
    [V D] = eigs(Y, 10); % reduce to 10 dimension 
    % project the original data 
    signals = data * V; 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
label = ones(N,1);% N samples in total, +1 represents face 1
for i=1:N 
    % For each face image, you run
    [signals,V] = pca2(data); % ith data
    if ....  % other faces than face 1
        label(i) = -1;
    end
    face(i,:) = reshape(signals,1,[]);
end
model = svmtrain(label,face);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...