Github user mengxr commented on a diff in the pull request:
https://github.com/apache/spark/pull/1975#discussion_r16322130
--- Diff:
mllib/src/main/scala/org/apache/spark/mllib/tree/DecisionTree.scala ---
@@ -198,29 +214,22 @@ class DecisionTree (private val strategy: Strategy)
extends Serializable with Lo
index: Int,
maxDepth: Int,
nodeSplitStats: (Split, InformationGainStats),
- parentImpurities: Array[Double],
- filters: Array[List[Filter]]): Unit = {
+ parentImpurities: Array[Double]): Unit = {
+ if (level >= maxDepth)
+ return
// 0 corresponds to the left child node and 1 corresponds to the right
child node.
var i = 0
while (i <= 1) {
- // Calculate the index of the node from the node level and the index
at the current level.
+ // Calculate the index of the node from the node level and the index
at the current level.
val nodeIndex = math.pow(2, level + 1).toInt - 1 + 2 * index + i
- if (level < maxDepth) {
- val impurity = if (i == 0) {
- nodeSplitStats._2.leftImpurity
- } else {
- nodeSplitStats._2.rightImpurity
- }
- logDebug("nodeIndex = " + nodeIndex + ", impurity = " + impurity)
- // noting the parent impurities
- parentImpurities(nodeIndex) = impurity
- // noting the parents filters for the child nodes
- val childFilter = new Filter(nodeSplitStats._1, if (i == 0) -1
else 1)
- filters(nodeIndex) = childFilter :: filters((nodeIndex - 1) / 2)
- for (filter <- filters(nodeIndex)) {
- logDebug("Filter = " + filter)
- }
+ val impurity = if (i == 0) {
+ nodeSplitStats._2.leftImpurity
+ } else {
+ nodeSplitStats._2.rightImpurity
}
+ logDebug("nodeIndex = " + nodeIndex + ", impurity = " + impurity)
+ // noting the parent impurities
+ parentImpurities(nodeIndex) = impurity
--- End diff --
Since most of the code is removed, maybe we can unfold the while loop:
~~~
val leftNodeIndex = math.pow(2, level + 1).toInt - 1 + 2 * index
parentImpurities(leftNodeIndex) = nodeSplitStats._2.leftImpurity
val rightNodeIndex = leftNodeIndex + 1
parentImpurities(rightNodeIndex) = nodeSplitStats._2.rightImpurity
~~~
Btw, could the code be simplified if we don't use `leftNode` and
`rightNode` but `childNodes: Array[Node]`?
---
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]