When transforming numerical variables into categorical variables I'm not aware of when should I use equal frequency binning and when equal width binning. Seems that each of them has their own advantages but I can't distinguish them.
-
2$\begingroup$ What's the purpose of binning here? Often, it's best not to discretize data at all. But, you'd have to say more about how you plan to use the discretized values. $\endgroup$– user20160Commented Dec 9, 2019 at 21:14
-
1$\begingroup$ There are plenty of other binning methods, too: various forms of clustering (such as Jenks' method); by multiples of a standard deviation; by N-letter values; and more. $\endgroup$– whuber ♦Commented Dec 9, 2019 at 23:10
-
$\begingroup$ Adding some useful resources. Blog: blog.trainindata.com/data-discretization-in-machine-learning Python library: feature-engine.trainindata.com/en/latest/user_guide/… $\endgroup$– Sole GalliCommented Apr 22 at 12:58
1 Answer
Binning is something I would rarely do myself on data. Many algorithms will bin continuous data for performance (XGboost, LGBM, ...) but the way they bin to create histograms is not as trivial as equal width or frequency.
In general, however, equal width is better for graphical representations (histograms) and is more intuitive, but it might have problems if the data is not evenly distributed, it's sparse, or has outliers, as you will have many empty, useless bins. Equal frequency will instead guarantee that every bin contains the roughly the same amount of data, which is usually preferable if you have to then use the data in any kind of model/algorithm as bins will be more significative in representing the underlying distribution.