Github user sethah commented on a diff in the pull request:
https://github.com/apache/spark/pull/8734#discussion_r50572835
--- Diff:
mllib/src/main/scala/org/apache/spark/ml/tree/impl/RandomForest.scala ---
@@ -740,7 +740,11 @@ private[ml] object RandomForest extends Logging {
val categoryStats =
binAggregates.getImpurityCalculator(nodeFeatureOffset,
featureValue)
val centroid = if (categoryStats.count != 0) {
- categoryStats.predict
+ if (categoryStats.count == 2) {
--- End diff --
I think you meant `categoryStats.stats.length == 2`. `categoryStats.count`
is the count of data points falling into that particular bin. Since we are
trying to determine here whether this is regression or binary classification, I
think checking `if (binAggregates.metadata.isClassification)` is more clear.
Additionally, the code under the if and else statements of
`centroidForCategories` is identical except for a single line. It seems cleaner
to restructure to something like:
```scala
val centroidForCategories = Range(0, numCategories).map { case featureValue
=>
val categoryStats =
binAggregates.getImpurityCalculator(nodeFeatureOffset, featureValue)
val centroid = if (categoryStats.count != 0) {
if (binAggregates.metadata.isMulticlass) {
// multiclass classification
categoryStats.calculate()
} else if (binAggregates.metadata.isClassification) {
// binary classification
categoryStats.stats(1)
} else {
// regression
categoryStats.predict
}
} else {
Double.MaxValue
}
(featureValue, centroid)
}
```
---
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]