# Including identifier in machine learning model as feature vs separate model for every identifier

I am new to machine learning and i am building a model to predict number of customers for the model branch at specific hour/season/other feature.

I know it will be bad idea to pit id(branch_id in my case) into model but customer count in this case hugely depend on which branch it is so i cannot exclude it.

I can think of two solutions, i am not sure which one is right and what is the best practice.

1. Create dummy variable(one hot encoding to avoid wieghing one id more than other) for all branch ids,but since i have 600 unique branch ids my features will go up-to 600+rest_of_features.
2. Learn a separate model for each of the branch(600 models), i am not sure if it is right approach and also i am not very familiar with this approach and it will be very time consuming.

Looking for the suggestion

Example of the data is below

    +-----------+------+-----------+-----------+-------------------+
| branch_id | hour | feature_2 | feature_3 | Count of customer |
+-----------+------+-----------+-----------+-------------------+
|         1 |   12 |        .. |        .. |                19 |
|         1 |   01 |        .. |        .. |                25 |
|         2 |   23 |        .. |        .. |                14 |
|         2 |   01 |        .. |        .. |                 5 |
+-----------+------+-----------+-----------+-------------------+


In my opinion including id as a feature will not make sense at all, because the model will treat the id as a numeric value which will decrease the model performance, because there should be no connection how big the id is and how many customers there are for that id.

Option 2 can make sense if you have enough data for every branch.

My suggestion will be to look deep into your features and try to find a feature which will replace the branch id. Let's say the number of supporting desks in a branch or the location of a branch as a categorical value. If you find enough features that can describe the specifics of branches, then no need to include ids or to do it separately.

• thanks for answering, what about "Create dummy variable(one hot encoding) for all branch ids,but since i have 600 unique branch ids my features will go up-to 600+rest_of_features." ? Mar 16 '19 at 18:29
• Regarding 600 dummy variables: it can practically work with some regressors if you have large enough number of observations. Probably except from decision tree regressors. The typical rule of thumb for the multiple linear regression is usually that the number of observations should be at least 5 times more than the number of variables, otherwise you will have completely insignificant estimates. For your case, I think if you have quite large dataset, then you can try it out, also try different ML algorithms to see which one goes well. Mar 17 '19 at 19:32

I agree with @karen's answer. Including id in your model could make your model preform worse. Now @mashraf, regarding your 1st solution. There is something called as cardinality while using one hot encoding. Generally you don't use one hot encoding for a feature whose cardinality exceeds 10. It is practiced so that your features don't sky rocket in numbers. Your second solution will be really time consuming. But I believe that's the right way to do it. You group data based on id, and build separate models for different branches. Or since there are only 600 unique branches, you could enter the name of branch in place of id.

branch_id in this case is a categorical variable, and you can treat is just like you would other categoricals (like city: "Seattle", "San Diego", "Austin"). You just need to be sure you use an algorithm that can treat it as categorical. LightGBM uses a method that sorts and optimally splits the histogram of the categorical integers, which is faster than OHE. CatBoost can leverage a few different methods.

In addition to regression, you can similarly convert the customer counts into ranges or histogram bins and use a classification algorithm to predict the bin.