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

 ##########
 File path: 
mllib/src/main/scala/org/apache/spark/ml/tree/impl/DecisionTreeMetadata.scala
 ##########
 @@ -115,7 +122,11 @@ private[spark] object DecisionTreeMetadata extends 
Logging {
     }
     require(numFeatures > 0, s"DecisionTree requires number of features > 0, " 
+
       s"but was given an empty features vector")
-    val numExamples = input.count()
+    val (numExamples, weightSum) = input.aggregate((0L, 0.0))(
+      seqOp = (cw, instance) => (cw._1 + 1L, cw._2 + instance.weight),
 
 Review comment:
   I got an error when I tried this:
   [error] 
/home/ilya/ilmat-spark/mllib/src/main/scala/org/apache/spark/ml/tree/impl/DecisionTreeMetadata.scala:126:
 not a legal formal parameter.
   [error] Note: Tuples cannot be directly destructured in method or function 
parameters.
   [error]       Either create a single parameter accepting the Tuple2,
   [error]       or consider a pattern matching anonymous function: `{ case 
(count, weight) => ... }
   [error]       seqOp = ((count, weight), instance) => (count + 1L, weight + 
instance.weight),
   [error]                ^
   [error] 
/home/ilya/ilmat-spark/mllib/src/main/scala/org/apache/spark/ml/tree/impl/DecisionTreeMetadata.scala:127:
 not a legal formal parameter.
   [error] Note: Tuples cannot be directly destructured in method or function 
parameters.
   [error]       Either create a single parameter accepting the Tuple2,
   [error]       or consider a pattern matching anonymous function: `{ case 
(count1, weight1) => ... }
   [error]       combOp = ((count1, weight1), (count2, weight2)) => (count1 + 
count2, weight1 + weight2)
   [error]                 ^
   [error] two errors found
   [error] Compile failed at Jan 15, 2019 12:02:10 AM [0.617s]
   

----------------------------------------------------------------
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