imatiach-msft commented on a change in pull request #23682: 
[SPARK-19591][ML][MLlib][FOLLOWUP] Add sample weights to decision trees - fix 
tolerance
URL: https://github.com/apache/spark/pull/23682#discussion_r252539474
 
 

 ##########
 File path: 
mllib/src/main/scala/org/apache/spark/ml/tree/impl/RandomForest.scala
 ##########
 @@ -1050,8 +1050,11 @@ private[spark] object RandomForest extends Logging with 
Serializable {
       // Calculate the expected number of samples for finding splits
       val weightedNumSamples = samplesFractionForFindSplits(metadata) *
         metadata.weightedNumExamples
+      // scale tolerance by number of samples with constant factor
+      // Note: constant factor was tuned by running some tests where there 
were no zero
+      // feature values and validating we are never within tolerance
+      val tolerance = Utils.EPSILON * unweightedNumSamples * 100
       // add expected zero value count and get complete statistics
-      val tolerance = Utils.EPSILON * unweightedNumSamples * 
unweightedNumSamples
       val valueCountMap = if (weightedNumSamples - partNumSamples > tolerance) 
{
 
 Review comment:
   Just to confirm you mean to do something like:
   ```
   if (Math.abs(weightedNumSamples - partNumSamples) > tolerance)
   ...
   ```
   Good question.  weightedNumSamples includes zero feature values (if they 
exist) whereas partNumSamples does not, so supposedly it should always be the 
case that weightedNumSamples >= partNumSamples; I believe it is possible that 
they could flip if there are no zero feature values due to numeric inaccuracies 
of floating point but the difference would be small and anyway no matter how 
big the difference would be we should always ignore it because it would 
indicate there are no zero feature values.  So technically we should only do 
weightedNumSamples - partNumSamples without the absolute value.  If you do see 
cases where partNumSamples >>(much greater than) weightedNumSamples let me 
know, that would mean there is something wrong in the code.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to