Skip to content

Instantly share code, notes, and snippets.

@Alrecenk
Last active December 26, 2015 04:39
Show Gist options
  • Save Alrecenk/7095311 to your computer and use it in GitHub Desktop.
Save Alrecenk/7095311 to your computer and use it in GitHub Desktop.
Bootstrap aggregation for a random forest algorithm.
//bootstrap aggregating of training data for a random forest
Random rand = new Random(seed);
treenode tree[] = new treenode[trees] ;
for(int k=0;k<trees;k++){
ArrayList<Datapoint> treedata = new ArrayList<Datapoint>()
for (int j = 0; j < datapermodel; j++){
//add a random data point to the training data for this tree
int nj = Math.abs(rand.nextInt())%data.size();
treedata.add(alldata.get(nj)) ;
}
tree[k]=new treenode(treedata,minpoints,maxdepth, featurefraction);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment