Skip to content

[SPARK-2152][MLlib] fix bin offset in DecisionTree node aggregations (also resolves SPARK-2160) - #1316

Closed
jonsondag wants to merge 1 commit into
apache:masterfrom
jonsondag:master
Closed

jonsondag wants to merge 1 commit into
apache:masterfrom
jonsondag:master

Conversation

@jonsondag

Copy link
Copy Markdown
Contributor

Hi, this pull fixes (what I believe to be) a bug in DecisionTree.scala.

In the extractLeftRightNodeAggregates function, the first set of rightNodeAgg values for Regression are set in line 792 as follows:

rightNodeAgg(featureIndex)(2 * (numBins - 2))
= binData(shift + (2 * numBins - 1)))

Then there is a loop that sets the rest of the values, as in line 809:

rightNodeAgg(featureIndex)(2 * (numBins - 2 - splitIndex)) =
binData(shift + (2 *(numBins - 2 - splitIndex))) +
rightNodeAgg(featureIndex)(2 * (numBins - 1 - splitIndex))

But since splitIndex starts at 1, this ends up skipping a set of binData values.

The changes here address this issue, for both the Regression and Classification cases.

@AmplabJenkins

Copy link
Copy Markdown

Can one of the admins verify this patch?

@srowen

srowen commented Jul 7, 2014

Copy link
Copy Markdown
Member

This was reported as https://issues.apache.org/jira/browse/SPARK-2152 (and duplicated for some reason as https://issues.apache.org/jira/browse/SPARK-2160) but the author didn't seem to make a PR. You could note this is tied to SPARK-2152 and resolves both.

@jonsondag jonsondag changed the title fix bin offset in DecisionTree node aggregations [SPARK-2152] fix bin offset in DecisionTree node aggregations Jul 7, 2014
@jonsondag jonsondag changed the title [SPARK-2152] fix bin offset in DecisionTree node aggregations [SPARK-2152] fix bin offset in DecisionTree node aggregations (also resolves SPARK-2160) Jul 7, 2014
@jonsondag

Copy link
Copy Markdown
Contributor Author

Thanks, I have edited the subject of this pull request and added comments in JIRA.

@pwendell

pwendell commented Jul 8, 2014

Copy link
Copy Markdown
Contributor

@johnnywalleye mind adding [MLlib] to the title. Then it's more likely to catch @mengxr's eye :)

@jonsondag jonsondag changed the title [SPARK-2152] fix bin offset in DecisionTree node aggregations (also resolves SPARK-2160) [SPARK-2152][MLlib] fix bin offset in DecisionTree node aggregations (also resolves SPARK-2160) Jul 8, 2014
@jonsondag

Copy link
Copy Markdown
Contributor Author

Sure, updated.

@manishamde

Copy link
Copy Markdown
Contributor

@johnnywalleye Thanks! I will review this PR and get back soon.

@jonsondag

Copy link
Copy Markdown
Contributor Author

Great, thanks!

On Tue, Jul 8, 2014 at 5:56 PM, manishamde notifications@github.com wrote:

@johnnywalleye https://github.com/johnnywalleye I will review this PR
and get back soon.

—
Reply to this email directly or view it on GitHub
#1316 (comment).

@manishamde

Copy link
Copy Markdown
Contributor

LGTM! The classic off-by-one error gets you no matter how much attention you pay. Thanks for the rigorous review.

@pwendell Could we also add this to the 1.0 patch release?

@johnnywalleye If possible, could you also update this PR. #886 It's on my repo on branch 'multiclass'. It's easy for me to update this but I am hoping you could review it as well since it's a non-trivial change. :-)

@manishamde

Copy link
Copy Markdown
Contributor

@johnnywalleye Nevermind. I fixed the same error on the multiclass PR.

@asfgit asfgit closed this in 1114207 Jul 9, 2014
asfgit pushed a commit that referenced this pull request Jul 9, 2014
…(also resolves SPARK-2160)

Hi, this pull fixes (what I believe to be) a bug in DecisionTree.scala.

In the extractLeftRightNodeAggregates function, the first set of rightNodeAgg values for Regression are set in line 792 as follows:

rightNodeAgg(featureIndex)(2 * (numBins - 2))
  = binData(shift + (2 * numBins - 1)))

Then there is a loop that sets the rest of the values, as in line 809:

rightNodeAgg(featureIndex)(2 * (numBins - 2 - splitIndex)) =
  binData(shift + (2 *(numBins - 2 - splitIndex))) +
  rightNodeAgg(featureIndex)(2 * (numBins - 1 - splitIndex))

