spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From manishamde <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-2756] [mllib] Decision tree bug fixes
Date Thu, 31 Jul 2014 21:23:34 GMT
Github user manishamde commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1673#discussion_r15670934
  
    --- 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 --
    
    Just curious: should these be log statements instead of 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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message