2

I have an array of dictionaries. Each dictionary holds data about an individual audio track. My app uses a star rating system so users can rate track 1-5 stars. Each dictionary has its own rating data per track, as follows:

  • avgRating (ex: 4.6)
  • rating_5_count (integer representing how many 5-star ratings a track received)
  • rating_4_count
  • rating_3_count
  • rating_2_count
  • rating_1_count

I'm trying to create a Top Charts table in my app. I'm creating a new array with objects sorted by avgRating. I understand how to sort the objects using NSSortDescriptors, but here is where I'm running into trouble...

If I only use avgRating as a sort descriptor, then if a track only receives one 5-star rating, it will jump to the top of the charts and beat out a track that might have a 4.9 with hundreds of votes.

I could set a minimum vote count to prevent this in the Top Charts array, but I would rather not do this. I would then have to change the min vote count as I get more users.

This is a bit subjective, but does anyone have any other suggestions on how to effectively sort the array?

4

2 回答 2

0

是的,向您的类添加一个方法,该方法返回根据平均投票数和投票数计算的权重。显然,重量的神奇公式取决于您。像 avgRating * log2 (2 + number_of_votes) 这样的东西可能会做到这一点。然后使用按此方法排序的单个排序描述符。

于 2012-07-14T19:16:11.883 回答
0

有很多方法可以处理这种情况。

一种方法可能是将投票数视为对评级平均值的置信度的衡量标准。从平均设置为 3 开始(每个示例)。

const double baseConfidenceRating = 3;
NSUInteger averageRating = ...;
NSUInteger voteCount = ...;

const NSUInteger baseConfidence = log10( 1000 );
double confidence = log10( 1 + voteCount ) / baseConfidence;
double confidenceWeight = fmin( confidence, 1.0 );

double confidenceRating = (1.0 - confidenceWeight) * baseConfidenceRating + confidenceWeight * averageRating;

现在根据confidenceRating而不是对数组进行排序averageRating

您可以通过更改需要多少票来调整上面的算法,使 confidenceRating 等于 averageRating,当然,您可以更改我在示例中使用的函数。平方根也可以工作,或者为什么不是线性进展。你的来电。

当然,这只是一个例子,一个非常愚蠢的例子。投票的标准差可能会在算法中增加一些智能,不仅要考虑投票的数量,还要考虑投票的分布。100 票对 100 票 5 比 1000 票随机散布在 0 和 5 之间更“自信”。我想。

于 2012-07-14T20:21:13.110 回答