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

    https://github.com/apache/spark/pull/16441#discussion_r95284176
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/ml/classification/GBTClassifierSuite.scala
 ---
    @@ -66,10 +70,79 @@ class GBTClassifierSuite extends SparkFunSuite with 
MLlibTestSparkContext
         ParamsSuite.checkParams(new GBTClassifier)
         val model = new GBTClassificationModel("gbtc",
           Array(new DecisionTreeRegressionModel("dtr", new LeafNode(0.0, 0.0, 
null), 1)),
    -      Array(1.0), 1)
    +      Array(1.0), 1, 2)
         ParamsSuite.checkParams(model)
       }
     
    +  test("GBTClassifier: Predictor, Classifier methods") {
    +    val rawPredictionCol = "rawPrediction"
    +    val predictionCol = "prediction"
    +    val labelCol = "label"
    +    val featuresCol = "features"
    +    val probabilityCol = "probability"
    +
    +    val gbt = new GBTClassifier().setSeed(123)
    +    val trainingDataset = trainData.toDF(labelCol, featuresCol)
    +    val gbtModel = gbt.fit(trainingDataset)
    +    assert(gbtModel.numClasses === 2)
    +    val numFeatures = 
trainingDataset.select(featuresCol).first().getAs[Vector](0).size
    +    assert(gbtModel.numFeatures === numFeatures)
    +
    +    val blas = BLAS.getInstance()
    +
    +    val validationDataset = validationData.toDF(labelCol, featuresCol)
    +    val results = gbtModel.transform(validationDataset)
    +    // check that raw prediction is tree predictions dot tree weights
    +    results.select(rawPredictionCol, featuresCol).collect().foreach {
    +      case Row(raw: Vector, features: Vector) =>
    +        assert(raw.size === 2)
    +        val treePredictions = 
gbtModel.trees.map(_.rootNode.predictImpl(features).prediction)
    +        val prediction = blas.ddot(gbtModel.numTrees, treePredictions, 1, 
gbtModel.treeWeights, 1)
    +        assert(raw ~== Vectors.dense(-prediction, prediction) relTol eps)
    +    }
    +
    +    // Compare rawPrediction with probability
    +    results.select(rawPredictionCol, probabilityCol).collect().foreach {
    +      case Row(raw: Vector, prob: Vector) =>
    +        assert(raw.size === 2)
    +        assert(prob.size === 2)
    +        val prodFromRaw = raw.toDense.values.map(value => 1 / (1 + 
math.exp(-2 * value)))
    +        assert(prob(0) ~== prodFromRaw(0) relTol eps)
    --- End diff --
    
    check that `prob(0) + prob(1) ~== 1.0 absTol 1e-8`


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