0
$\begingroup$

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
$\endgroup$

1 Answer 1

1
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$ Feb 22, 2019 at 9:14
  • $\begingroup$ That's why there isn't a rule of thumb imo. You should try and evaluate the result based on your own data. $\endgroup$
    – Tasos
    Feb 22, 2019 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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