DataLab is a compact statistics package aiming at exploratory data analysis. Please visit the DataLab Web site for more information....


RPar

Declaration: TRndForest.RPar: double;
The property RPar controls the resampling factor of the random forest. Typical values are between 0.30 and 0.6. The valid range of RPar is between 0.05 and 0.7, setting RPar to values below or above the valid range will automatically restrict it to that range.

Hint: You can find the optimum resampling factor by performing an R-scan in the Random Forest Development Tool.

Sample
Program:
The following sample program shows how to scan the RPar property and display the OOB RMS error in a chart:

program RF_RScan;

const
  TRNDATA = 'boilpts_500.idt';   // training data
  PAGE = 1;          // default chart page
  SCANRVON = 0.02;   // range of RPar to be scanned
  SCANRBIS = 0.7;    // do not increase beyond 0.7
  SCANRRES = 0.02;   // resolution of R scan
  NREP = 5;          // number of repetitions
  NTREES = 75;       // number of trees
  NXVARS = 12;       // use the first 12 variables
  TARGETCOL = 13;    // column 13 is the y vector

var
  rep         : integer;
  RF          : TRndForest;
  errnum      : integer;
  repo        : TRFReport;
  FVers       : integer;
  i, obj      : integer;

begin
FuncMon (false);
LoadDlabFile (GetDLabDir(ddWork)+TRNDATA, FVers, true);

ChartBook.Reset;
ChartBook.TabCaption[PAGE] := 'Tab 1';
ChartBook.Configure
   (PAGE,               // page 1
    true, false, false, // only the chart is visible
    250, 250);          // default width & height
ChartBook.TabCaption[PAGE] := 'Cross Section';
ChartBook.Charts[PAGE].Clear;
ChartBook.Charts[PAGE].ScalePropsX[1].Caption := 'R';
ChartBook.Charts[PAGE].ScalePropsY[1].Caption := 'OOB RMSError';
ChartBook.Charts[PAGE].SetRange(1,0,0,0.8,50);
ChartBook.Charts[PAGE].DataColor := clBlue;
RF := TRndForest.Create(nil);

RF.NTrees := NTREES;
RF.ResizeTrnData (NXVARS, DStore.NrOfRows);
for i:=1 to NXVARS do
  RF.TrnDataX.CopyColumnFrom (DStore,i,i);         // X data block
for obj:=1 to DStore.NrOfRows do
  RF.TrnDataY[obj] := DStore.Elem[TARGETCOL,obj];  // Y data
RF.RPar := SCANRVON-SCANRRES;
while (RF.RPar < SCANRBIS) do
  begin
  RF.RPar := RF.RPar + SCANRRES;
  Application.ProcessMessages;
  ChartBook.Charts[PAGE].SuppressPaint := true;
  rep:=0;
  while rep < NREP do
    begin
    inc (rep);
    Application.ProcessMessages;
    errnum := RF.TrainRF;
    repo := RF.Report;
    ChartBook.Charts[PAGE].MarkAt (RF.RPar, repo.OOBRMSError, 26);
    end;
  ChartBook.Charts[PAGE].SuppressPaint := false;
  end;
ChartBook.Charts[PAGE].AutoRange (1,2);
ChartBook.Charts[PAGE].Update;
RF.Free;
FuncMon (true);
end.