[jvm-packages]Fix early stopping condition (#3928)
* add back train method but mark as deprecated * add back train method but mark as deprecated * add back train method but mark as deprecated * add back train method but mark as deprecated * fix scalastyle error * fix scalastyle error * fix scalastyle error * fix scalastyle error * update version * 0.82 * fix early stopping condition * remove unused * update comments * udpate comments * update test
This commit is contained in:
@@ -218,8 +218,15 @@ public class XGBoost {
|
||||
Map<String, Object> params, int earlyStoppingRounds, float[][] metrics, int iter) {
|
||||
boolean maximizeEvaluationMetrics = getMetricsExpectedDirection(params);
|
||||
boolean onTrack = false;
|
||||
// we don't need to consider iterations before reaching to `earlyStoppingRounds`th iteration
|
||||
if (iter < earlyStoppingRounds - 1) {
|
||||
return true;
|
||||
}
|
||||
float[] criterion = metrics[metrics.length - 1];
|
||||
for (int shift = 0; shift < Math.min(iter, earlyStoppingRounds) - 1; shift++) {
|
||||
for (int shift = 0; shift < earlyStoppingRounds - 1; shift++) {
|
||||
// the initial value of onTrack is false and if the metrics in any of `earlyStoppingRounds`
|
||||
// iterations goes to the expected direction, we should consider these `earlyStoppingRounds`
|
||||
// as `onTrack`
|
||||
onTrack |= maximizeEvaluationMetrics ?
|
||||
criterion[iter - shift] >= criterion[iter - shift - 1] :
|
||||
criterion[iter - shift] <= criterion[iter - shift - 1];
|
||||
|
||||
Reference in New Issue
Block a user