0
$\begingroup$

I have a dataset (pandas data frame) with all features of type int32 containing continuous values except one feature state_number, its data type is int32, but it represents different states of a network (category). The feature state_number has 11 unique values. I want to train a cat boost model on this dataset; how can I specify in cat boost to treat it as a category even though it looks like a number? So far I have tried these steps:

  1. Type cast state_number to category type for both train and test data.

    X_train_['state_number'] = X_train_['state_number'].astype("category")

  2. While training cat boost, I specified the state_number in the cat_feature parameter.

    model_catBoost.fit(X_train, y_train ,cat_features = ['state_number'])

Is this approach correct, or am I adding some bias or doing something wrong?

$\endgroup$

1 Answer 1

0
$\begingroup$

Is this approach correct, or am I adding some bias or doing something wrong?

You're approach is correct.

You are correct in thinking that the categorical variable state_number should not be treated as an ordinary numerical variable. CatBoost offers functionality to handle categorical features. Passing the column name state_number as an argument to the cat_features parameter within the .fit() method--as you have done--is a perfectly acceptable method (see documentation).

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .