-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hello everyone ! I add two new files to my repository: 1) CohenKappa.…
…m for evaluating the classification and 2) CV_MultiSVDD for the cross validation.
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |