How to tell CatBoost which feature is categorical?

I am excited to learn that CatBoost can handle categorical features by itself. One of my features, Department ID, is categorical. However, it looks like numeric, since the values are like 1001, 1002, ..., 1218. Those numbers are just IDs of the departments. It by no means has numeric or ordinal meanings. How do I tell CatBoost to treat it as categorical (nominal), not numeric?

Thanks.

Topic catboost categorical-data

Category Data Science


When you are training your Catboost classifier, you can pass the list of cat features like this in python :

CatboostClassifier has a parameter called Cat_Features which takes list of names and treat them as categorical variables

from catboost import CatBoostClassifier


clf = CatBoostClassifier(
    iterations=5, 
    learning_rate=0.1, 
    #loss_function='CrossEntropy'
)

clf.fit(X_train, y_train, 
        cat_features=['Name of your categorical variables'], ## This 
        eval_set=(X_val, y_val), 
        verbose=False
)

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.