Github user Ishiihara commented on a diff in the pull request: https://github.com/apache/spark/pull/2394#discussion_r18106416 --- Diff: mllib/src/main/scala/org/apache/spark/mllib/regression/StochasticGradientBoosting.scala --- @@ -0,0 +1,173 @@ +package org.apache.spark.mllib.regression + +import org.apache.spark.mllib.linalg.Vector +import org.apache.spark.mllib.tree.DecisionTree +import org.apache.spark.mllib.tree.configuration.Algo.Algo +import org.apache.spark.mllib.tree.configuration.Strategy +import org.apache.spark.mllib.tree.impurity.Impurity +import org.apache.spark.mllib.tree.model.DecisionTreeModel +import org.apache.spark.rdd.{DoubleRDDFunctions, RDD} +import scala.util.Random + +/** + * + * Read about the algorithm "Gradient boosting" here: + * http://www.montefiore.ulg.ac.be/services/stochastic/pubs/2007/GWD07/geurts-icml2007.pdf + * + * Libraries that implement the algorithm "Gradient boosting" similar way + * https://code.google.com/p/jforests/ + * https://code.google.com/p/jsgbm/ + * + */ +class StochasticGradientBoosting { + + /** + * Train a Gradient Boosting model given an RDD of (label, features) pairs. + * + * @param input Training dataset: RDD of [[org.apache.spark.mllib.regression.LabeledPoint]]. + * @param leaningRate Learning rate + * @param countOfTrees Number of trees. + * @param samplingSizeRatio Size of random sample, percent of ${input} size. + * @param strategy The configuration parameters for the tree algorithm which specify the type + * of algorithm (classification, regression, etc.), feature type (continuous, + * categorical), depth of the tree, quantile calculation strategy, etc. + * @return StochasticGradientBoostingModel that can be used for prediction + */ + def run( + input : RDD[LabeledPoint], + leaningRate : Double, + countOfTrees : Int, + samplingSizeRatio : Double, + strategy: Strategy): StochasticGradientBoostingModel = { + + val featureDimension = input.count() + val mean = new DoubleRDDFunctions(input.map(l => l.label)).mean() + val boostingModel = new StochasticGradientBoostingModel(countOfTrees, mean, leaningRate) + + for (i <- 0 to countOfTrees - 1) { + val gradient = input.map(l => l.label - boostingModel.computeValue(l.features)) --- End diff -- @mengxr Would it be better if cache input explicitly as it is used many times inside this 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org