I am trying to intelligently bin a sorted collection. I have a collection of $n$ pieces of data. But I know that this data fits into $m$ unequally sized bins. I don't know how to intelligently choose the endpoints to properly fit the data. for example:
Say I have 12 items in my collection, and I know the data will fit into 3 bins:
Index: 1 2 3 4 5 6 7 8 9 10 11 12
Value: 1 1 1 3 3 3 3 3 3 5 5 6
How do I intelligently choose my breakpoints for the bins of $i = \{1-3\}, \{4-9\}, \{10-12\}$?
The current implementation I have breaks the data into evenly sized bins and then takes the average of the endpoints to find the indexes for the end of the bins. So it works like this:
Index: 1 2 3 4 5 6 7 8 9 10 11 12
Value: 1 1 1 3 3 3 3 3 3 5 5 6
first break evenly: i = 1-4, 5-8, 9-12
mean endpoints: between 4 and 5: (3+3)/2 = 3
between 8 and 9: (3+3)/2 = 3
So now anything below 3 fits in bin 1, anything above 3 but below 3 fits in bin 2, and anything above 3 fits in bin 3. You can see what my problem is. If the data has unequal bins my method fails.
A friend mentioned the k-nearest neighbor algorithm but I'm not sure.