Return-Path: X-Original-To: apmail-spark-reviews-archive@minotaur.apache.org Delivered-To: apmail-spark-reviews-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 69AEF11D1D for ; Thu, 31 Jul 2014 21:23:35 +0000 (UTC) Received: (qmail 52234 invoked by uid 500); 31 Jul 2014 21:23:35 -0000 Delivered-To: apmail-spark-reviews-archive@spark.apache.org Received: (qmail 52212 invoked by uid 500); 31 Jul 2014 21:23:35 -0000 Mailing-List: contact reviews-help@spark.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: reviews@spark.apache.org Delivered-To: mailing list reviews@spark.apache.org Received: (qmail 52201 invoked by uid 99); 31 Jul 2014 21:23:34 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 31 Jul 2014 21:23:34 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 9461B95186A; Thu, 31 Jul 2014 21:23:34 +0000 (UTC) From: manishamde To: reviews@spark.apache.org Reply-To: reviews@spark.apache.org References: In-Reply-To: Subject: [GitHub] spark pull request: [SPARK-2756] [mllib] Decision tree bug fixes Content-Type: text/plain Message-Id: <20140731212334.9461B95186A@tyr.zones.apache.org> Date: Thu, 31 Jul 2014 21:23:34 +0000 (UTC) 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. ---