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

Suggestion for "Control logging for early stopping using shouldPrint() XGBoost.java" #7326

Merged
merged 3 commits into from
Oct 21, 2021
Merged
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
@@ -1,5 +1,5 @@
/*
Copyright (c) 2014 by Contributors
Copyright (c) 2014,2021 by Contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

/**
* trainer for xgboost
Expand Down Expand Up @@ -253,13 +252,14 @@ public static Booster trainAndSaveCheckpoint(
booster.setAttr("best_score", String.valueOf(bestScore));
}
}
if (earlyStoppingRounds > 0) {
if (shouldEarlyStop(earlyStoppingRounds, iter, bestIteration)) {
if (shouldEarlyStop(earlyStoppingRounds, iter, bestIteration)) {
if (shouldPrint(params, iter)) {
Rabit.trackerPrint(String.format(
"early stopping after %d rounds away from the best iteration",
earlyStoppingRounds));
break;
"early stopping after %d rounds away from the best iteration",
earlyStoppingRounds
));
}
break;
}
if (Rabit.getRank() == 0 && shouldPrint(params, iter)) {
if (shouldPrint(params, iter)){
Expand Down Expand Up @@ -352,6 +352,9 @@ private static boolean shouldPrint(Map<String, Object> params, int iter) {
}

static boolean shouldEarlyStop(int earlyStoppingRounds, int iter, int bestIteration) {
if (earlyStoppingRounds <= 0) {
return false;
}
return iter - bestIteration >= earlyStoppingRounds;
}

Expand Down