Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update Instance scope
  • Loading branch information
zhengruifeng committed Oct 23, 2019
commit 23f27a55b1cfbef6342745268f4eb5008d3010be
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.apache.spark.ml.linalg.Vector
* @param weight The weight of this instance.
* @param features The vector of features for this data point.
*/
private[ml] case class Instance(label: Double, weight: Double, features: Vector)
private[spark] case class Instance(label: Double, weight: Double, features: Vector)

/**
* Case class that represents an instance of data point with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.github.fommil.netlib.BLAS

import org.apache.spark.{SparkException, SparkFunSuite}
import org.apache.spark.ml.classification.LinearSVCSuite.generateSVMInput
import org.apache.spark.ml.feature.LabeledPoint
import org.apache.spark.ml.feature.{Instance, LabeledPoint}
import org.apache.spark.ml.linalg.{Vector, Vectors}
import org.apache.spark.ml.param.ParamsSuite
import org.apache.spark.ml.regression.DecisionTreeRegressionModel
Expand Down Expand Up @@ -401,8 +401,10 @@ class GBTClassifierSuite extends MLTest with DefaultReadWriteTest {
model3.trees.take(2), model3.treeWeights.take(2), model3.numFeatures, model3.numClasses)

val evalArr = model3.evaluateEachIteration(validationData.toDF)
val remappedValidationData = validationData.map(
x => LabeledPoint((x.label * 2) - 1, x.features).toInstance)
val remappedValidationData = validationData.map {
case LabeledPoint(label, features) =>
Instance(label * 2 - 1, 1.0, features)
}
val lossErr1 = GradientBoostedTrees.computeError(remappedValidationData,
model1.trees, model1.treeWeights, model1.getOldLossType)
val lossErr2 = GradientBoostedTrees.computeError(remappedValidationData,
Expand Down Expand Up @@ -437,8 +439,10 @@ class GBTClassifierSuite extends MLTest with DefaultReadWriteTest {
assert(modelWithValidation.numTrees < numIter)

val (errorWithoutValidation, errorWithValidation) = {
val remappedRdd = validationData.map(x =>
LabeledPoint(2 * x.label - 1, x.features).toInstance)
val remappedRdd = validationData.map {
case LabeledPoint(label, features) =>
Instance(label * 2 - 1, 1.0, features)
}
(GradientBoostedTrees.computeError(remappedRdd, modelWithoutValidation.trees,
modelWithoutValidation.treeWeights, modelWithoutValidation.getOldLossType),
GradientBoostedTrees.computeError(remappedRdd, modelWithValidation.trees,
Expand Down