Skip to content

Commit e37d0ad

Browse files
committed
catboost fall back
1 parent b4e693d commit e37d0ad

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

ml_grid/pipeline/grid_search_cross_validate.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from scikeras.wrappers import KerasClassifier
1515
from sklearn import metrics
1616
from IPython.display import display
17+
from catboost import CatBoostError
1718
from pandas.testing import assert_index_equal
1819
from xgboost.core import XGBoostError
1920

@@ -326,6 +327,17 @@ def __init__(
326327
# Pass reset data to search
327328
current_algorithm = search.run_search(X_train_reset, y_train_reset)
328329

330+
except CatBoostError as e:
331+
if "All features are either constant or ignored" in str(e):
332+
self.logger.error(f"CatBoostError occurred for {method_name}: {e}")
333+
self.logger.warning(f"Continuing despite CatBoost error...")
334+
# Set a default score and return to allow the pipeline to continue
335+
self.grid_search_cross_validate_score_result = 0.5
336+
return
337+
else:
338+
# Re-raise other CatBoost errors
339+
raise e
340+
329341

330342
except XGBoostError as e:
331343
if 'cuda' in str(e).lower() or 'memory' in str(e).lower():
@@ -618,6 +630,14 @@ def adjust_param(param_value):
618630
elif isinstance(parameter_space, dict) and 'subsample' in parameter_space:
619631
parameter_space['subsample'] = adjust_param(parameter_space['subsample'])
620632

633+
# Also adjust 'rsm' (colsample_bylevel) which can cause the same issue
634+
if isinstance(parameter_space, list):
635+
for params in parameter_space:
636+
if 'rsm' in params:
637+
params['rsm'] = adjust_param(params['rsm'])
638+
elif isinstance(parameter_space, dict) and 'rsm' in parameter_space:
639+
parameter_space['rsm'] = adjust_param(parameter_space['rsm'])
640+
621641

622642
def dummy_auc() -> float:
623643
"""Returns a constant AUC score of 0.5.

0 commit comments

Comments
 (0)