1
$\begingroup$

This is an open ended WHY TO or WHEN TO question rather than a question on HOW TO encode numeric to categorical data.

I am currently working on Telco Customer Churn dataset from kaggle.

This is classification problem to predict if a customer will Churn or Not.

It has total 7043 rows and 21 columns, a mix of categorical and numerial columns. One of the column is Tenure which has data distributed in the range

> df.tenure.unique()

array([ 1, 34,  2, 45,  8, 22, 10, 28, 62, 13, 16, 58, 49, 25, 69, 52, 71,
       21, 12, 30, 47, 72, 17, 27,  5, 46, 11, 70, 63, 43, 15, 60, 18, 66,
        9,  3, 31, 50, 64, 56,  7, 42, 35, 48, 29, 65, 38, 68, 32, 55, 37,
       36, 41,  6,  4, 33, 67, 23, 57, 61, 14, 20, 53, 40, 59, 24, 44, 19,
       54, 51, 26, 39])

In one of the public kernel I saw the guy changing it into a categorical column.

> pd.cut(df['tenure'], bins=[0,12,24,48, 60, df['tenure'].max()], labels=['Tenure_0-12', 'Tenure_12-24', 'Tenure_24-48','Tenure_48-60','Tenure_gt_60'])
0        Tenure_0-12
1       Tenure_24-48
2        Tenure_0-12
3       Tenure_24-48
4        Tenure_0-12
            ...     
7027    Tenure_12-24
7028    Tenure_gt_60
7029     Tenure_0-12
7030     Tenure_0-12
7031    Tenure_gt_60
Name: tenure, Length: 7032, dtype: category

It is a common practice to group/bin some numeric columns (usually with date/time columns like Age, Seasonal). I am not quite sure of the benefits of doing so across various Traditional ML algorithms.

Some Algorithms which are sensitive to dimentionality may perform bad, as the number of dimensions increases by One-Hot encoding of the newly created Categorical column.

Rationally, with the columns grouped into bins it will be very difficult to cluster the target for algo like K-NearestNeighbour or SVM to find a plane.

Please! Lets discuss on the impact of this technique on different ML Algorithms (Not just limited to tradiotnal or classification algorithms).

$\endgroup$
1
$\begingroup$

One reason to convert numerical data to categorical data is to improve the signal-to-noise ratio. Fitting a model to bins reduces the impact that small fluctuates in the data has on the model, often small fluctuates are just noise. Each bin "smooths" out the fluctuates/noises in sections of the data.

| improve this answer | |
$\endgroup$
  • $\begingroup$ So which algorithms are affected by signal-to-noise ratio ? $\endgroup$ – Rohit Nandi Jun 4 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.