Home > @DecisionTreeClassifier > learn.m

learn

PURPOSE ^

function [cl, err] = learn(cl, trnExamples, targetOuts)

SYNOPSIS ^

function [cl, clErr] = learn(cl, trnExamples, targetOuts, wts)

DESCRIPTION ^

 function [cl, err] = learn(cl, trnExamples, targetOuts)
   learning function for the Decision Tree classifier

   Inputs:
       trainingExamples: examples for training the classifier.
       targetOuts: target classification outputs. its size must be the
           same as the number of examples.
       wts: weights of training examples (used to compute the weighted
           classification error)
   Outputs:
       cl : trained SVMClassifier
       clErr: classification error of the trained classifier

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [cl, clErr] = learn(cl, trnExamples, targetOuts, wts)
0002 % function [cl, err] = learn(cl, trnExamples, targetOuts)
0003 %   learning function for the Decision Tree classifier
0004 %
0005 %   Inputs:
0006 %       trainingExamples: examples for training the classifier.
0007 %       targetOuts: target classification outputs. its size must be the
0008 %           same as the number of examples.
0009 %       wts: weights of training examples (used to compute the weighted
0010 %           classification error)
0011 %   Outputs:
0012 %       cl : trained SVMClassifier
0013 %       clErr: classification error of the trained classifier
0014 
0015 %% Deal with Cell Array Input
0016 if iscell(trnExamples),
0017     trnExamples = cell2mat(trnExamples);
0018 end
0019 
0020 cl.trainedCl = ClassificationTree.fit(trnExamples, targetOuts, 'weights', wts);
0021 cl.isTrained = true;
0022 
0023 %% Compute Classification Error
0024 if nargout > 1
0025     outs = cl.trainedCl.predict(trnExamples);
0026 
0027     if nargin < 4,
0028         clErr = sum(outs ~= targetOuts) / nExamples;
0029     else
0030         clErr = (outs ~= targetOuts)' * wts;
0031     end
0032 
0033     if isnan(clErr),
0034         error('error is nan');
0035     end
0036 end

Generated on Sun 29-Sep-2013 01:25:24 by m2html © 2005