CLOP中的Random Forest
CLOP中的Random Forest调用R来实现,比较稳定,同时基于Spider的框架,用起来也算方便
CLOP中大多数分类器适用于两类分类,处理多类的demo中都是OVA,OVO的例子
Random Forest本身对待多类和两类并无区别,不过在CLOP1.6中,RF的训练部分代码适用于多类,而分类部分的代码只能用于两类分类
CLOP/challenge_objects/pat/@rf/testing.m
switch algo.optimizer case 'R' preds=fevalR('RFtest', 'forest', forest, 'xtest', X_te); % warning, may have inverted the 2 classes. % case of 2 classes only %% 这里只处理了两类分类优质内容筛选与推荐>>
%% preds.resu 是一个numIns * numClass的矩阵,对应分类为不同类别的概率,根据这个矩阵可以求解多类的Y_resu outval=preds.resu(:,2)-preds.resu(:,1); Y_conf=abs(outval); Y_resu=sign(outval); zero_val=find(Y_resu==0); % remove ties Y_resu(zero_val)=algo.algorithm.default_output; case 'Weka' % ... case 'Merk' param = forest.param; warning off out = RFClass(param, X_te, Y_te, forest); warning on Y_resu=targets(out.ypredts); zero_val=find(Y_resu==0); % remove ties Y_resu(zero_val)=algo.algorithm.default_output; Y_conf=abs(log(out.countts(:,2)+1)-log(out.countts(:,1)+1)); zero_val=find(Y_conf==0); % remove ties Y_conf(zero_val)=eps; %Y_resu=out.countts(:,2)-out.countts(:,1); % we use the counts as class likelihoods % the discriminant value is log(p1/p2) end