uclamii / model_tuner

A library to tune the hyperparameters of common ML models. Supports calibration and custom pipelines.
Apache License 2.0
3 stars 0 forks source link

Runtime and UserWarning Due to Zero-Variance Columns During Grid Search #27

Closed lshpaner closed 2 months ago

lshpaner commented 2 months ago

When performing grid search parameter tuning using model_tuner.grid_search_param_tuning(X, y), I encountered the following issue:

If X contains any zero-variance (constant) columns, the process generates multiple RuntimeWarning and UserWarning messages as shown below:

image

Proposed Solution:

To prevent these warnings, I suggest adding a check before the grid search process starts to identify and drop any zero-variance columns in X. This can be achieved with a simple if block like:

# Check for zero-variance columns and drop them
zero_variance_columns = X.columns[X.var() == 0]
if not zero_variance_columns.empty:
    X = X.drop(columns=zero_variance_columns)

This would help avoid unnecessary warnings and improve the overall robustness of the function.

Steps to Reproduce:

Include a column in X with the same value for all rows. Run model_tuner.grid_search_param_tuning(X, y).

Expected Behavior:

The grid search should proceed without triggering RuntimeWarning or UserWarning messages.

lshpaner commented 2 months ago

Mitigated by adding new section Caveats in documentation

image