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

    https://github.com/apache/spark/pull/5530#discussion_r28487029
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/ml/classification/DecisionTreeClassifierSuite.scala
 ---
    @@ -0,0 +1,274 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.ml.classification
    +
    +import org.scalatest.FunSuite
    +
    +import org.apache.spark.ml.impl.TreeTests
    +import org.apache.spark.mllib.linalg.Vectors
    +import org.apache.spark.mllib.regression.LabeledPoint
    +import org.apache.spark.mllib.tree.{DecisionTree => OldDecisionTree,
    +  DecisionTreeSuite => OldDecisionTreeSuite}
    +import org.apache.spark.mllib.util.MLlibTestSparkContext
    +import org.apache.spark.rdd.RDD
    +import org.apache.spark.sql.DataFrame
    +
    +
    +class DecisionTreeClassifierSuite extends FunSuite with 
MLlibTestSparkContext {
    +
    +  import DecisionTreeClassifierSuite.compareAPIs
    +
    +  private var categoricalDataPointsRDD: RDD[LabeledPoint] = _
    +  private var orderedLabeledPointsWithLabel0RDD: RDD[LabeledPoint] = _
    +  private var orderedLabeledPointsWithLabel1RDD: RDD[LabeledPoint] = _
    +  private var categoricalDataPointsForMulticlassRDD: RDD[LabeledPoint] = _
    +  private var continuousDataPointsForMulticlassRDD: RDD[LabeledPoint] = _
    +  private var categoricalDataPointsForMulticlassForOrderedFeaturesRDD: 
RDD[LabeledPoint] = _
    +
    +  override def beforeAll() {
    +    super.beforeAll()
    +    categoricalDataPointsRDD =
    +      sc.parallelize(OldDecisionTreeSuite.generateCategoricalDataPoints())
    +    orderedLabeledPointsWithLabel0RDD =
    +      
sc.parallelize(OldDecisionTreeSuite.generateOrderedLabeledPointsWithLabel0())
    +    orderedLabeledPointsWithLabel1RDD =
    +      
sc.parallelize(OldDecisionTreeSuite.generateOrderedLabeledPointsWithLabel1())
    +    categoricalDataPointsForMulticlassRDD =
    +      
sc.parallelize(OldDecisionTreeSuite.generateCategoricalDataPointsForMulticlass())
    +    continuousDataPointsForMulticlassRDD =
    +      
sc.parallelize(OldDecisionTreeSuite.generateContinuousDataPointsForMulticlass())
    +    categoricalDataPointsForMulticlassForOrderedFeaturesRDD = 
sc.parallelize(
    +      
OldDecisionTreeSuite.generateCategoricalDataPointsForMulticlassForOrderedFeatures())
    +  }
    +
    +  
/////////////////////////////////////////////////////////////////////////////
    +  // Tests calling train()
    +  
/////////////////////////////////////////////////////////////////////////////
    +
    +  test("Binary classification stump with ordered categorical features") {
    +    val dt = new DecisionTreeClassifier()
    +      .setImpurity("gini")
    +      .setMaxDepth(2)
    +      .setMaxBins(100)
    +    val categoricalFeatures = Map(0 -> 3, 1-> 3)
    +    val numClasses = 2
    +    compareAPIs(categoricalDataPointsRDD, dt, categoricalFeatures, 
numClasses)
    +  }
    +
    +  test("Binary classification stump with fixed labels 0,1 for 
Entropy,Gini") {
    +    val dt = new DecisionTreeClassifier()
    +      .setMaxDepth(3)
    +      .setMaxBins(100)
    +    val numClasses = 2
    +    Array(orderedLabeledPointsWithLabel0RDD, 
orderedLabeledPointsWithLabel1RDD).foreach { rdd =>
    +      DecisionTreeClassifier.supportedImpurities.foreach { impurity =>
    +        dt.setImpurity(impurity)
    +        compareAPIs(rdd, dt, categoricalFeatures = Map.empty[Int, Int], 
numClasses)
    +      }
    +    }
    +  }
    +
    +  test("Multiclass classification stump with 3-ary (unordered) categorical 
features") {
    +    val rdd = categoricalDataPointsForMulticlassRDD
    +    val dt = new DecisionTreeClassifier()
    +      .setImpurity("Gini")
    +      .setMaxDepth(4)
    +    val numClasses = 3
    +    val categoricalFeatures = Map(0 -> 3, 1 -> 3)
    +    compareAPIs(rdd, dt, categoricalFeatures, numClasses)
    +  }
    +
    +  test("Binary classification stump with 1 continuous feature, to check 
off-by-1 error") {
    +    val arr = new Array[LabeledPoint](4)
    +    arr(0) = new LabeledPoint(0.0, Vectors.dense(0.0))
    +    arr(1) = new LabeledPoint(1.0, Vectors.dense(1.0))
    +    arr(2) = new LabeledPoint(1.0, Vectors.dense(2.0))
    +    arr(3) = new LabeledPoint(1.0, Vectors.dense(3.0))
    --- End diff --
    
    ~~~scala
    val arr = Array(
      new LabelPoint(...),
      new ...
    }
    ~~~


---
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