2016-05-14 6 views
0

私はthisが本当によく説明された計算を見つけましたが、それが正しいかどうか本当にわかりません。WilsonスコアはC#の1-5の評価で

私は、次の

 double posf = model.stars == 1 ? 0 : 
       model.stars == 2 ? 0.25 : 
       model.stars == 3 ? 0.5 : 
       model.stars == 4 ? 0.75 : 
       model.stars == 5 ? 1 : 0; 
      double negf = model.stars == 1 ? 1 : 
       model.stars == 2 ? 0.75 : 
       model.stars == 3 ? 0.5 : 
       model.stars == 4 ? 0.25 : 
       model.stars == 5 ? 0 : 0; 

      rating.positif += posf; 
      rating.negatif += negf; 
      rating.ratingcount += 1; 
      rating.ratingavg = Math.Round((((rating.positif/rating.ratingcount) * 4) + 1) * 2, 0)/2; 
      rating.calcSort = ((rating.positif + 1.9208)/(rating.positif + rating.negatif) - 1.96 * Math.Sqrt((rating.positif * rating.negatif)/(rating.positif + rating.negatif) + 0.9604)/(rating.positif + rating.negatif))/(1 + 3.8416/(rating.positif + rating.negatif)); 
としてのC#に変換
Stars Negative Positive Total 
0  0   0   0 
1  1   0   1 
2  0.75  0.25  1 
3  0.5   0.5   1 
4  0.25  0.75  1 
5  0   1   1 

SET new.total = new.positive + new.negative, 
    new.stars = ROUND((((new.positive/new.total) * 4) + 1) * 2, 0)/2, 
    new.lower_bound = ((new.positive + 1.9208)/(new.positive + new.negative) - 1.96 * SQRT((new.positive * new.negative)/(new.positive + new.negative) + 0.9604)/(new.positive + new.negative))/(1 + 3.8416/(new.positive + new.negative)) 

:私は5

のために最も重要な部分はこれで1つの計算を見て、私はhaventは件名に記事をたくさん見てきました

このコーディングが正しい変換であり、SQLバージョンが実際に正しい場合は、誰かが助けてくれますか?

答えて

1

下限値を二重に格納することができます。丸めする必要はありません。 C#の機能は、このようなものに変えることができます。

private static double WilsonAlgorithm(double positive, double negative) 
    { 
     return ((positive + 1.9208)/(positive + negative) - 
       1.96 * Math.Sqrt((positive * negative)/(positive + negative) + 0.9604)/
       (positive + negative))/(1 + 3.8416/(positive + negative)); 
    } 

(クレジットへ:http://www.evanmiller.org/how-not-to-sort-by-average-rating.html、そのほとんどが彼のページでSQLコードから来た)星から変換するには

- >正/負読みやすくするために三項演算子を使いすぎなくても計算できます。

// constants 
    const int maxRating = 5; 
    const int minRating = 1; 
    const double shareRating = 0.25; 
    // conversions 
    var stars = 5; 
    var positive = (stars - minRating) * shareRating; 
    var negative = (maxRating - stars) * shareRating; 

    // .. 

    // usage? 
    var lowerBoundRating = WilsonAlgorithm(totalPositive, totalNegative); 
+0

いただきありがとうございます。数学と数式はURLで正しいのですか?それは実際にもっと重要です。 – drewex