-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-7127] [MLLIB] Adding broadcast of model before prediction for ensembles #6300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
83904bb
aaad77b
6fd153c
171a6ce
1f34be4
9afad56
40a139d
86e73de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,6 +109,7 @@ object RandomForestClassifier { | |
| RandomForestParams.supportedFeatureSubsetStrategies | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * :: AlphaComponent :: | ||
| * | ||
|
|
@@ -134,13 +135,23 @@ final class RandomForestClassificationModel private[ml] ( | |
|
|
||
| override def treeWeights: Array[Double] = _treeWeights | ||
|
|
||
| override def transform(dataset: DataFrame): DataFrame = { | ||
| val bcastModel = dataset.sqlContext.sparkContext.broadcast(this) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mentioned that we might want to selectively broadcast the model, only if it's large enough. Do you think that is something we can do here automatically, or would it need to be a configuration setting? |
||
| val predictFunc = (features: Vector) => predictImpl(features, () => bcastModel.value) | ||
| transformImpl(dataset, predictFunc) | ||
| } | ||
|
|
||
| override protected def predict(features: Vector): Double = { | ||
| // TODO: Override transform() to broadcast model. SPARK-7127 | ||
| // TODO: When we add a generic Bagging class, handle transform there: SPARK-7128 | ||
| // Predict without using a broadcasted model | ||
| predictImpl(features, () => this) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still want to support prediction without broadcasting?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we will want to. If it's a small model, then it can be faster to not broadcast it. |
||
| } | ||
|
|
||
| protected def predictImpl(features: Vector, modelAccesor: () => TreeEnsembleModel): Double = { | ||
| // Classifies using majority votes. | ||
| // Ignore the weights since all are 1.0 for now. | ||
| val votes = mutable.Map.empty[Int, Double] | ||
| _trees.view.foreach { tree => | ||
| modelAccesor().trees.view.foreach { tree => | ||
| val prediction = tree.rootNode.predict(features).toInt | ||
| votes(prediction) = votes.getOrElse(prediction, 0.0) + 1.0 // 1.0 = weight | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could call: