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 @@ -319,7 +319,12 @@ class GBTClassificationModel private[ml](
}
}

/** Number of trees in ensemble */
/**
* Number of trees in ensemble
*
* @deprecated Use [[getNumTrees]] instead. This method will be removed in 3.0.0.
*/
@deprecated("Use getNumTrees instead. This method will be removed in 3.0.0.", "2.4.5")
val numTrees: Int = trees.length

@Since("1.4.0")
Expand All @@ -330,7 +335,7 @@ class GBTClassificationModel private[ml](

@Since("1.4.0")
override def toString: String = {
s"GBTClassificationModel (uid=$uid) with $numTrees trees"
s"GBTClassificationModel (uid=$uid) with $getNumTrees trees"
}

/**
Expand All @@ -349,7 +354,7 @@ 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.ddot(numTrees, treePredictions, 1, _treeWeights, 1)
blas.ddot(getNumTrees, treePredictions, 1, _treeWeights, 1)
}

/** (private[ml]) Convert to a model in the old API */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,15 @@ class GBTRegressionModel private[ml](
// 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.ddot(numTrees, treePredictions, 1, _treeWeights, 1)
blas.ddot(getNumTrees, treePredictions, 1, _treeWeights, 1)
}

/** Number of trees in ensemble */
/**
* Number of trees in ensemble
*
* @deprecated Use [[getNumTrees]] instead. This method will be removed in 3.0.0.
*/
@deprecated("Use getNumTrees instead. This method will be removed in 3.0.0.", "2.4.5")
val numTrees: Int = trees.length

@Since("1.4.0")
Expand All @@ -269,7 +274,7 @@ class GBTRegressionModel private[ml](

@Since("1.4.0")
override def toString: String = {
s"GBTRegressionModel (uid=$uid) with $numTrees trees"
s"GBTRegressionModel (uid=$uid) with $getNumTrees trees"
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ class GBTClassifierSuite extends MLTest with DefaultReadWriteTest {
assert(raw.size === 2)
// check that raw prediction is tree predictions dot tree weights
val treePredictions = gbtModel.trees.map(_.rootNode.predictImpl(features).prediction)
val prediction = blas.ddot(gbtModel.numTrees, treePredictions, 1, gbtModel.treeWeights, 1)
val prediction = blas.ddot(gbtModel.getNumTrees, treePredictions, 1,
gbtModel.treeWeights, 1)
assert(raw ~== Vectors.dense(-prediction, prediction) relTol eps)

// Compare rawPrediction with probability
Expand Down Expand Up @@ -410,9 +411,9 @@ class GBTClassifierSuite extends MLTest with DefaultReadWriteTest {
gbt.setValidationIndicatorCol(validationIndicatorCol)
val modelWithValidation = gbt.fit(trainDF.union(validationDF))

assert(modelWithoutValidation.numTrees === numIter)
assert(modelWithoutValidation.getNumTrees === numIter)
// early stop
assert(modelWithValidation.numTrees < numIter)
assert(modelWithValidation.getNumTrees < numIter)

val (errorWithoutValidation, errorWithValidation) = {
val remappedRdd = validationData.map(x => new LabeledPoint(2 * x.label - 1, x.features))
Expand All @@ -428,10 +429,10 @@ class GBTClassifierSuite extends MLTest with DefaultReadWriteTest {
modelWithoutValidation.treeWeights, modelWithoutValidation.getOldLossType,
OldAlgo.Classification)
assert(evaluationArray.length === numIter)
assert(evaluationArray(modelWithValidation.numTrees) >
evaluationArray(modelWithValidation.numTrees - 1))
assert(evaluationArray(modelWithValidation.getNumTrees) >
evaluationArray(modelWithValidation.getNumTrees - 1))
var i = 1
while (i < modelWithValidation.numTrees) {
while (i < modelWithValidation.getNumTrees) {
assert(evaluationArray(i) <= evaluationArray(i - 1))
i += 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ class GBTRegressorSuite extends MLTest with DefaultReadWriteTest {
gbt.setValidationIndicatorCol(validationIndicatorCol)
val modelWithValidation = gbt.fit(trainDF.union(validationDF))

assert(modelWithoutValidation.numTrees === numIter)
assert(modelWithoutValidation.getNumTrees === numIter)
// early stop
assert(modelWithValidation.numTrees < numIter)
assert(modelWithValidation.getNumTrees < numIter)

val errorWithoutValidation = GradientBoostedTrees.computeError(validationData,
modelWithoutValidation.trees, modelWithoutValidation.treeWeights,
Expand All @@ -267,10 +267,10 @@ class GBTRegressorSuite extends MLTest with DefaultReadWriteTest {
modelWithoutValidation.treeWeights, modelWithoutValidation.getOldLossType,
OldAlgo.Regression)
assert(evaluationArray.length === numIter)
assert(evaluationArray(modelWithValidation.numTrees) >
evaluationArray(modelWithValidation.numTrees - 1))
assert(evaluationArray(modelWithValidation.getNumTrees) >
evaluationArray(modelWithValidation.getNumTrees - 1))
var i = 1
while (i < modelWithValidation.numTrees) {
while (i < modelWithValidation.getNumTrees) {
assert(evaluationArray(i) <= evaluationArray(i - 1))
i += 1
}
Expand Down