Github user catap commented on the pull request:

    https://github.com/apache/spark/pull/6795#issuecomment-118237792
  
    @feynmanliang I think you mean `tf.persist()`, don't you? Because 
`tf.collect()` convert RDD to local array  and I can't use this on 
DecisionTree.trainClassifier.
    
    So, when I re-run test with `tf.persist()` and `transformed_tf.persist()`, 
I had result:
    ```
    Elapsed time 2 min, 5 sec, 711 millis (total 125711 millis)
    Elapsed transformed time 0 min, 2 sec, 750 millis (total 2750 millis)
    ```
    
    the code:
    ```scala
    import java.util.Random
    
    import org.apache.spark.mllib.feature.{HashingTF, SignificantSelector}
    import org.apache.spark.mllib.regression.LabeledPoint
    import org.apache.spark.mllib.tree.DecisionTree
    import org.apache.spark.rdd.RDD
    
    import scala.concurrent.duration._
    import scala.language.implicitConversions
    
    val rnd = new Random
    
    val length = 20
    
    implicit def bool2Double(b:Boolean): Double = if (b) 1d else 0d
    
    val localDocs = (1 to length).map(_ =>
      (rnd.nextBoolean().toDouble, (1 to 1000).map(_ => 
rnd.nextDouble().toString)))
    
    val docs = sc.parallelize(localDocs, 2)
    
    val hashingTF = new HashingTF()
    
    val tf: RDD[LabeledPoint] = docs.map { case (label, words) => 
LabeledPoint(label, hashingTF.transform(words)) }
    
    val transformer = new SignificantSelector().fit(tf.map(_.features))
    
    val transformed_tf = tf.map(p => p.copy(features = 
transformer.transform(p.features)))
    
    tf.persist()
    
    val start = System.currentTimeMillis()
    val model = DecisionTree.trainClassifier(tf, 2, Map[Int, Int](), "gini", 
30, length)
    val end = System.currentTimeMillis()
    
    tf.unpersist()
    
    transformed_tf.persist()
    
    val transformed_start = System.currentTimeMillis()
    val transformed_model = DecisionTree.trainClassifier(transformed_tf, 2, 
Map[Int, Int](), "gini", 30, length)
    val transformed_end = System.currentTimeMillis()
    
    transformed_tf.unpersist()
    
    val elapsed = DurationLong(end - start).millis
    val transformed_elapsed = DurationLong(transformed_end - 
transformed_start).millis
    
    println("Ok, done.")
    println(f"Elapsed time ${elapsed.toMinutes} min, ${elapsed.toSeconds % 60} 
sec, ${elapsed.toMillis % 1000} millis (total ${elapsed.toMillis} millis)")
    println(f"Elapsed transformed time ${transformed_elapsed.toMinutes} min, 
${transformed_elapsed.toSeconds % 60} sec, ${transformed_elapsed.toMillis % 
1000} millis (total ${transformed_elapsed.toMillis} millis)")
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

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

Reply via email to