#11143 [FIX] Normalize node risk with sample weight sum
authorcodingforfun <codingforfun@users.noreply.github.com>
Tue, 27 Mar 2018 13:39:36 +0000 (15:39 +0200)
committercodingforfun <codingforfun@users.noreply.github.com>
Tue, 27 Mar 2018 13:39:36 +0000 (15:39 +0200)
In case of regression trees, node risk is computed as sum of squared
error. To get a meaningfull value to compare with it needs to be
normalized to the number of samples in the node (or more generally to
the sum of sample weights in this node). Otherwise the sum of squared
error is highly dependend on the number of samples in the node and
comparision with `regressionAccuracy` parameter is not very meaningful.

After normalization `node_risk` means in fact sample variance for all
samples in the node, which makes much more sence and seams to be what
was originaly intended by the code given that node risk is later used as
a split termination criteria by
```
sqrt(node.node_risk) < params.getRegressionAccuracy()
```

modules/ml/src/tree.cpp

index c02b7440e714a75495bbce64ac002bd9fb3e6127..4b3079b3d10f664ed44979448895ec31e8942de8 100644 (file)
@@ -632,6 +632,7 @@ void DTreesImpl::calcValue( int nidx, const vector<int>& _sidx )
         }
 
         node->node_risk = sum2 - (sum/sumw)*sum;
+        node->node_risk /= sumw;
         node->value = sum/sumw;
     }
 }