You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by jkbradley <gi...@git.apache.org> on 2014/08/01 01:35:16 UTC

[GitHub] spark pull request: [SPARK-2756] [mllib] Decision tree bug fixes

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

    https://github.com/apache/spark/pull/1673#discussion_r15676566
  
    --- 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 --
    
    @mengxr  Your thoughts?


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