Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.json4s.JsonDSL._

import org.apache.spark.annotation.Since
import org.apache.spark.internal.Logging
import org.apache.spark.ml.linalg.{BLAS, DenseVector, SparseVector, Vector, Vectors}
import org.apache.spark.ml.linalg.{DenseVector, SparseVector, Vector, Vectors}
import org.apache.spark.ml.param.ParamMap
import org.apache.spark.ml.regression.DecisionTreeRegressionModel
import org.apache.spark.ml.tree._
Expand Down Expand Up @@ -367,8 +367,13 @@ class GBTClassificationModel private[ml](

/** Raw prediction for the positive class. */
private def margin(features: Vector): Double = {
val treePredictions = _trees.map(_.rootNode.predictImpl(features).prediction)
BLAS.nativeBLAS.ddot(getNumTrees, treePredictions, 1, _treeWeights, 1)
var prediction = 0.0
var i = 0
while (i < _trees.length) {
prediction += _trees(i).rootNode.predictImpl(features).prediction * _treeWeights(i)
i += 1
}
prediction
}

/** (private[ml]) Convert to a model in the old API */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.json4s.JsonDSL._

import org.apache.spark.annotation.Since
import org.apache.spark.internal.{Logging, LogKeys}
import org.apache.spark.ml.linalg.{BLAS, Vector}
import org.apache.spark.ml.linalg.Vector
import org.apache.spark.ml.param.ParamMap
import org.apache.spark.ml.tree._
import org.apache.spark.ml.tree.impl.GradientBoostedTrees
Expand Down Expand Up @@ -301,8 +301,13 @@ class GBTRegressionModel private[ml](
override def predict(features: Vector): Double = {
// TODO: When we add a generic Boosting class, handle transform there? SPARK-7129
// Classifies by thresholding sum of weighted tree predictions
val treePredictions = _trees.map(_.rootNode.predictImpl(features).prediction)
BLAS.nativeBLAS.ddot(getNumTrees, treePredictions, 1, _treeWeights, 1)
var prediction = 0.0
var i = 0
while (i < _trees.length) {
prediction += _trees(i).rootNode.predictImpl(features).prediction * _treeWeights(i)
i += 1
}
prediction
}

@Since("1.4.0")
Expand Down