forestTrain

PURPOSE ^

Train random forest classifier.

SYNOPSIS ^

function forest = forestTrain( data, hs, varargin )

DESCRIPTION ^

 Train random forest classifier.

 Dimensions:
  M - number trees
  F - number features
  N - number input vectors
  H - number classes

 USAGE
  forest = forestTrain( data, hs, [varargin] )

 INPUTS
  data     - [NxF] N length F feature vectors
  hs       - [Nx1] target output hs in [1,H]
  varargin - additional params (struct or name/value pairs)
   .M        - [1] number of trees to train
   .N1       - [5*N/M] number of data points for training each tree
   .F1       - [sqrt(F)] number features to sample for each node split
   .minCount - [1] minimum number of data points to allow split
   .maxDepth - [64] maximum depth of tree
   .dWts     - [] weights used for sampling and weighing each data point
   .fWts     - [] weights used for sampling features

 OUTPUTS
  forest   - learned forest model struct array w the following fields
   .fids     - [Mx1] feature ids for each node
   .thrs     - [Mx1] threshold corresponding to each fid
   .child    - [Mx1] index of child for each node
   .distr    - [MxH] prob distribution at each node
   .count    - [Mx1] number of data points at each node
   .depth    - [Mx1] depth of each node

 EXAMPLE
  N=10000; H=5; d=2; [xs0,hs0,xs1,hs1]=demoGenData(N,N,H,d,1,1);
  xs0=single(xs0); xs1=single(xs1);
  pTrain={'maxDepth',50,'F1',2,'M',150};
  tic, forest=forestTrain(xs0,hs0,pTrain{:}); toc
  hsPr0 = forestApply(xs0,forest);
  hsPr1 = forestApply(xs1,forest);
  e0=mean(hsPr0~=hs0); e1=mean(hsPr1~=hs1);
  fprintf('errors trn=%f tst=%f\n',e0,e1); figure(1);
  subplot(2,2,1); visualizeData(xs0,2,hs0);
  subplot(2,2,2); visualizeData(xs0,2,hsPr0);
  subplot(2,2,3); visualizeData(xs1,2,hs1);
  subplot(2,2,4); visualizeData(xs1,2,hsPr1);

 See also forestApply, fernsClfTrain

 Piotr's Image&Video Toolbox      Version 3.01
 Copyright 2012 Piotr Dollar.  [pdollar-at-caltech.edu]
 Please email me if you find bugs, or have suggestions or questions!
 Licensed under the Simplified BSD License [see external/bsd.txt]

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:
Generated by m2html © 2003