But since splitIndex starts at 1, this ends up skipping a set of binData values.

The changes here address this issue, for both the Regression and Classification cases.

Author: johnnywalleye <jsondag@gmail.com>

Closes #1316 from johnnywalleye/master and squashes the following commits:

73809da [johnnywalleye] fix bin offset in DecisionTree node aggregations

(cherry picked from commit 1114207)
Signed-off-by: Xiangrui Meng <meng@databricks.com>
@mengxr

mengxr commented Jul 9, 2014

Copy link
Copy Markdown
Contributor

Thanks @johnnywalleye for the fix and @manishamde for reviewing the PR! I merged it into both master and branch-1.0, but I'm not sure whether it can make into v1.0.1 . I will update the JIRA if it doesn't.

Btw, I tested this patch locally but let's try calling Jenkins (sorry).

@mengxr

mengxr commented Jul 9, 2014

Copy link
Copy Markdown
Contributor

Jenkins, test this please.

@manishamde

Copy link
Copy Markdown
Contributor

Thanks @mengxr

asfgit pushed a commit that referenced this pull request Jul 9, 2014
Fixes test failures introduced by #1316.

For both the regression and classification cases,
val stats is the InformationGainStats for the best tree split.
stats.predict is the predicted value for the data, before the split is made.
Since 600 of the 1,000 values generated by DecisionTreeSuite.generateCategoricalDataPoints() are 1.0 and the rest 0.0, the regression tree and classification tree both correctly predict a value of 0.6 for this data now, and the assertions have been changed to reflect that.

Author: johnnywalleye <jsondag@gmail.com>

Closes #1343 from johnnywalleye/decision-tree-tests and squashes the following commits:

ef80603 [johnnywalleye] [SPARK-2417][MLlib] Fix DecisionTree tests
asfgit pushed a commit that referenced this pull request Jul 9, 2014
Fixes test failures introduced by #1316.

For both the regression and classification cases,
val stats is the InformationGainStats for the best tree split.
stats.predict is the predicted value for the data, before the split is made.
Since 600 of the 1,000 values generated by DecisionTreeSuite.generateCategoricalDataPoints() are 1.0 and the rest 0.0, the regression tree and classification tree both correctly predict a value of 0.6 for this data now, and the assertions have been changed to reflect that.

Author: johnnywalleye <jsondag@gmail.com>

Closes #1343 from johnnywalleye/decision-tree-tests and squashes the following commits:

ef80603 [johnnywalleye] [SPARK-2417][MLlib] Fix DecisionTree tests

(cherry picked from commit d35e3db)
Signed-off-by: Xiangrui Meng <meng@databricks.com>
gzm55 pushed a commit to MediaV/spark that referenced this pull request Jul 18, 2014
…(also resolves SPARK-2160)

Hi, this pull fixes (what I believe to be) a bug in DecisionTree.scala.

In the extractLeftRightNodeAggregates function, the first set of rightNodeAgg values for Regression are set in line 792 as follows:

rightNodeAgg(featureIndex)(2 * (numBins - 2))
  = binData(shift + (2 * numBins - 1)))

Then there is a loop that sets the rest of the values, as in line 809:

rightNodeAgg(featureIndex)(2 * (numBins - 2 - splitIndex)) =
  binData(shift + (2 *(numBins - 2 - splitIndex))) +
  rightNodeAgg(featureIndex)(2 * (numBins - 1 - splitIndex))

But since splitIndex starts at 1, this ends up skipping a set of binData values.

The changes here address this issue, for both the Regression and Classification cases.

Author: johnnywalleye <jsondag@gmail.com>

Closes apache#1316 from johnnywalleye/master and squashes the following commits:

73809da [johnnywalleye] fix bin offset in DecisionTree node aggregations

(cherry picked from commit 1114207)
Signed-off-by: Xiangrui Meng <meng@databricks.com>
gzm55 pushed a commit to MediaV/spark that referenced this pull request Jul 18, 2014
Fixes test failures introduced by apache#1316.

For both the regression and classification cases,
val stats is the InformationGainStats for the best tree split.
stats.predict is the predicted value for the data, before the split is made.
Since 600 of the 1,000 values generated by DecisionTreeSuite.generateCategoricalDataPoints() are 1.0 and the rest 0.0, the regression tree and classification tree both correctly predict a value of 0.6 for this data now, and the assertions have been changed to reflect that.

