Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1673#discussion_r15681460
  
    --- Diff: 
examples/src/main/scala/org/apache/spark/examples/mllib/DecisionTreeRunner.scala
 ---
    @@ -100,16 +109,57 @@ object DecisionTreeRunner {
       }
     
       def run(params: Params) {
    +
         val conf = new SparkConf().setAppName("DecisionTreeRunner")
         val sc = new SparkContext(conf)
     
         // Load training data and cache it.
    -    val examples = MLUtils.loadLabeledPoints(sc, params.input).cache()
    +    val origExamples = params.dataFormat match {
    +      case "dense" => MLUtils.loadLabeledPoints(sc, params.input).cache()
    +      case "libsvm" => MLUtils.loadLibSVMFile(sc, params.input).cache()
    +    }
    +    // For classification, re-index classes if needed.
    +    val (examples, numClasses) = params.algo match {
    +      case Classification => {
    +        // classCounts: class --> # examples in class
    +        val classCounts = origExamples.map(_.label).countByValue()
    +        val sortedClasses = classCounts.keys.toList.sorted
    +        val numClasses = classCounts.size
    +        // classIndexMap: class --> index in 0,...,numClasses-1
    +        val classIndexMap = {
    +          if (classCounts.keySet != Set(0.0, 1.0)) {
    +            sortedClasses.zipWithIndex.toMap
    +          } else {
    +            Map[Double, Int]()
    +          }
    +        }
    +        val examples = {
    +          if (classIndexMap.isEmpty) {
    +            origExamples
    +          } else {
    +            origExamples.map(lp => LabeledPoint(classIndexMap(lp.label), 
lp.features))
    +          }
    +        }
    +        val numExamples = examples.count()
    +        println(s"numClasses = $numClasses.")
    --- End diff --
    
    This is on the driver node. It should be okay to use `println`.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to