Skip to content

Commit

Permalink
couple of small fixes in rtrees variable importance calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
vpisarev committed Dec 10, 2015
1 parent fda1727 commit 544990e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions modules/ml/src/rtrees.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,13 @@ class DTreesImplForRTrees : public DTreesImpl
oobError /= n_oob;
if( rparams.calcVarImportance && n_oob > 1 )
{
Mat sample_clone;
oobperm.resize(n_oob);
for( i = 0; i < n_oob; i++ )
oobperm[i] = oobidx[i];
for (i = n_oob - 1; i > 0; --i) //Randomly shuffle indices so we can permute features
{
int r_i = rng.uniform(0, i + 1);
int r_i = rng.uniform(0, n_oob);
std::swap(oobperm[i], oobperm[r_i]);
}

Expand All @@ -252,7 +253,7 @@ class DTreesImplForRTrees : public DTreesImpl
j = oobidx[i];
int vj = oobperm[i];
sample0 = Mat( nallvars, 1, CV_32F, psamples + sstep0*w->sidx[j], sstep1*sizeof(psamples[0]) );
Mat sample_clone = sample0.clone(); //create a copy so we don't mess up the original data
sample0.copyTo(sample_clone); //create a copy so we don't mess up the original data
sample_clone.at<float>(vi) = psamples[sstep0*w->sidx[vj] + sstep1*vi];

double val = predictTrees(Range(treeidx, treeidx+1), sample_clone, predictFlags);
Expand Down

0 comments on commit 544990e

Please sign in to comment.