# Binning By Equal-Width

I have a dataset:

5, 10, 11, 13, 15, 35, 50 ,55, 72, 92, 204, 215


The formula for binning into equal-widths is this (as far as I know) $$width = (max - min) / N$$

I think N is a number that divides the length of the list nicely. So in this case it is 3. Therefore:

width = 70

How do I use that 70 to make the bins?

EDIT: Found the answer. Should I answer my own question or just delete it?

• You can answer your own question (maybe not now, but tomorrow it will be possible). – Davide Giraudo Nov 7 '13 at 10:07
• Check the list of related questions to the right -> and perhaps try a search. If you can't find another question with an answer or answers that deal with your question, please go ahead and answer it yourself. If there is another question/answer that does answer your question, it would be better to delete. – Glen_b Nov 7 '13 at 11:05
• Two comments: I think that the number of bins is more typically not a factor of the sample size; there's no need for it to be. (Also, more typically, though not always, the first and last bin boundaries are placed at roundish numbers.) -- but the requirements of what you're doing may differ – Glen_b Nov 7 '13 at 18:05
• Mike, you might appreciate this assessment of histograms offered by @Glen_b in response to a related question. – whuber Nov 7 '13 at 20:41
• 3 appears out of mid-air and is never explained. The question is mystifying on several different levels. 0. Why 3 here? 1. Why bin at all? You can show all the values directly in a dot or strip plot or a quantile plot. 2. Even if you bin, there are grounds (aesthetic and other) for nicer numbers such as lower bin limits 0, 50, 100, .. 3. Who says that bins all need to be populated? I have no problem with some empty bins showing gaps in the data. They are less misleading than wider bins. – Nick Cox Feb 26 '18 at 10:24

I found the answer. I was somewhat close with the question. The trick is that width is not just width, it is width of each interval.

Therefore

bin1: 5,10,11,13,15,35,50,55,72 I.e. all values between 5 and 75
bin2: 92 I.e. all values between 75 and 145
bin3: 204,215 I.e. all values between 145 and 215


And for equal width binning you are given number of required bins and in this case it is 3.

• I am still not getting this. How did you get N=3 and why not 4 or 2? Also, how did you divide them into 3 bins with those particular data points. I would highly appreciate any references as I also wanted to see how equal probabilities are done (in terms of chi-square ). – leviathan Dec 4 '13 at 0:03
• The answer to 'I am still not getting this. How did you get N=3 and why not 4 or 2?' is that, the question itself asks for three bins with equal width. When the range of the sequence(max-min) is divided by the number of bins (N=3), the output yields the width of each bin(equal width of 70). Now that we have the width of the bin decided, we can easily divide the given sequence according to closed and open intervals to include every element of the sequence to be a member of some interval or the other.Hope this helps. – Indu May 7 '17 at 13:20
• So, the question should be described as Binning By Equal-Width with 3 bins? – Nick Dong Feb 9 '19 at 8:09

Binning is a unsupervised technique of converting Numerical data to categorical data but it do not use the class information. There are two unsupervised technique.

1-Equal width. 2-Equal frequency.

In Equal width, we divide the data in equal widths. In order to calculate width we have the formula.

width=(max−min)/N

So from the available data in the problem we have 75 is the width.

We divide the data with three categories:

5 to 75 75 to 145 145 to 215.

Now we keep the numbers in the above ranges.Thus,

bin1: 5,10,11,13,15,35,50,55,72 bin2: 92 will hold only one value as we have only one value exist between 75 and 145
bin3: 204,215.

• This doesn't seem to say anything that isn't in the accepted answer – Nick Cox Feb 26 '18 at 11:15
• why 75 instead of 70? The answer should give an example of 2-Equal frequency, either, since you mentioned this concept here. – Nick Dong Feb 9 '19 at 8:06

\begin{align}\text{width}= \frac{\max-\min}{ \text{number of bins}} = \frac{215-5}3 =70. \end{align}

$$5, 10, 11, 13, 15, 35, 50 ,55, 72, 92, 204, 215$$

1. $$70+5=75$$ (from $$5$$ to $$75)=$$Bin $$1: 5,10,11,13,15,35,50,55,72$$
2. $$75+70=145$$ (from $$75$$ to $$145)=$$Bin $$2:92$$
3. $$145+70=215$$ (from $$145$$ to $$215)=$$Bin $$3: 204,215$$