Answers.Body: <p><strong>Is this approach correct, or am I adding some bias or doing something wrong?</strong></p>
  <p>You're approach is correct.</p>
  <p>You are correct in thinking that the categorical variable <code>state_number</code> should not be treated as an ordinary numerical variable.  CatBoost offers functionality to handle categorical features.  Passing the column name <code>state_number</code> as an argument to the <code>cat_features</code> parameter within the <code>.fit()</code> method--as you have done--is a perfectly acceptable method (see <a href="https://catboost.ai/en/docs/concepts/python-reference_catboostclassifier#cat_features" rel="nofollow noreferrer">documentation</a>).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-11-01T19:53:00.613Z
Answers.LastActivityDate: 2022-11-01T20:53:15.157Z
Answers.LastEditDate: 2022-11-01T20:53:15.157Z
Answers.UserDisplayName: Snehal Patel
Body: <p>I have a dataset (pandas data frame) with all features of type int32 containing continuous values except one feature <code>state_number</code>, its data type is int32, but it represents different states of a network (category). The feature <code>state_number</code> 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:</p>
  <ol>
  <li><p>Type cast <code>state_number</code> to category type for both train and test data.</p>
  <p><code>X_train_['state_number'] = X_train_['state_number'].astype(&quot;category&quot;)</code></p>
  </li>
  <li><p>While training cat boost, I specified the <code>state_number</code> in the <code>cat_feature</code> parameter.</p>
  <p><code>model_catBoost.fit(X_train, y_train ,cat_features = ['state_number'])</code></p>
  </li>
  </ol>
  <p>Is this approach correct, or am I adding some bias or doing something wrong?</p>
  
Tags: <machine-learning><binary-classification><ensemble-learning><categorical-data><boosting>
Title: How to specify categorical features in cat boost?
UserDisplayName: Zal
ThreadText: # How to specify categorical features in cat boost?
  
  (Asked by: username_0 on 2022-11-01)
  
  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?
  
  **Tags:** machine-learning, binary-classification, ensemble-learning, categorical-data, boosting
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-11-01. Score: 0 | Accepted answer
  
  **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](https://catboost.ai/en/docs/concepts/python-reference_catboostclassifier#cat_features)).
  
  
  ---
  
  