Skip to content

Commit

Permalink
[XGBoost4J-Spark] bestIteration and bestScore for early stopping (#7095)
Browse files Browse the repository at this point in the history
  • Loading branch information
naveenkb authored Jul 19, 2021
1 parent d7c1449 commit 9f7f8b9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
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);
TestCase.assertEquals(attr.get("testKey1"), "testValue2");
TestCase.assertEquals(attr.get("aa"), "AA");
TestCase.assertEquals(attr.get("bb"), "BB");
Expand Down

0 comments on commit 9f7f8b9

Please sign in to comment.