Github user jkbradley commented on a diff in the pull request:
https://github.com/apache/spark/pull/1950#discussion_r16301157
--- Diff:
mllib/src/main/scala/org/apache/spark/mllib/tree/DecisionTree.scala ---
@@ -689,37 +631,26 @@ object DecisionTree extends Serializable with Logging
{
* bin index for this labeledPoint
* (or InvalidBinIndex if labeledPoint is not handled by
this node)
*/
- def findBinsForLevel(labeledPoint: LabeledPoint): Array[Double] = {
+ def findBinsForLevel(treePoint: TreePoint): Array[Double] = {
// Calculate bin index and label per feature per node.
val arr = new Array[Double](1 + (numFeatures * numNodes))
// First element of the array is the label of the instance.
- arr(0) = labeledPoint.label
+ arr(0) = treePoint.label
// Iterate over nodes.
var nodeIndex = 0
while (nodeIndex < numNodes) {
val parentFilters = findParentFilters(nodeIndex)
// Find out whether the sample qualifies for the particular node.
- val sampleValid = isSampleValid(parentFilters, labeledPoint)
+ val sampleValid = isSampleValid(parentFilters, treePoint)
val shift = 1 + numFeatures * nodeIndex
if (!sampleValid) {
// Mark one bin as -1 is sufficient.
arr(shift) = InvalidBinIndex
} else {
var featureIndex = 0
+ // TODO: Vectorize this
while (featureIndex < numFeatures) {
- val featureInfo =
strategy.categoricalFeaturesInfo.get(featureIndex)
- val isFeatureContinuous = featureInfo.isEmpty
- if (isFeatureContinuous) {
- arr(shift + featureIndex)
- = findBin(featureIndex, labeledPoint, isFeatureContinuous,
false)
- } else {
- val featureCategories = featureInfo.get
- val isSpaceSufficientForAllCategoricalSplits
- = numBins > math.pow(2, featureCategories.toInt - 1) - 1
- arr(shift + featureIndex)
- = findBin(featureIndex, labeledPoint, isFeatureContinuous,
- isSpaceSufficientForAllCategoricalSplits)
- }
+ arr(shift + featureIndex) = treePoint.features(featureIndex)
--- End diff --
I agree with @chouqin that TreePoint simply stores feature values (exactly
the same data as LabeledPoint) for ordered categorical features. We could save
some space by not making a copy of those (up to 2x the storage). The main
issue is that indexing would be a little trickier since we do not separate out
these various features.
@chouqin About the arr structure, I am doing that in my next updates,
where I eliminate that entire part of the aggregation step. I.e., I eliminate
the call to findBinsForLevel() and keep the binMappedRDD.aggregate().
---
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]