You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by MechCoder <gi...@git.apache.org> on 2016/06/13 21:36:15 UTC
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
GitHub user MechCoder opened a pull request:
https://github.com/apache/spark/pull/13650
[SPARK-9623] [ML] Provide variance for RandomForestRegressor predictions
## What changes were proposed in this pull request?
It is useful to get the variance of predictions from the `RandomForestRegressor` to plot confidence intervals on the predictions. I verified the formula from page 17 of this paper (http://arxiv.org/pdf/1211.0906v2.pdf)
## How was this patch tested?
I added a couple of tests to the RandomForestRegression test suite.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/MechCoder/spark random_forest_var
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/13650.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #13650
----
commit 75254c91cf8d9c2f3638a3f9b1cfd5c029e10996
Author: MechCoder <mk...@nyu.edu>
Date: 2016-06-09T18:22:53Z
[SPARK-9623] [ML] Provide variance for RandomForestRegressor predictions
----
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r70637268
--- Diff: mllib/src/test/scala/org/apache/spark/ml/regression/RandomForestRegressorSuite.scala ---
@@ -105,6 +109,54 @@ class RandomForestRegressorSuite extends SparkFunSuite with MLlibTestSparkContex
}
}
+ test("Random Forest variance") {
+ val categoricalFeatures = Map.empty[Int, Int]
+ val df: DataFrame = TreeTests.setMetadata(
+ orderedLabeledPoints50_1000, categoricalFeatures, 0)
+
+ // RF with one tree should have the same variance as that of the tree.
+ val rf = new RandomForestRegressor()
+ .setImpurity("variance")
+ .setMaxDepth(30)
+ .setNumTrees(1)
+ .setMaxBins(10)
+ .setFeatureSubsetStrategy("all")
+ .setSubsamplingRate(1.0)
+ .setSeed(123)
+
+ val rfModel = rf.fit(df)
+ val rfVariances = rfModel.transform(df).select("variance").collect()
+
+ val dt = new DecisionTreeRegressor()
+ .setImpurity("variance")
+ .setMaxDepth(30)
+ .setMaxBins(10)
+ .setSeed(123)
+ val dtModel = dt.fit(df)
+ val dtVariances = dtModel.transform(df).select("variance").collect()
+ val nSamples = dtVariances.size
+ (0 to nSamples - 1).foreach { i =>
+ assert(rfVariances(i).getDouble(0) ~== dtVariances(i).getDouble(0) absTol 1e-6)
+ }
+
+ rf.setMaxDepth(2)
+ rf.setNumTrees(20)
+ val rfNewModel = rf.fit(df)
+ val results = rfNewModel.transform(df).select("features", "variance").collect()
+ val features = col("features")
+ val trees = rfNewModel.trees
+ val numTrees = rfNewModel.getNumTrees
+ results.map { case Row(features: Vector, variance: Double) =>
--- End diff --
```results.foreach { ... }```
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/13650
**[Test build #61478 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/61478/consoleFull)** for PR 13650 at commit [`a48f198`](https://github.com/apache/spark/commit/a48f19828ae1a7be5252d0319b5f6c9b4c8ddc09).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide conditional variance for Rando...
Posted by MechCoder <gi...@git.apache.org>.
Github user MechCoder commented on the issue:
https://github.com/apache/spark/pull/13650
@yanboliang Sorry for the wrong delay! Hope you are still here.
1. The term variance in predictions is ambiguous and a bit misleading. Let us say that we have the original data generating distribution, the variance in prediction for a decision tree describes how much the prediction changes from one decision tree to another fit on the subsample of the data. As we know, this "variance in predictions" is high for a decision tree and reduces to zero for a random forest, (assuming there a huge number of trees and the trees are uncorrelated). I have updated the PR title to reflect this.
2. No, the paper as such is not widely cited. Also what @sethah describes is correct. This approach is picking a random tree with equal probability, and use the expected variance as got by that. However, the conditional distribution of Y|X is NOT the mean of the conditional distribution of Y|X of each tree. That is P(Y | X) != (P(Y_1 | x) + P(Y_2 | x) + .. P(Y_n | x)) / n. It is only that the expectation of Y|x is given by the mean of the expectation of the individual trees. The correct way of deriving the conditional CDF of Y | x is given in the well-cited paper (http://www.jmlr.org/papers/volume7/meinshausen06a/meinshausen06a.pdf) .
3. However, the formula derived in the paper is the same as got by the weighted variance with weights given to the target variable in the training data as defined in formula 5 of http://www.jmlr.org/papers/volume7/meinshausen06a/meinshausen06a.pdf . I have verified it on synthetic data in a notebook over here (https://github.com/MechCoder/Notebooks/blob/master/Conditional_variances.ipynb) .
I have spent more time then I would have initially expected on this Pull Request and I'm willing to do anything more that is required to merge.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/13650
Merged build finished. Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by sethah <gi...@git.apache.org>.
Github user sethah commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r67740399
--- Diff: mllib/src/main/scala/org/apache/spark/ml/regression/RandomForestRegressor.scala ---
@@ -168,15 +173,39 @@ class RandomForestRegressionModel private[ml] (
// Note: We may add support for weights (based on tree performance) later on.
private lazy val _treeWeights: Array[Double] = Array.fill[Double](_trees.length)(1.0)
+ @Since("2.1.0")
+ /** @group getParam */
+ def setVarianceCol(value: String): this.type = set(varianceCol, value)
+
@Since("1.4.0")
override def treeWeights: Array[Double] = _treeWeights
override protected def transformImpl(dataset: Dataset[_]): DataFrame = {
val bcastModel = dataset.sparkSession.sparkContext.broadcast(this)
+
+ var output = dataset
+
val predictUDF = udf { (features: Any) =>
bcastModel.value.predict(features.asInstanceOf[Vector])
}
- dataset.withColumn($(predictionCol), predictUDF(col($(featuresCol))))
+ val predictions = predictUDF(col($(featuresCol)))
+ output = dataset.withColumn($(predictionCol), predictions)
+
+ val varianceUDF = udf { (features: Any) =>
--- End diff --
I think we should follow the decision tree implementation and add a `predictVariance` method. Then you can just change this to:
```scala
val predictVarianceUDF = udf { (features: Vector) => predictVariance(features) }
```
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/13650
Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/61480/
Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r70601639
--- Diff: mllib/src/main/scala/org/apache/spark/ml/regression/RandomForestRegressor.scala ---
@@ -93,6 +94,10 @@ class RandomForestRegressor @Since("1.4.0") (@Since("1.4.0") override val uid: S
override def setFeatureSubsetStrategy(value: String): this.type =
super.setFeatureSubsetStrategy(value)
+ @Since("2.1.0")
+ /** @group getParam */
--- End diff --
```getParam``` -> ```setParam```
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r70637680
--- Diff: mllib/src/test/scala/org/apache/spark/ml/regression/RandomForestRegressorSuite.scala ---
@@ -105,6 +109,54 @@ class RandomForestRegressorSuite extends SparkFunSuite with MLlibTestSparkContex
}
}
+ test("Random Forest variance") {
+ val categoricalFeatures = Map.empty[Int, Int]
+ val df: DataFrame = TreeTests.setMetadata(
+ orderedLabeledPoints50_1000, categoricalFeatures, 0)
+
+ // RF with one tree should have the same variance as that of the tree.
+ val rf = new RandomForestRegressor()
+ .setImpurity("variance")
+ .setMaxDepth(30)
+ .setNumTrees(1)
+ .setMaxBins(10)
+ .setFeatureSubsetStrategy("all")
+ .setSubsamplingRate(1.0)
+ .setSeed(123)
+
+ val rfModel = rf.fit(df)
+ val rfVariances = rfModel.transform(df).select("variance").collect()
+
+ val dt = new DecisionTreeRegressor()
+ .setImpurity("variance")
+ .setMaxDepth(30)
+ .setMaxBins(10)
+ .setSeed(123)
+ val dtModel = dt.fit(df)
+ val dtVariances = dtModel.transform(df).select("variance").collect()
+ val nSamples = dtVariances.size
+ (0 to nSamples - 1).foreach { i =>
+ assert(rfVariances(i).getDouble(0) ~== dtVariances(i).getDouble(0) absTol 1e-6)
+ }
+
+ rf.setMaxDepth(2)
+ rf.setNumTrees(20)
+ val rfNewModel = rf.fit(df)
+ val results = rfNewModel.transform(df).select("features", "variance").collect()
+ val features = col("features")
+ val trees = rfNewModel.trees
+ val numTrees = rfNewModel.getNumTrees
+ results.map { case Row(features: Vector, variance: Double) =>
+ val rootNodes = trees.map(_.rootNode.predictImpl(features))
--- End diff --
This is not root nodes for each trees, may be it can be named ```predictionNodes```.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r70639350
--- Diff: mllib/src/test/scala/org/apache/spark/ml/regression/RandomForestRegressorSuite.scala ---
@@ -105,6 +109,54 @@ class RandomForestRegressorSuite extends SparkFunSuite with MLlibTestSparkContex
}
}
+ test("Random Forest variance") {
+ val categoricalFeatures = Map.empty[Int, Int]
+ val df: DataFrame = TreeTests.setMetadata(
+ orderedLabeledPoints50_1000, categoricalFeatures, 0)
+
+ // RF with one tree should have the same variance as that of the tree.
+ val rf = new RandomForestRegressor()
+ .setImpurity("variance")
+ .setMaxDepth(30)
+ .setNumTrees(1)
+ .setMaxBins(10)
+ .setFeatureSubsetStrategy("all")
+ .setSubsamplingRate(1.0)
+ .setSeed(123)
+
+ val rfModel = rf.fit(df)
+ val rfVariances = rfModel.transform(df).select("variance").collect()
+
+ val dt = new DecisionTreeRegressor()
+ .setImpurity("variance")
+ .setMaxDepth(30)
+ .setMaxBins(10)
+ .setSeed(123)
+ val dtModel = dt.fit(df)
+ val dtVariances = dtModel.transform(df).select("variance").collect()
+ val nSamples = dtVariances.size
+ (0 to nSamples - 1).foreach { i =>
+ assert(rfVariances(i).getDouble(0) ~== dtVariances(i).getDouble(0) absTol 1e-6)
+ }
+
+ rf.setMaxDepth(2)
+ rf.setNumTrees(20)
+ val rfNewModel = rf.fit(df)
+ val results = rfNewModel.transform(df).select("features", "variance").collect()
+ val features = col("features")
--- End diff --
This line is never used, remove it.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by sethah <gi...@git.apache.org>.
Github user sethah commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r67747441
--- Diff: mllib/src/test/scala/org/apache/spark/ml/regression/RandomForestRegressorSuite.scala ---
@@ -105,6 +108,55 @@ class RandomForestRegressorSuite extends SparkFunSuite with MLlibTestSparkContex
}
}
+ test("Random Forest variance") {
--- End diff --
These tests will still pass if we ever implement a new impurity type, but the computed variance won't be correct. In fact, the tests in `DecisionTreeRegressorSuite` also fail to capture this. If `impurityStats.calculate()` doesn't always return the variance of the labels then the current implementation won't work. We should add a test here and in DT to ensure that the variance is computed correctly. The best way is probably to construct a fake tree, use some small fake data and ensure that the resulting variance is equal to the formula in the linked paper.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by sethah <gi...@git.apache.org>.
Github user sethah commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r67741186
--- Diff: mllib/src/main/scala/org/apache/spark/ml/regression/RandomForestRegressor.scala ---
@@ -168,15 +173,39 @@ class RandomForestRegressionModel private[ml] (
// Note: We may add support for weights (based on tree performance) later on.
private lazy val _treeWeights: Array[Double] = Array.fill[Double](_trees.length)(1.0)
+ @Since("2.1.0")
+ /** @group getParam */
+ def setVarianceCol(value: String): this.type = set(varianceCol, value)
+
@Since("1.4.0")
override def treeWeights: Array[Double] = _treeWeights
override protected def transformImpl(dataset: Dataset[_]): DataFrame = {
val bcastModel = dataset.sparkSession.sparkContext.broadcast(this)
+
+ var output = dataset
+
val predictUDF = udf { (features: Any) =>
bcastModel.value.predict(features.asInstanceOf[Vector])
}
- dataset.withColumn($(predictionCol), predictUDF(col($(featuresCol))))
+ val predictions = predictUDF(col($(featuresCol)))
+ output = dataset.withColumn($(predictionCol), predictions)
+
+ val varianceUDF = udf { (features: Any) =>
+ val leafNodes = bcastModel.value.returnLeafNodes(features.asInstanceOf[Vector])
+ leafNodes.map { leafNode =>
+ leafNode.impurityStats.calculate() + math.pow(leafNode.prediction, 2)
+ }.sum / getNumTrees
+ }
+ val variance = varianceUDF(col($(featuresCol)))
+
+ output = output.withColumn($(varianceCol), variance - pow(predictions, 2))
+ output.toDF
+ }
+
+ private def returnLeafNodes(features: Vector): Array[LeafNode] = {
--- End diff --
This is only used once, I don't think it merits its own function.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by MechCoder <gi...@git.apache.org>.
Github user MechCoder commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r68985017
--- Diff: mllib/src/main/scala/org/apache/spark/ml/regression/RandomForestRegressor.scala ---
@@ -168,15 +173,39 @@ class RandomForestRegressionModel private[ml] (
// Note: We may add support for weights (based on tree performance) later on.
private lazy val _treeWeights: Array[Double] = Array.fill[Double](_trees.length)(1.0)
+ @Since("2.1.0")
+ /** @group getParam */
+ def setVarianceCol(value: String): this.type = set(varianceCol, value)
+
@Since("1.4.0")
override def treeWeights: Array[Double] = _treeWeights
override protected def transformImpl(dataset: Dataset[_]): DataFrame = {
val bcastModel = dataset.sparkSession.sparkContext.broadcast(this)
+
+ var output = dataset
+
val predictUDF = udf { (features: Any) =>
bcastModel.value.predict(features.asInstanceOf[Vector])
}
- dataset.withColumn($(predictionCol), predictUDF(col($(featuresCol))))
+ val predictions = predictUDF(col($(featuresCol)))
+ output = dataset.withColumn($(predictionCol), predictions)
+
+ val varianceUDF = udf { (features: Any) =>
+ val leafNodes = bcastModel.value.returnLeafNodes(features.asInstanceOf[Vector])
+ leafNodes.map { leafNode =>
--- End diff --
Nice! I'll address this for the `RandomForest` here and we can move the decision tree test strengthening to another PR.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/13650
**[Test build #60436 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/60436/consoleFull)** for PR 13650 at commit [`0e4e82f`](https://github.com/apache/spark/commit/0e4e82fb778e94aa4641b63e09d848a0362e5939).
* This patch passes all tests.
* This patch merges cleanly.
* This patch adds no public classes.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/13650
Merged build finished. Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/13650
Merged build finished. Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/13650
**[Test build #64093 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64093/consoleFull)** for PR 13650 at commit [`505e3c2`](https://github.com/apache/spark/commit/505e3c289f19f5d04f9fd51d8f5050822f155738).
* This patch passes all tests.
* This patch merges cleanly.
* This patch adds no public classes.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by MechCoder <gi...@git.apache.org>.
Github user MechCoder commented on the issue:
https://github.com/apache/spark/pull/13650
cc: @yanboliang @MLnick
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/13650
**[Test build #60436 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/60436/consoleFull)** for PR 13650 at commit [`0e4e82f`](https://github.com/apache/spark/commit/0e4e82fb778e94aa4641b63e09d848a0362e5939).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r70637181
--- Diff: mllib/src/test/scala/org/apache/spark/ml/regression/RandomForestRegressorSuite.scala ---
@@ -105,6 +109,54 @@ class RandomForestRegressorSuite extends SparkFunSuite with MLlibTestSparkContex
}
}
+ test("Random Forest variance") {
+ val categoricalFeatures = Map.empty[Int, Int]
+ val df: DataFrame = TreeTests.setMetadata(
+ orderedLabeledPoints50_1000, categoricalFeatures, 0)
+
+ // RF with one tree should have the same variance as that of the tree.
+ val rf = new RandomForestRegressor()
+ .setImpurity("variance")
+ .setMaxDepth(30)
+ .setNumTrees(1)
+ .setMaxBins(10)
+ .setFeatureSubsetStrategy("all")
+ .setSubsamplingRate(1.0)
+ .setSeed(123)
+
+ val rfModel = rf.fit(df)
+ val rfVariances = rfModel.transform(df).select("variance").collect()
+
+ val dt = new DecisionTreeRegressor()
+ .setImpurity("variance")
+ .setMaxDepth(30)
+ .setMaxBins(10)
+ .setSeed(123)
+ val dtModel = dt.fit(df)
+ val dtVariances = dtModel.transform(df).select("variance").collect()
+ val nSamples = dtVariances.size
+ (0 to nSamples - 1).foreach { i =>
+ assert(rfVariances(i).getDouble(0) ~== dtVariances(i).getDouble(0) absTol 1e-6)
+ }
+
+ rf.setMaxDepth(2)
+ rf.setNumTrees(20)
+ val rfNewModel = rf.fit(df)
+ val results = rfNewModel.transform(df).select("features", "variance").collect()
+ val features = col("features")
+ val trees = rfNewModel.trees
+ val numTrees = rfNewModel.getNumTrees
+ results.map { case Row(features: Vector, variance: Double) =>
--- End diff --
```results.foreach```
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on the issue:
https://github.com/apache/spark/pull/13650
@MechCoder Sorry for late response. I will make a pass soon.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/13650
Merged build finished. Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r70638775
--- Diff: mllib/src/test/scala/org/apache/spark/ml/regression/RandomForestRegressorSuite.scala ---
@@ -105,6 +109,54 @@ class RandomForestRegressorSuite extends SparkFunSuite with MLlibTestSparkContex
}
}
+ test("Random Forest variance") {
+ val categoricalFeatures = Map.empty[Int, Int]
+ val df: DataFrame = TreeTests.setMetadata(
+ orderedLabeledPoints50_1000, categoricalFeatures, 0)
+
+ // RF with one tree should have the same variance as that of the tree.
+ val rf = new RandomForestRegressor()
+ .setImpurity("variance")
+ .setMaxDepth(30)
+ .setNumTrees(1)
+ .setMaxBins(10)
+ .setFeatureSubsetStrategy("all")
+ .setSubsamplingRate(1.0)
+ .setSeed(123)
+
+ val rfModel = rf.fit(df)
+ val rfVariances = rfModel.transform(df).select("variance").collect()
+
+ val dt = new DecisionTreeRegressor()
+ .setImpurity("variance")
+ .setMaxDepth(30)
+ .setMaxBins(10)
+ .setSeed(123)
+ val dtModel = dt.fit(df)
+ val dtVariances = dtModel.transform(df).select("variance").collect()
+ val nSamples = dtVariances.size
+ (0 to nSamples - 1).foreach { i =>
+ assert(rfVariances(i).getDouble(0) ~== dtVariances(i).getDouble(0) absTol 1e-6)
+ }
+
+ rf.setMaxDepth(2)
+ rf.setNumTrees(20)
+ val rfNewModel = rf.fit(df)
+ val results = rfNewModel.transform(df).select("features", "variance").collect()
+ val features = col("features")
+ val trees = rfNewModel.trees
+ val numTrees = rfNewModel.getNumTrees
+ results.map { case Row(features: Vector, variance: Double) =>
+ val rootNodes = trees.map(_.rootNode.predictImpl(features))
+ val predsquared = rootNodes.map(x => math.pow(x.prediction, 2)).sum / numTrees
+ val treeVariance = rootNodes.map(_.impurityStats.calculate()).sum / numTrees
+ val predictions = rootNodes.map(_.prediction).sum / numTrees
--- End diff --
```predictions``` -> ```avgPrediction```
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/13650
**[Test build #61480 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/61480/consoleFull)** for PR 13650 at commit [`0048cc8`](https://github.com/apache/spark/commit/0048cc8e89d20a5d989ef990ff4e25008ac2a316).
* This patch passes all tests.
* This patch merges cleanly.
* This patch adds no public classes.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/13650
Merged build finished. Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r70638276
--- Diff: mllib/src/test/scala/org/apache/spark/ml/regression/RandomForestRegressorSuite.scala ---
@@ -105,6 +109,54 @@ class RandomForestRegressorSuite extends SparkFunSuite with MLlibTestSparkContex
}
}
+ test("Random Forest variance") {
+ val categoricalFeatures = Map.empty[Int, Int]
+ val df: DataFrame = TreeTests.setMetadata(
+ orderedLabeledPoints50_1000, categoricalFeatures, 0)
+
+ // RF with one tree should have the same variance as that of the tree.
+ val rf = new RandomForestRegressor()
+ .setImpurity("variance")
+ .setMaxDepth(30)
+ .setNumTrees(1)
+ .setMaxBins(10)
+ .setFeatureSubsetStrategy("all")
+ .setSubsamplingRate(1.0)
+ .setSeed(123)
+
+ val rfModel = rf.fit(df)
+ val rfVariances = rfModel.transform(df).select("variance").collect()
+
+ val dt = new DecisionTreeRegressor()
+ .setImpurity("variance")
+ .setMaxDepth(30)
+ .setMaxBins(10)
+ .setSeed(123)
+ val dtModel = dt.fit(df)
+ val dtVariances = dtModel.transform(df).select("variance").collect()
+ val nSamples = dtVariances.size
+ (0 to nSamples - 1).foreach { i =>
+ assert(rfVariances(i).getDouble(0) ~== dtVariances(i).getDouble(0) absTol 1e-6)
+ }
+
+ rf.setMaxDepth(2)
+ rf.setNumTrees(20)
+ val rfNewModel = rf.fit(df)
+ val results = rfNewModel.transform(df).select("features", "variance").collect()
+ val features = col("features")
+ val trees = rfNewModel.trees
+ val numTrees = rfNewModel.getNumTrees
+ results.map { case Row(features: Vector, variance: Double) =>
+ val rootNodes = trees.map(_.rootNode.predictImpl(features))
+ val predsquared = rootNodes.map(x => math.pow(x.prediction, 2)).sum / numTrees
--- End diff --
```averagePredSquared```
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by sethah <gi...@git.apache.org>.
Github user sethah commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r67741020
--- Diff: mllib/src/main/scala/org/apache/spark/ml/param/shared/sharedParams.scala ---
@@ -149,6 +149,8 @@ private[ml] trait HasVarianceCol extends Params {
*/
final val varianceCol: Param[String] = new Param[String](this, "varianceCol", "Column name for the biased sample variance of prediction")
+ setDefault(varianceCol, "variance")
--- End diff --
You should not modify this file directly. Update `SharedParamsCodeGen.scala` instead.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r70601786
--- Diff: mllib/src/main/scala/org/apache/spark/ml/regression/RandomForestRegressor.scala ---
@@ -168,15 +173,37 @@ class RandomForestRegressionModel private[ml] (
// Note: We may add support for weights (based on tree performance) later on.
private lazy val _treeWeights: Array[Double] = Array.fill[Double](_trees.length)(1.0)
+ @Since("2.1.0")
+ /** @group getParam */
--- End diff --
```getParam``` -> ```setParam```
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by sethah <gi...@git.apache.org>.
Github user sethah commented on the issue:
https://github.com/apache/spark/pull/13650
@MechCoder I made a pass. The biggest concern is making sure the tests will fail if we implement different impurities in the future.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r70603646
--- Diff: mllib/src/main/scala/org/apache/spark/ml/param/shared/SharedParamsCodeGen.scala ---
@@ -44,7 +44,8 @@ private[shared] object SharedParamsCodeGen {
" probabilities. Note: Not all models output well-calibrated probability estimates!" +
" These probabilities should be treated as confidences, not precise probabilities",
Some("\"probability\"")),
- ParamDesc[String]("varianceCol", "Column name for the biased sample variance of prediction"),
+ ParamDesc[String]("varianceCol", "Column name for the biased sample variance of prediction",
+ Some("\"variance\"")),
--- End diff --
I'd like this change, although we did not output variance column by default at #8866. Consider that we have default value for ```probabilityCol```, I think it's ok to add default value for ```varianceCol```.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r70607457
--- Diff: mllib/src/main/scala/org/apache/spark/ml/regression/RandomForestRegressor.scala ---
@@ -168,15 +173,37 @@ class RandomForestRegressionModel private[ml] (
// Note: We may add support for weights (based on tree performance) later on.
private lazy val _treeWeights: Array[Double] = Array.fill[Double](_trees.length)(1.0)
+ @Since("2.1.0")
+ /** @group getParam */
+ def setVarianceCol(value: String): this.type = set(varianceCol, value)
+
@Since("1.4.0")
override def treeWeights: Array[Double] = _treeWeights
+ private def predictVariance(features: Vector): Double = {
+ val meanSumOfPredictionsAndVariance = _trees.map { tree =>
+ val leafNode = tree.rootNode.predictImpl(features)
+ leafNode.impurityStats.calculate() + math.pow(leafNode.prediction, 2)
+ }.sum / getNumTrees
+ meanSumOfPredictionsAndVariance - math.pow(predict(features), 2)
+ }
+
override protected def transformImpl(dataset: Dataset[_]): DataFrame = {
val bcastModel = dataset.sparkSession.sparkContext.broadcast(this)
+
+ var output = dataset
+
val predictUDF = udf { (features: Any) =>
bcastModel.value.predict(features.asInstanceOf[Vector])
}
- dataset.withColumn($(predictionCol), predictUDF(col($(featuresCol))))
+ val predictions = predictUDF(col($(featuresCol)))
+ output = dataset.withColumn($(predictionCol), predictions)
+
+ val predictVarianceUDF = udf { (features: Any) =>
+ bcastModel.value.predictVariance(features.asInstanceOf[Vector])
+ }
+ output = output.withColumn($(varianceCol), predictVarianceUDF(col($(featuresCol))))
+ output.toDF
--- End diff --
Could we directly use ```output.withColumn($(varianceCol), predictVarianceUDF(col($(featuresCol))))```?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by sethah <gi...@git.apache.org>.
Github user sethah commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r71028688
--- Diff: mllib/src/main/scala/org/apache/spark/ml/regression/RandomForestRegressor.scala ---
@@ -168,15 +173,37 @@ class RandomForestRegressionModel private[ml] (
// Note: We may add support for weights (based on tree performance) later on.
private lazy val _treeWeights: Array[Double] = Array.fill[Double](_trees.length)(1.0)
+ @Since("2.1.0")
+ /** @group getParam */
+ def setVarianceCol(value: String): this.type = set(varianceCol, value)
+
@Since("1.4.0")
override def treeWeights: Array[Double] = _treeWeights
+ private def predictVariance(features: Vector): Double = {
--- End diff --
I took a closer look at the methodology in the paper. If you view the prediction of a random forest as the mean of several random variables (the predictions of each tree) then computing the variance of the prediction would require knowledge of the covariances of the individual rvs. We don't track that. The methodology in the paper gets around this by assuming that the prediction from a random forest is done by randomly selecting a single tree and then using that tree's prediction as the overall prediction. So, AFAICT, the methodology in the paper does not apply here, though it might be "better than nothing", but then again it might be worse to mislead users. I'm curious to hear others' thoughts on this.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by MechCoder <gi...@git.apache.org>.
Github user MechCoder commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r69039559
--- Diff: mllib/src/test/scala/org/apache/spark/ml/regression/RandomForestRegressorSuite.scala ---
@@ -105,6 +108,55 @@ class RandomForestRegressorSuite extends SparkFunSuite with MLlibTestSparkContex
}
}
+ test("Random Forest variance") {
--- End diff --
The first test is meant to pass for all impurities, since it compares the variance of a forest with one tree (with bootstrapping set off). You are right, that we have to be deterministic about checking the predicted variances. I have done it for the DecisionTrees here (https://github.com/apache/spark/pull/13981) but not sure it is straightforward for a RandomForest....
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r70638644
--- Diff: mllib/src/test/scala/org/apache/spark/ml/regression/RandomForestRegressorSuite.scala ---
@@ -105,6 +109,54 @@ class RandomForestRegressorSuite extends SparkFunSuite with MLlibTestSparkContex
}
}
+ test("Random Forest variance") {
+ val categoricalFeatures = Map.empty[Int, Int]
+ val df: DataFrame = TreeTests.setMetadata(
+ orderedLabeledPoints50_1000, categoricalFeatures, 0)
+
+ // RF with one tree should have the same variance as that of the tree.
+ val rf = new RandomForestRegressor()
+ .setImpurity("variance")
+ .setMaxDepth(30)
+ .setNumTrees(1)
+ .setMaxBins(10)
+ .setFeatureSubsetStrategy("all")
+ .setSubsamplingRate(1.0)
+ .setSeed(123)
+
+ val rfModel = rf.fit(df)
+ val rfVariances = rfModel.transform(df).select("variance").collect()
+
+ val dt = new DecisionTreeRegressor()
+ .setImpurity("variance")
+ .setMaxDepth(30)
+ .setMaxBins(10)
+ .setSeed(123)
+ val dtModel = dt.fit(df)
+ val dtVariances = dtModel.transform(df).select("variance").collect()
+ val nSamples = dtVariances.size
+ (0 to nSamples - 1).foreach { i =>
+ assert(rfVariances(i).getDouble(0) ~== dtVariances(i).getDouble(0) absTol 1e-6)
+ }
+
+ rf.setMaxDepth(2)
+ rf.setNumTrees(20)
+ val rfNewModel = rf.fit(df)
+ val results = rfNewModel.transform(df).select("features", "variance").collect()
+ val features = col("features")
+ val trees = rfNewModel.trees
+ val numTrees = rfNewModel.getNumTrees
+ results.map { case Row(features: Vector, variance: Double) =>
+ val rootNodes = trees.map(_.rootNode.predictImpl(features))
+ val predsquared = rootNodes.map(x => math.pow(x.prediction, 2)).sum / numTrees
+ val treeVariance = rootNodes.map(_.impurityStats.calculate()).sum / numTrees
--- End diff --
```treeVariance``` -> ```avgTreeVariance```
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r70637087
--- Diff: mllib/src/test/scala/org/apache/spark/ml/regression/RandomForestRegressorSuite.scala ---
@@ -105,6 +109,54 @@ class RandomForestRegressorSuite extends SparkFunSuite with MLlibTestSparkContex
}
}
+ test("Random Forest variance") {
+ val categoricalFeatures = Map.empty[Int, Int]
+ val df: DataFrame = TreeTests.setMetadata(
+ orderedLabeledPoints50_1000, categoricalFeatures, 0)
+
+ // RF with one tree should have the same variance as that of the tree.
+ val rf = new RandomForestRegressor()
+ .setImpurity("variance")
+ .setMaxDepth(30)
+ .setNumTrees(1)
+ .setMaxBins(10)
+ .setFeatureSubsetStrategy("all")
+ .setSubsamplingRate(1.0)
+ .setSeed(123)
+
+ val rfModel = rf.fit(df)
+ val rfVariances = rfModel.transform(df).select("variance").collect()
+
+ val dt = new DecisionTreeRegressor()
+ .setImpurity("variance")
+ .setMaxDepth(30)
+ .setMaxBins(10)
+ .setSeed(123)
+ val dtModel = dt.fit(df)
+ val dtVariances = dtModel.transform(df).select("variance").collect()
+ val nSamples = dtVariances.size
+ (0 to nSamples - 1).foreach { i =>
--- End diff --
Nit: ```(0 until nSamples)```
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on the issue:
https://github.com/apache/spark/pull/13650
@MechCoder It seems there is a typo in the PR's description:
```
The variance is calculated by summing up the mean of the variance of each decision tree + mean of the prediction^2 of each tree + square(mean of the prediction of each tree)
```
It should be:
```
The variance is calculated by summing up the mean of the variance of each decision tree + mean of the prediction^2 of each tree - square(mean of the prediction of each tree)
```
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/13650
**[Test build #61480 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/61480/consoleFull)** for PR 13650 at commit [`0048cc8`](https://github.com/apache/spark/commit/0048cc8e89d20a5d989ef990ff4e25008ac2a316).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/13650
Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/64093/
Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/13650
**[Test build #60435 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/60435/consoleFull)** for PR 13650 at commit [`75254c9`](https://github.com/apache/spark/commit/75254c91cf8d9c2f3638a3f9b1cfd5c029e10996).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r70607599
--- Diff: mllib/src/main/scala/org/apache/spark/ml/regression/RandomForestRegressor.scala ---
@@ -168,15 +173,37 @@ class RandomForestRegressionModel private[ml] (
// Note: We may add support for weights (based on tree performance) later on.
private lazy val _treeWeights: Array[Double] = Array.fill[Double](_trees.length)(1.0)
+ @Since("2.1.0")
+ /** @group getParam */
+ def setVarianceCol(value: String): this.type = set(varianceCol, value)
+
@Since("1.4.0")
override def treeWeights: Array[Double] = _treeWeights
+ private def predictVariance(features: Vector): Double = {
--- End diff --
Add annotation about the reference paper and formula.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/13650
**[Test build #60435 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/60435/consoleFull)** for PR 13650 at commit [`75254c9`](https://github.com/apache/spark/commit/75254c91cf8d9c2f3638a3f9b1cfd5c029e10996).
* This patch passes all tests.
* This patch merges cleanly.
* This patch adds no public classes.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by sethah <gi...@git.apache.org>.
Github user sethah commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r67746985
--- Diff: mllib/src/test/scala/org/apache/spark/ml/regression/RandomForestRegressorSuite.scala ---
@@ -105,6 +108,55 @@ class RandomForestRegressorSuite extends SparkFunSuite with MLlibTestSparkContex
}
}
+ test("Random Forest variance") {
+ val categoricalFeatures = Map.empty[Int, Int]
+ val df: DataFrame = TreeTests.setMetadata(
+ orderedLabeledPoints50_1000, categoricalFeatures, 0)
+
+ // RF with one tree should have the same variance as that of the tree.
+ val rf = new RandomForestRegressor()
+ .setImpurity("variance")
+ .setMaxDepth(30)
+ .setNumTrees(1)
+ .setMaxBins(10)
+ .setFeatureSubsetStrategy("all")
+ .setSubsamplingRate(1.0)
+ .setSeed(123)
+
+ val rfModel = rf.fit(df)
+ val rfVariances = rfModel.transform(df).select("variance").collect()
+
+ val dt = new DecisionTreeRegressor()
+ .setImpurity("variance")
+ .setMaxDepth(30)
+ .setMaxBins(10)
+ .setSeed(123)
+ val dtModel = dt.fit(df)
+ val dtVariances = dtModel.transform(df).select("variance").collect()
+ val nSamples = dtVariances.size
+ (0 to nSamples - 1).foreach { i =>
+ val diff = math.abs(rfVariances(i).getDouble(0) - dtVariances(i).getDouble(0))
+ assert(diff < 1e-6)
+ }
+
+ rf.setMaxDepth(2)
+ rf.setNumTrees(20)
+ val rfNewModel = rf.fit(df)
+ val results = rfNewModel.transform(df).select("features", "variance").collect()
+ val features = col("features")
+ val trees = rfNewModel.trees
+ val numTrees = rfNewModel.getNumTrees
+ results.map { case Row(features: Vector, variance: Double) =>
+ val rootNodes = trees.map(_.rootNode.predictImpl(features))
+ val predsquared = rootNodes.map(x => math.pow(x.prediction, 2)).sum / numTrees
+ val variance = rootNodes.map(_.impurityStats.calculate()).sum / numTrees
+ val predictions = rootNodes.map(_.prediction).sum / numTrees
+ val expectedVariance = -math.pow(predictions, 2) + variance + predsquared
+ assert(variance === expectedVariance,
+ s"Expected variance $expectedVariance but got $variance.")
--- End diff --
I believe you are using the wrong variance here, since you re-use that variable name.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/13650
Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/60436/
Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by sethah <gi...@git.apache.org>.
Github user sethah commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r67743994
--- Diff: mllib/src/test/scala/org/apache/spark/ml/regression/RandomForestRegressorSuite.scala ---
@@ -105,6 +108,55 @@ class RandomForestRegressorSuite extends SparkFunSuite with MLlibTestSparkContex
}
}
+ test("Random Forest variance") {
+ val categoricalFeatures = Map.empty[Int, Int]
+ val df: DataFrame = TreeTests.setMetadata(
+ orderedLabeledPoints50_1000, categoricalFeatures, 0)
+
+ // RF with one tree should have the same variance as that of the tree.
+ val rf = new RandomForestRegressor()
+ .setImpurity("variance")
+ .setMaxDepth(30)
+ .setNumTrees(1)
+ .setMaxBins(10)
+ .setFeatureSubsetStrategy("all")
+ .setSubsamplingRate(1.0)
+ .setSeed(123)
+
+ val rfModel = rf.fit(df)
+ val rfVariances = rfModel.transform(df).select("variance").collect()
+
+ val dt = new DecisionTreeRegressor()
+ .setImpurity("variance")
+ .setMaxDepth(30)
+ .setMaxBins(10)
+ .setSeed(123)
+ val dtModel = dt.fit(df)
+ val dtVariances = dtModel.transform(df).select("variance").collect()
+ val nSamples = dtVariances.size
+ (0 to nSamples - 1).foreach { i =>
+ val diff = math.abs(rfVariances(i).getDouble(0) - dtVariances(i).getDouble(0))
--- End diff --
you should be able to use:
`assert(rfVariances(i).getDouble(0) ~== dtVariances(i).getDouble(0) absTol 1e-6)`
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/13650
Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/61478/
Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/13650
**[Test build #61478 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/61478/consoleFull)** for PR 13650 at commit [`a48f198`](https://github.com/apache/spark/commit/a48f19828ae1a7be5252d0319b5f6c9b4c8ddc09).
* This patch passes all tests.
* This patch merges cleanly.
* This patch adds no public classes.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/13650
Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/60435/
Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/13650
**[Test build #64093 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64093/consoleFull)** for PR 13650 at commit [`505e3c2`](https://github.com/apache/spark/commit/505e3c289f19f5d04f9fd51d8f5050822f155738).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #13650: [SPARK-9623] [ML] Provide variance for RandomForestRegre...
Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on the issue:
https://github.com/apache/spark/pull/13650
This PR looks good overall, I left some inline comments. Thanks for working on this. @MechCoder
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by sethah <gi...@git.apache.org>.
Github user sethah commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r67740952
--- Diff: mllib/src/main/scala/org/apache/spark/ml/regression/RandomForestRegressor.scala ---
@@ -168,15 +173,39 @@ class RandomForestRegressionModel private[ml] (
// Note: We may add support for weights (based on tree performance) later on.
private lazy val _treeWeights: Array[Double] = Array.fill[Double](_trees.length)(1.0)
+ @Since("2.1.0")
+ /** @group getParam */
+ def setVarianceCol(value: String): this.type = set(varianceCol, value)
+
@Since("1.4.0")
override def treeWeights: Array[Double] = _treeWeights
override protected def transformImpl(dataset: Dataset[_]): DataFrame = {
val bcastModel = dataset.sparkSession.sparkContext.broadcast(this)
+
+ var output = dataset
+
val predictUDF = udf { (features: Any) =>
bcastModel.value.predict(features.asInstanceOf[Vector])
}
- dataset.withColumn($(predictionCol), predictUDF(col($(featuresCol))))
+ val predictions = predictUDF(col($(featuresCol)))
+ output = dataset.withColumn($(predictionCol), predictions)
+
+ val varianceUDF = udf { (features: Any) =>
+ val leafNodes = bcastModel.value.returnLeafNodes(features.asInstanceOf[Vector])
+ leafNodes.map { leafNode =>
--- End diff --
I see that this and the decision tree variance functions rely on the fact that the only currently implemented impurity for regression is `Variance`. If anything else ever gets added then this function will be incorrect. We'll need to make sure that the unit tests will fail in such a case.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r70640862
--- Diff: mllib/src/main/scala/org/apache/spark/ml/regression/RandomForestRegressor.scala ---
@@ -168,15 +173,37 @@ class RandomForestRegressionModel private[ml] (
// Note: We may add support for weights (based on tree performance) later on.
private lazy val _treeWeights: Array[Double] = Array.fill[Double](_trees.length)(1.0)
+ @Since("2.1.0")
+ /** @group getParam */
+ def setVarianceCol(value: String): this.type = set(varianceCol, value)
+
@Since("1.4.0")
override def treeWeights: Array[Double] = _treeWeights
+ private def predictVariance(features: Vector): Double = {
--- End diff --
ping @jkbradley to double check the formula in the academic citation is widely used and accepted.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #13650: [SPARK-9623] [ML] Provide variance for RandomFore...
Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/13650#discussion_r70642695
--- Diff: mllib/src/test/scala/org/apache/spark/ml/regression/RandomForestRegressorSuite.scala ---
@@ -105,6 +108,55 @@ class RandomForestRegressorSuite extends SparkFunSuite with MLlibTestSparkContex
}
}
+ test("Random Forest variance") {
--- End diff --
Should ```test("Random Forest Regression predict variance")``` be better?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org