Author: johnnywalleye <jsondag@gmail.com>

Closes apache#1343 from johnnywalleye/decision-tree-tests and squashes the following commits:

ef80603 [johnnywalleye] [SPARK-2417][MLlib] Fix DecisionTree tests

(cherry picked from commit d35e3db)
Signed-off-by: Xiangrui Meng <meng@databricks.com>
xiliu82 pushed a commit to xiliu82/spark that referenced this pull request Sep 4, 2014
…(also resolves SPARK-2160)

Hi, this pull fixes (what I believe to be) a bug in DecisionTree.scala.

In the extractLeftRightNodeAggregates function, the first set of rightNodeAgg values for Regression are set in line 792 as follows:

rightNodeAgg(featureIndex)(2 * (numBins - 2))
  = binData(shift + (2 * numBins - 1)))

Then there is a loop that sets the rest of the values, as in line 809:

rightNodeAgg(featureIndex)(2 * (numBins - 2 - splitIndex)) =
  binData(shift + (2 *(numBins - 2 - splitIndex))) +
  rightNodeAgg(featureIndex)(2 * (numBins - 1 - splitIndex))

But since splitIndex starts at 1, this ends up skipping a set of binData values.

The changes here address this issue, for both the Regression and Classification cases.

Author: johnnywalleye <jsondag@gmail.com>

Closes apache#1316 from johnnywalleye/master and squashes the following commits:

73809da [johnnywalleye] fix bin offset in DecisionTree node aggregations
xiliu82 pushed a commit to xiliu82/spark that referenced this pull request Sep 4, 2014
Fixes test failures introduced by apache#1316.

For both the regression and classification cases,
val stats is the InformationGainStats for the best tree split.
stats.predict is the predicted value for the data, before the split is made.
Since 600 of the 1,000 values generated by DecisionTreeSuite.generateCategoricalDataPoints() are 1.0 and the rest 0.0, the regression tree and classification tree both correctly predict a value of 0.6 for this data now, and the assertions have been changed to reflect that.

Author: johnnywalleye <jsondag@gmail.com>

Closes apache#1343 from johnnywalleye/decision-tree-tests and squashes the following commits:

ef80603 [johnnywalleye] [SPARK-2417][MLlib] Fix DecisionTree tests
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Nov 3, 2026
…che#1320)

### What changes were proposed in this pull request?

The Build's "Protobuf breaking change detection and Python CodeGen check" and "Run Spark UI tests" jobs now run only when their own files change. They ran on every pull request.

- **The bug.** The precondition of `.github/workflows/build_and_test.yml` gives each job a file gate: `buf=false` unless a `.proto` or `_pb2` file changes, and `ui=false` unless `ui-test/` or a static UI resource does. Spark's own lines set `buf=true` and `ui=true` unconditionally at the end of the same branch. The gates sat above those lines, so the defaults ran after the gates and undid them. That has been true since the gates were added (apache#89), and both jobs ran on apache#1311, apache#1313 and apache#1316, the last of which changed only plan files.
- **The fix.** `buf=true` and `ui=true` are now set just before the buf gate, and the later block keeps only `docs=true` and `java25=true`. The SparkR, Kubernetes and OIDC gates have no later default and are unchanged.
- **A lint rule keeps the order.** A new `ci-gates` rule in `dev/varka_lint.py` reports a `x=true` at a gate's own depth, later in the same branch, after that gate's `x=false`. The pre-commit hook and the Build's lint self-test both run it. Against master's workflow it reports lines 203 and 204; against this change it reports nothing.
- **Plan.** `sql/varka/plans/m8/VARKA-558.md` and PLAN.md row 558.

### Why are the changes needed?

Each Build spent two runners on jobs that could not fail for the change at hand, about two minutes for the protobuf check and one for the UI suite. They run in parallel with the rest, so the cost is slots on the fork's 40 concurrent jobs, not wall time. The rule matters more than the minutes: a gate that silently does nothing looks the same as one that works.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

- `dev/varka_lint.py --selftest`: 21 cases. Two are new: a gate undone by a later default is reported, and a default set before its gate is not.
- The rule reports master's two lines and nothing on this change.
- Ruff 0.14.8 format and check, the YAML parse, the plan lint, the quote check and the pre-commit hook pass.
- This change itself edits the workflow, which no module of `modules.py` claims, so its own Build runs Spark's whole matrix and both jobs once more. The next pull request that touches neither protobuf nor UI files shows the fix by skipping both.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 5.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants