Skip to content

Sklearn RFECV doesn't work with categorial columns in Catboost #17338

Closed

Description

@wallnfl

I want to do cross-validated recursive feature elimination with a catboost model on data which contains categorial columns. After i did the follwing:

ts = TimeSeriesSplit(n_splits=n_cv_splits)
model = CatBoostClassifier(iterations=n_iterations, cat_features=categorial_cols, eval_metric='AUC', task_type='GPU')
rfe = RFECV(model, step=1, verbose=2, cv=ts)
rfe = rfe.fit(X, y)

I get the follwing error:
ValueError: could not convert string to float: 'W'

'W' is a value of my first categorial column. Although i told catboost which columns are categorial through the cat_features parameter (in my case i passed it as list of labels), it expected a numerical column. Is this the expected behaviour? Or do i have to integer encode the categories in this use case?

If i call just model.fit(X,y), it works without problems.

Activity

  1. glemaitre commented on May 25, 2020

    @glemaitre
    Member

    You need to encode the categorical features with a ColumnTransformer and an OrdinalEncoder or OneHotEncoder. Scikit-learn does not handle natively the categorical data.

    CatBoostClassifier is handling natively those columns (you still need to pass the column names apparently).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions