Collaborative Representation Classifier with Training and Validation Data

6 ビュー (過去 30 日間)
Shay Marceau
Shay Marceau 2020 年 11 月 16 日
回答済み: Shashank Gupta 2020 年 11 月 19 日
With CRC I can simplify the equation to
I have training data, validation data and test data. How do I go about implementing this. This is what I have done so far. I just need to implement CRC but I am losts as to how to do it with training data and validation data.
load AR_DAT.mat
figure; imagesc(reshape(NewTrain_DAT(:,1),60,43)); colormap(gray)
NewTrain_DAT = double(NewTrain_DAT);
NewTest_DAT = double(NewTest_DAT);
% cross-validation
nfold = 5; % k-fold cross-validation
C = length(unique(trainlabels));
%% Use leave-one-out to tune regularization parameter
lambda = [0.005, 0.05, 0.01, 0.1, 0.5, 1, 2, 5]; % please set/tune the range yourself
Acc = zeros(1,length(lambda)); % record the accuracy for each lambda
nfoldAcc = zeros(1,nfold);
for k = 1:length(Acc)
for i = 1:nfold
XTrain = []; % new training set, for the next fold this will be cleared and construct a new one
XVal = []; % valiation set
LTrain = []; % lables
LVal = [];
for j = 1:C
data = NewTrain_DAT(:, trainlabels==j); % class j samples
XVal = [XVal, data(:,i)]; % leave the ith sample out for validation
LVal = [LVal, j];
data(:,i) = []; % the rest for training
XTrain = [XTrain, data];
LTrain = [LTrain, j*ones(1,size(data,2))];
end
%nfoldAcc(i) = CRC(XTrain, XVal, LTrain, LVal, lambda(k)); %need to create this function
end
Acc(k) = mean(nfoldAcc); % the average accuracy for lambda(k)
end
I do not want the answer. I just want some assistance on how to go from here. I am mostly confused about the training data and validation data.

回答 (1 件)

Shashank Gupta
Shashank Gupta 2020 年 11 月 19 日
Hey Shay,
You can probably first start with attacking a simpler problem by just taking training set and test set and omitting validation data for now, things become slightly easy to understand when there are less complication from validation sets. The equation of CRC have "X" and "y", first you need to understand, here "X" will be Xtrain(taking notation from your code) and "y" will be "Ltest", use the equation and find out "P" (rho cap) and use this for further processing. So in simple terms the equation will look something like,
% Projection matrix
H = inv((Xtrain' * Xtrain + lambda * eye(size(Xtrain,2)))) * Xtrain';
% finding P
rho_hat = H * Ltest;
I hope this clear some confusion about the data classificaiton.
Cheers

カテゴリ

Help Center および File ExchangeSupport Vector Machine Regression についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by