Github user sethah commented on a diff in the pull request:
https://github.com/apache/spark/pull/9008#discussion_r53092866
--- Diff:
mllib/src/test/scala/org/apache/spark/ml/regression/DecisionTreeRegressorSuite.scala
---
@@ -73,6 +76,56 @@ class DecisionTreeRegressorSuite extends SparkFunSuite
with MLlibTestSparkContex
MLTestingUtils.checkCopy(model)
}
+ test("training with weighted data") {
+ val (dataset, weightedDataset) = {
+ val testData1 = TreeTests.generateNoisyData(5, 123)
+ val testData2 = TreeTests.generateNoisyData(5, 456)
+
+ // Over-sample the 1st dataset twice.
+ val overSampledTestData1 = testData1.flatMap {
+ labeledPoint => Iterator(labeledPoint, labeledPoint)
+ }
+
+ val rnd = new Random(8392)
+ val weightedTestData1 = testData1.flatMap {
+ case LabeledPoint(label: Double, features: Vector) => {
+ if (rnd.nextGaussian() > 0.0) {
+ Iterator(
+ Instance(label, 1.2, features),
+ Instance(label, 0.8, features),
+ Instance(0.0, 0.0, features))
+ } else {
+ Iterator(
+ Instance(label, 0.3, features),
+ Instance(1.0, 0.0, features),
+ Instance(label, 1.1, features),
+ Instance(label, 0.6, features))
+ }
+ }
+ }
+ val weightedTestData2 = testData2.map {
+ p: LabeledPoint => Instance(p.label, 1, p.features)
+ }
+
+ (sqlContext.createDataFrame(sc.parallelize(overSampledTestData1 ++
testData2, 2)),
+ sqlContext.createDataFrame(sc.parallelize(weightedTestData1 ++
weightedTestData2, 2)))
+ }
+
+ val featureIndexer = new VectorIndexer()
+ .setInputCol("features")
+ .setOutputCol("indexedFeatures")
+ .setMaxCategories(4)
+ .fit(dataset)
+
+ val dt = new DecisionTreeRegressor()
+ .setFeaturesCol("indexedFeatures")
+
+ val model1 = dt.fit(featureIndexer.transform(dataset))
+ val model2 = dt.fit(featureIndexer.transform(weightedDataset),
+ dt.weightCol->"weight")
--- End diff --
ditto
---
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]