-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcopulaCrossValidation.m
More file actions
23 lines (18 loc) · 987 Bytes
/
copulaCrossValidation.m
File metadata and controls
23 lines (18 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function [ confusionMatrix ] = copulaCrossValidation( family, method, X, Y, k )
%COPULACROSSVAL Given a copula family, fitting method and an input sample
%runs k-fold cross-validation of the input data using classifier based on
%copulas and returns a confusion matrix for the classification.
dbg('copula.crossval', 2, 'Cross validation for family %s.\n', family);
% Run stratified k-fold cross-validation
fun = @(X, Y, TX, TY) classifyfun(family, method, X, Y, TX, TY);
results = crossval(fun, X, Y, 'kfold', k, 'stratify', Y);
% Transform results of cross-validation to single confusion matrix
c = numel(unique(Y));
confusionMatrix = reshape(sum(results), c, c);
end
function [ confusionMatrix ] = classifyfun(family, method, X, Y, TX, TY)
%CLASSIFYFUN Wrapper over classifier based on copulas (copulacls) for
%MATLAB's crossval method.
TYhat = copulaClassification(family, method, TX, X, Y);
confusionMatrix = confusionmat(TY, TYhat, 'order', unique(Y));
end