Skip to content

akamud/wilson-score-csharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wilson Score for C#

You shouldn't use average for your scores.

Here's why:

Item A has 900 upvotes and 100 downvotes, resulting in an average of 90% likes.
Item B just came up in your database, it has 1 upvote and 0 downvotes, resulting in 100% likes! Woot!

Now Item B will come first than Item A. That's not what you want, is it?

That's exactly the problem that Wilson Score solves.

I found out about this on 'How Not To Sort By Average Rating'. Give it a read.

Tl;dr: Wilson Score takes into account that a higher number of votes has more chance to be a correct representation of the general opinion. It basically answers the question: Given the ratings I have, there is a 95% chance that the "real" fraction of positive ratings is at least what?

If you still think you should sort by average, know that Reddit uses this on "best" sorting. Yelp too.

Using WilsonScore in your C# projects

Nuget package available here, install it with

PM> Install-Package WilsonScore

Using it is as simple as you would expect:

Wilson.Score(upvotes, total);

By default it uses 90% confidence (z = 1.644853). If you want to change the confidence, you can pass a third parameter, like so:

Wilson.Score(upvotes, total, 1.96); // 95% confidence
// or
Wilson.Score(upvotes, total, 2.326348); // 99% confidence

Using Wilson Score on the case mentioned at the start would give these values:

Item Average Score Wilson Score
Item A 90% 88.32%
Item B 100% 26.98%

Wilson Score puts Item A in a better position, now everyone is happy.

Right now that's all it does, and that's probably all you need anyway.

Supported Platforms

.NET Framework 4+
Silverlight 5+
Windows 8+
Windows Phone 8.1+
Windows Phone Silverlight 8
Xamarin.Android
Xamarin.iOS

Notes

Based on the javascript version by Jonathan Ong.
MIT License

About

C# implementation of the Wilson Score

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages