Skip to content
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

[XGBoost4J-Spark] bestIteration and bestScore for early stopping #7095

Merged
merged 3 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,15 @@ public static Booster trainAndSaveCheckpoint(
if (score > bestScore) {
bestScore = score;
bestIteration = iter;
booster.setAttr("best_iteration", String.valueOf(bestIteration));
booster.setAttr("best_score", String.valueOf(bestScore));
}
} else {
if (score < bestScore) {
bestScore = score;
bestIteration = iter;
booster.setAttr("best_iteration", String.valueOf(bestIteration));
booster.setAttr("best_score", String.valueOf(bestScore));
}
}
if (earlyStoppingRounds > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ public void testSetAndGetAttrs() throws XGBoostError {
}});

Map<String, String> attr = booster.getAttrs();
TestCase.assertEquals(attr.size(), 4);
TestCase.assertEquals(attr.size(), 6);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some comments why the attr.size() is equal to 6?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wbo4958 maybe because 2 attributes got added?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I know the extra 2 attrs, but others may be so confused. Better to add some comments here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wbo4958 Yes as attr.size() is 6 because 2 additional attributes are added. The test case is checking setter and getter method and also total number of attributes in the booster object.
I will update the doc to explain best iteration/score.

Any suggestion on adding unit test for these attribute ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checking if the booster is containing best_iteration and best_score?

TestCase.assertEquals(attr.get("testKey1"), "testValue2");
TestCase.assertEquals(attr.get("aa"), "AA");
TestCase.assertEquals(attr.get("bb"), "BB");
Expand Down