2
$\begingroup$

I am training a supervised machine learning model.

The training data contains 2 independent groups of people. The dataset contains independent continuous variables and 1 dependent binary variable.

I want to select the optimal number of bins to use for each independent variable. I define the optimal number of bins as the number of bins that will highlight the largest difference in counts between my binary y variables.

I am aware of Sturge’s and Freedman-Diaconis rules. However, to my knowledge, these approaches do not select the number of bins based on their ability to parcellate the dependent variable groups per bin.

If I were to do this manually, I would divide the data using 2-15 bins. Then, I would plot histograms of each. Finally, I would eyeball the number of bins. The histogram that showed the greatest difference between the two dependent variable groups, for a particular bin range, is the number of bins I would use.

I am looking for an equation/ test, similar to Sturge’s and Freedman-Diaconis rules, that can do this. Alternatively, if there is a more optimal, and straightforward, approach I would gladly consider this also.

$\endgroup$
1
  • 1
    $\begingroup$ What do you mean by "highlighting the largest difference in counts"? Binning throws away an incredible amount of information, stats.stackexchange.com/q/68834/1352, you should be very certain you want to do this before you start. $\endgroup$ Commented Aug 18, 2022 at 12:06

1 Answer 1

3
$\begingroup$

Unless you have a good theoretical justification for reducing your continuous variables into categorical variables, like an expectation of discontinuity between groups/bins, you should avoid doing so. Your question doesn't indicate that there is a theoretical justification for any binning, since you are trying to define the number of bins based on the data itself.

The simple answer is that you are potentially throwing away a lot of information that would otherwise be contained in your continuous variables. Therefore it is generally better to use the continuous variables in your model than trying to group them arbitrarily.

Categorising a continuous independent variable assumes that the relationship between that variable and the outcome that you are trying to predict (or explain) would be flat within-group and that there is a discontinuity between groups (as the boundary between groups is crossed).

Generally, linearity is a better starting assumption, and if the effect is non-linear, you could try using polynomials or splines.

This post by Frank Harrell offers a detailed list of the issues with categorizing continuous variables, and demonstrates that there are multiple concerns about doing so, beyond the short summary I've offered.

$\endgroup$
1
  • 1
    $\begingroup$ Welcome to Cross Validated! Nicely summarized (+1). Please continue to contribute to the site! $\endgroup$
    – EdM
    Commented Aug 18, 2022 at 14:38

Your Answer

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

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