我正在創建一個電子商務網站,而且我很難開發出一種很好的算法來對從數據庫中提取的產品進行分類,將其分類到適當的組中。我試圖簡單地將最高價格分成4份,然後將每個組分成幾份。我也嘗試了基於平均值的標準偏差。兩者都可能導致價格範圍內沒有產品將落入,這不是一個有用的過濾選項。價格過濾器分組算法
我也嘗試了四分之一的產品,但我的問題是,價格範圍從1美元到4000美元。 4,000美元幾乎從不出售,而且重要性也不那麼重要,但他們一直在歪曲我的結果。
有什麼想法?我應該在統計類更加重視......
更新:
我最終結合的方法一點。我使用四分之一/桶方法,但是通過硬編碼某些範圍內的更多數量的價格組會出現黑客攻擊。
//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;
}
}
這聽起來像是如果用實際銷售信息豐富產品信息(僅包含價格),那麼您將能夠執行更好的拆分(儘管我現在還不知道如何) – 2010-07-21 22:46:03