⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cv_cpann.m

📁 this file is leverage algorithm written in matlab as m-file and tested in matlab.so anyone can ue th
💻 M
字号:
function cv = cv_cpann(X,class,settings,cv_groups)

% cross validation for counterpropagation artificial neural networks (CPANNs)
% cross validation is perfomred with venetian blinds, i.e. with 3 cv groups
% the split of the first group will be [1,0,0,1,0,0,....,1,0,0] and so on.
% 
% cv = cv_cpann(X,class,settings,cv_groups);
%
% input:
%   X           data [n x p], n samples, p variables
%   class       class vector [n x 1], numerical labels
%   settings    setting structure
%   cv_groups   number of cross-validation groups
% 
% output:
%   cv is a structure, with the following fields
%   cv.pred_class           calculated class in cross validation [n x 1]
%   cv.class_param          structure containing confusion matrix, 
%                           error rate, non-error rate, specificity, 
%                           precision and sensitivity
% 
% important:
% - to define the settings structure type 'help som_settings'
% - data are always range scaled (inbetween 0 and 1) in order to
%   make them comparable with net weights
% 
% see the HTML HELP files (help.htm) for details and examples
%
% version 1.0 - may 2007
% Davide Ballabio
% Milano Chemometrics and QSAR Research Group
% www.disat.unimib.it/chm

% checks
errortype = cpann_check(X,class,settings,[],'cv');  
if ~strcmp(errortype,'none')
    disp(errortype)
    return
end

nobj = size(X,1);
pred_cv = zeros(nobj,1);
for i=1:cv_groups
    disp(['cross validating group ' num2str(i)])
    % prepares objects
    in = ones(nobj,1);
    out = [i:cv_groups:nobj];
    in(out) = 0;
    X_training = X(find(in==1),:);
    X_test = X(find(in==0),:);
    class_training = class(find(in==1));
    class_test = class(find(in==0));
    % calculates model
    model = model_cpann(X_training,class_training,settings);
    pred = pred_cpann(X_test,model);
    pred_cv(find(in==0)) = pred.class;
end

class_param = cpann_class_param(pred_cv,class);

% saves results
cv.type = 'cpann';
cv.pred_class = pred_cv;
cv.class_param = class_param;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -