I am creating an ecommerce site, and I am having trouble developing a good algorithm to sort a products that are pulled from the database into halfway appropriate groups. I have tried simply dividing the highest price into 4, and basing each group off that. I also tried standard deviations based around the mean. Both could result with price ranges that no product would fall into, which isn't a useful filtering option.
I also tried take quartiles of the products, but my problem is that the price ranges from $1 items to $4,000. The $4,000 almost never sell, and are far less important, but they keep skewing my results.
Any thoughts? I should have paid more attention in stats class ...
Update:
I ended up combining methods a bit. I used the quartile/bucket method, but hacked it a bit by hardcoding certain ranges within which a greater number of price groups would appear.
//Price range algorithm
sort($prices);
//Divide the number of prices into four groups
$quartilelength = count($prices)/4;
//Round to the nearest ...
$simplifier = 10;
//Get the total range of the prices
$range = max($prices)-min($prices);
//Assuming we actually are working with multiple prices
if ($range>0 )
{
// If there is a decent spread in price, and there are a decent number of prices, give more price groups
if ($range>20 && count($prices) > 10)
{
$priceranges[0] = floor($prices[floor($quartilelength)]/$simplifier)*$simplifier;
}
// Always grab the median price
$priceranges[1] = floor($prices[floor($quartilelength*2)]/$simplifier)*$simplifier;
// If there is a decent spread in price, and there are a decent number of prices, give more price groups
if ($range>20 && count($this->data->prices) > 10)
{
$priceranges[2] = floor($prices[floor($quartilelength*3)]/$simplifier)*$simplifier;
}
}