Wilson Score sorting algorithm, Wilson Score, is used for quality sorting. The data contains positive and negative reviews. Taking into account the number of comments and praise rate, the higher the score, the higher the quality.
represents the number of positive examples (good reviews), represents the number of negative examples (bad reviews), represents the total number of instances (total number of reviews), represents the positive rate, and is the score of the normal distribution. Number of bits (parameter), represents the final Wilson score. generally takes a value of 2, which is 95% confidence.
Here is the quantile table for the normal distribution:
![](https://upload-images.jianshu.io/upload_images/749674-35a2dc9beddd2083.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/456/format/webp)
Algorithm traits:
- Properties: The range of score is , effect: normalized, suitable for sorting
- Properties: When the number of positive examples is , is , and the score is ; effect: no positive comments, the score is the lowest;
- Properties: When the number of negative examples is , is , degenerates to , and the score is always less than ; effect: the score has permanent comparability;
- Properties: When remains unchanged, the larger is, the reduction speed of the numerator is smaller than the reduction speed of the denominator, and the greater the score , and vice versa; Effect: The positive rate is the same, the total number of instances is , the more you score;
- Properties: When tends to infinity, it degenerates to , and the score is determined by ; Effect: When the total number of comments is more, the positive rate will bring the score is more obvious;
- Properties: When the quantile is larger, the total number of reviews is more important, and the praise rate is less important, and vice versa; Effect: The larger is, the total number of reviews is more important. The degree of discrimination is low; the smaller is, the more important the praise rate is;
Python Implementation.
Distribution plot of Wilson score algorithm
![](https://upload-images.jianshu.io/upload_images/749674-3340e75c9438e31e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1200/format/webp)
Let's try to put this theory into use with following example.
Example: Suppose Doctor A has 100 reviews, 1 negative review and 99 positive reviews. Doctor B has 2 reviews, both of which are good reviews. Which one should be ranked first?
When , that is, 95% confidence level, doctor A's score is 0.9440, doctor B's score is 0.3333, and doctor A ranks in front.
PS: Rating Level Question: What should we do if we have a five-star evaluation system or a hundred percent evaluation system?
Just change the Wilson score formula from Bernoulli distribution to normal distribution.
Note: The mean and variance are both normalized values.
Python Implementation.
Example of normalization:
PS: About the z parameter, that is, the normal quantile. The normal quantile affects the distribution of Wilson scores, and the value of the parameter is based on the magnitude of the number of samples. For example: the same 100 samples, 90 positive reviews, value is 2 or 6, the scores are very different, and the number of samples accommodated (or distinguished) by the system is also very different (the same is 0.82 points and 90% positive reviews, requires 100 samples, requires 1000 samples), generally speaking, the larger the magnitude of the number of samples, the larger the value of z.
References: