Giter VIP home page Giter VIP logo

nssortdescriptor-wilsonrank's Introduction

NSSortDescriptor+WilsonRank

The Correct Way To Rank Up/Down Voted Items

Let's say you have a collection of items, each of which have been rated thumbs positively or negatively a certain number of times. Maybe it's products on an e-commerce store, or links submitted to a popular hacker community.

How do we rank them?

Sorting by positive vs. negative % alone gives undue advantage to items with fewer ratings, whereas sorting by total number of positive ratings makes it difficult for new items to break into the top.

Fortunately, there is a correct solution: use the lower bound of Wilson score confidence interval for a Bernoulli parameter.

As eloquently described by Evan Miller:

We need to balance the proportion of positive ratings with the uncertainty of a small number of observations. Fortunately, the math for this was worked out in 1927 by Edwin B. Wilson. What we want to ask is: Given the ratings I have, there is a 95% chance that the "real" fraction of positive ratings is at least what? Wilson gives the answer. Considering only positive and negative ratings (i.e. not a 5-star scale), the lower bound on the proportion of positive ratings is given by:

Here p̂ is the observed fraction of positive ratings, zα/2 is the (1-α/2) quantile of the standard normal distribution, and n is the total number of ratings.

Usage

NSArray *fruits = @[@{@"name": @"apple", @"up": @(77), @"down": @(14)},
                    @{@"name": @"banana", @"up": @(90), @"down": @(78)},
                    @{@"name": @"cherry", @"up": @(28), @"down": @(6)},
                    @{@"name": @"durian", @"up": @(2), @"down": @(43)},
                    @{@"name": @"elderberry", @"up": @(81), @"down": @(42)},
                    @{@"name": @"fig", @"up": @(70), @"down": @(93)},
                    @{@"name": @"grape", @"up": @(48), @"down": @(89)},
                    @{@"name": @"honeydew", @"up": @(65), @"down": @(26)},
                    ];

NSSortDescriptor *sortDescriptor =
    [NSSortDescriptor wilsonRankSortDescriptorWithPositiveKey:@"up"
                                                  negativeKey:@"down"
                                                    ascending:NO];

for (id fruit in [fruits sortedArrayUsingDescriptors:@[sortDescriptor]]) {
    NSLog(@"%@ (%@↑ / %@↓)", fruit[@"name"], fruit[@"up"], fruit[@"down"]);
}

Results

  • apple (77↑ / 14↓)
  • cherry (28↑ / 6↓)
  • honeydew (65↑ / 26↓)
  • elderberry (81↑ / 42↓)
  • banana (90↑ / 78↓)
  • fig (70↑ / 93↓)
  • grape (48↑ / 89↓)
  • durian (2↑ / 43↓)

Contact

Mattt

License

NSSortDescriptor+WilsonRank is available under the MIT license. See the LICENSE file for more info.

nssortdescriptor-wilsonrank's People

Contributors

dkhamsing avatar mattt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.