How to select the best bins while creating a new categorical variable from a continuous variable?

plot
feature_engineering

#1

Hello,

I wanted to know how to select the best bins from a continuous variable to convert it into a categorical variable by looking at the plot/distribution. For example->

Thanks.


#2

As a basic step you may want to use the cut2 function from Hmisc.
Look for discretization or smbinning package for optimal binning for more detailed algorithms in binning.