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

[spark] Add validation for param 'early_stopping_rounds' and 'validation_indicator_col' #8250

Merged
merged 5 commits into from Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions python-package/xgboost/spark/core.py
Expand Up @@ -295,6 +295,15 @@ def _validate_params(self):
if not isinstance(self.getOrDefault(self.eval_metric), str):
raise ValueError("Only string type 'eval_metric' param is allowed.")

if self.isDefined(self.early_stopping_rounds):
if not (
self.isDefined(self.validationIndicatorCol) and self.getOrDefault(self.validationIndicatorCol)
):
raise ValueError(
"If 'early_stopping_rounds' param is set, you need to set "
"'validation_indicator_col' param as well."
)

if self.getOrDefault(self.enable_sparse_data_optim):
if self.getOrDefault(self.missing) != 0.0:
# If DMatrix is constructed from csr / csc matrix, then inactive elements
Expand Down
5 changes: 5 additions & 0 deletions tests/python/test_spark/test_spark_local.py
Expand Up @@ -1145,3 +1145,8 @@ def test_empty_partition(self):
num_workers=4,
)
classifier.fit(data_trans)

def test_early_stop_param_validation(self):
classifier = SparkXGBClassifier(early_stopping_rounds=1)
with pytest.raises(ValueError):
classifier.fit(self.cls_df_train)