zhengruifeng commented on a change in pull request #26803: [SPARK-30178][ML] 
RobustScaler support large numFeatures
URL: https://github.com/apache/spark/pull/26803#discussion_r359141048
 
 

 ##########
 File path: mllib/src/main/scala/org/apache/spark/ml/feature/RobustScaler.scala
 ##########
 @@ -147,49 +146,73 @@ class RobustScaler (override val uid: String)
 
   override def fit(dataset: Dataset[_]): RobustScalerModel = {
     transformSchema(dataset.schema, logging = true)
-    val localRelativeError = $(relativeError)
 
-    val summaries = dataset.select($(inputCol)).rdd.map {
-      case Row(vec: Vector) => vec
-    }.mapPartitions { iter =>
-      var agg: Array[QuantileSummaries] = null
-      while (iter.hasNext) {
-        val vec = iter.next()
+    val vectors = dataset.select($(inputCol)).rdd.map { case Row(vec: Vector) 
=> vec }
+    val numFeatures = MetadataUtils.getNumFeatures(dataset.schema($(inputCol)))
+      .getOrElse(vectors.first().size)
+
+    val localRelativeError = $(relativeError)
+    val localUpper = $(upper)
+    val localLower = $(lower)
+
+    // each featureIndex and its QuantileSummaries
+    val summaries = if (numFeatures < 1000) {
 
 Review comment:
   I revisit this PR and found that the performance regression may come from 
two side:
   1, `QuantileSummaries` are not compressed after _map_ side;
   2, two-step aggregation: `aggregateByKey` & `reduceByKey` may not improve 
the performance as supposed;
   
   So I come back to the inital commit, and use a trick to compress aggregators 
at _map_ out. Now it is faster than the previous commit but still about 10% 
slower than Master in the edge case.
   Since this impl is concise, so I prefer it to previous ones.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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