Github user jkbradley commented on a diff in the pull request:
https://github.com/apache/spark/pull/5330#discussion_r27700338
--- Diff:
mllib/src/main/scala/org/apache/spark/mllib/tree/model/treeEnsembleModels.scala
---
@@ -166,6 +156,56 @@ class GradientBoostedTreesModel(
object GradientBoostedTreesModel extends Loader[GradientBoostedTreesModel]
{
+ /**
+ * Method to compute initial error and prediction as a RDD for the first
+ * iteration of gradient boosting.
+ * @param data RDD of [[org.apache.spark.mllib.regression.LabeledPoint]]
+ * @param initTreeWeight: learning rate assigned to the first tree.
+ * @param initTree: first DecisionTreeModel
+ * @param loss: evaluation metric
+ * @return a RDD with each element being a zip of the prediction and
error
+ * corresponding to every sample.
+ */
+ def computeInitialPredictionAndError(
+ data: RDD[LabeledPoint],
+ initTreeWeight: Double,
+ initTree: DecisionTreeModel, loss: Loss): RDD[(Double, Double)] = {
+ data.map { i =>
+ val pred = initTreeWeight * initTree.predict(i.features)
+ val error = loss.computeError(pred, i.label)
+ (pred, error)
+ }
+ }
+
+ /**
+ * Method to update a zipped predictionError RDD
+ * (as obtained with computeInitialPredictionAndError)
+ * @param data RDD of [[org.apache.spark.mllib.regression.LabeledPoint]]
+ * @param predictionAndError: predictionError RDD
+ * @param currentTreeWeight: learning rate.
+ * @param currentTree: first DecisionTree
+ * @param loss: evaluation metric
+ * @return a RDD with each element being a zip of the prediction and
error
+ * corresponing to each sample.
+ */
+ def updatePredictionError(
+ data: RDD[LabeledPoint],
+ predictionAndError: RDD[(Double, Double)],
+ currentTreeWeight: Double,
+ currentTree: DecisionTreeModel,
+ loss: Loss): RDD[(Double, Double)] = {
+
+ data.zip(predictionAndError).mapPartitions { iter =>
+ iter.map {
+ case (point, (pred, error)) => {
--- End diff --
"point" --> (Use the same variable name for a labeled point everywhere for
consistency. I tend to use "lp")
---
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]