# Converting continuous to categorical variable

What method must be chosen for converting a continuous variable(socio-economic ratio) into a categorical variable, the quantiles are as follows:

df['ses'].quantile([0,0.25,0.5,0.75,1])

0.00     0.000
0.25     1.070
0.50     1.979
0.75     3.341
1.00    11.889


Whenever I want to convert a continuous feature into categorical with bins, I use one of the following two ways.

1. Freedman–Diaconis rule (wikipedia source)

Bin width = 2 x IQR(x) x n^(-1/3)

Where IQR(x) is max-min and n is the number of your observations in your sample.

1. Frequency Bins

You get such a bin width that each of them will have the same number of observations.

I don't have a rule of thumb, where to use each of them. I usually try both and measure the impact on accuracy. Then decide which I will use in the final model.

• but won't frequency bins we flawed if most of the observations have same or similar value and some values are far apart, especially in cases where socioeconomic factors are involved. Feb 22 '19 at 9:14
• That's why there isn't a rule of thumb imo. You should try and evaluate the result based on your own data. Feb 22 '19 at 9:21