【发布时间】:2011-03-19 06:41:24
【问题描述】:
我正在创建一个电子商务网站,但我无法开发一个好的算法来将从数据库中提取的产品分类到适当的组中。我尝试将最高价格简单地分成 4 份,然后将每组都以此为基础。我还尝试了基于平均值的标准偏差。两者都可能导致没有产品会落入的价格范围,这不是一个有用的过滤选项。
我也尝试过取产品的四分位数,但我的问题是价格从 1 美元到 4,000 美元不等。 4,000 美元几乎从来没有卖出去,而且远没有那么重要,但它们一直在扭曲我的结果。
有什么想法吗?我应该在统计课上多加注意...
更新:
我最终结合了一些方法。我使用了 quartile/bucket 方法,但通过硬编码将出现更多价格组的某些范围进行了一些修改。
//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;
}
}
【问题讨论】:
-
听起来如果你用实际的销售信息来丰富产品信息(只包含价格),那么你将能够进行更好的拆分(虽然我还不知道如何)
标签: php algorithm statistics e-commerce