Skip to content

Commit

Permalink
Hello everyone ! I add two new files to my repository: 1) CohenKappa.…
Browse files Browse the repository at this point in the history
…m for evaluating the classification and 2) CV_MultiSVDD for the cross validation.
  • Loading branch information
AlbiCarle authored Jan 14, 2023
1 parent 559e042 commit 021ceb3
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
70 changes: 70 additions & 0 deletions CV_MultiSVDD.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
function [param_star, C_star, err_matrix] = ...
CV_MultiSVDD(X, Y, kernel,nrip, KerPar,Cpar)

% Cross Validation function for MC-SVDD

Num_class = length(unique(Y));
minimum_abs = 100;

for rip = 1:nrip

disp(['--->', num2str(rip)])

cv = cvpartition(Y,'HoldOut',0.3, 'Stratify',true);
idx = cv.test;

Xtr = X(~idx,:); Ytr = Y(~idx,:);
Xvl = X(idx,:); Yvl = Y(idx,:);

err_matrix = zeros(size(KerPar,2),size(Cpar,1));

i = 0;

for param = KerPar

i = i + 1;

j = 0;

for C = Cpar'

C = C';

j = j + 1;

[x_class, Ytr_class, Rsquared_class, a_class, SV_class, YSV_class]=...
NC_SVDD_TRAINING(Xtr, Ytr, Num_class, kernel, param, C);

y_predict = ...
NC_SVDD_TEST(Xtr, Ytr_class, Num_class, x_class, Xvl, kernel, param, Rsquared_class);

n = size(Yvl,1);

err = (n-sum(Yvl == y_predict))/n;

err_matrix(i,j) = err;

end
end

minimum = min(min(err_matrix));

if minimum < minimum_abs

[x,y]=find(err_matrix==minimum);

param_star = KerPar(x(1));

C_star = Cpar(y(1),:);

minimum_abs = minimum;

disp(minimum_abs)

end

end

disp('Done')

end
26 changes: 26 additions & 0 deletions CohenKappa.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function K = CohenKappa(X, Y, y_pred, Num_class)

% Function that computes the CohenKappa index for multiclassification
% algorithms

CM = ConfusionMatrix(Y, y_pred, Num_class);

c = sum(diag(CM));

s = size(X,1);

p = []; t = [];

for k =1:Num_class

p_k = sum(CM(:,k));

p = [p,p_k];

t_k = sum(CM(k,:));

t = [t,t_k];

end

K = ((c*s) - sum(p.*t))/(s^2 - sum(p.*t));

0 comments on commit 021ceb3

Please sign in to comment.