Evan Miller's Rating Sorting in Python

A common problem with a website is how to sort things by their rating. Evan Miller describes it well in his 2009 post, How Not To Sort By Average Rating.

Here is a Python snippet that implements his method:

import math
from scipy import stats

def ci_lower_bound(positive_ratings, total_ratings, confidence):
    Following http://www.evanmiller.org/how-not-to-sort-by-average-rating.html#changes
    :return: the lower bound of the confidence interval
    n =  total_ratings
    z = stats.norm.ppf(1 - (1 - confidence) / 2)
    p_hat = 1.0 * positive_ratings / n
    result = (
             p_hat + z * z / (2 * n)
             - z * math.sqrt(
                 (p_hat * (1 - p_hat) + z * z / (4 * n)) / n
        ) / (1 + z * z / n)
    return result

Note that this assumes you have the python package scipy installed. You can find it here.

As Evan Miller notes, your z value will be constant so you can also hardcode it, for example to 1.96 if you want a 95% confidence interval.

You can interpret the output of this function as a corrected rating, which ‘punishes’ items with a low number of votes.


Quick Links

Here are some things that caught my attention recently:

  • A couple of high school kids in California build up a massive drug smuggling empire in this long read from the great Atavist Magazine. Link
  • Trees calm us down and make us healthier. Link
  • Balaji Srinivasan from 21 (the company) thinks that a ‘machine payable’ web is coming, i.e. one in which machines send some cryptocurrency along with requests to each other. This would drastically decrease the effort it takes to start using an API. Video Link
  • Two tips for managers:
    • Don’t add your two cents, it will cause people to lose the sense of ownership. Link
    • Let people make decisions, say “it’s your call” as much as you can. Link

I am looking for an objective summary of the major Bitcoin initiatives. Does anyone know of one? If not I might attempt to write one myself.


Quick Links

I really enjoy Greg Linden’s +- bi-monthly quick links. Here’s my first version of things that caught my attention recently:

  • Coinbase, one of the largest cryptocurrency exchanges, discusses their security. This includes “special machines in the office that are in a locked room, that you only use for SSH access” and cameras to monitor who accesses these machines. They also share that “98% of customer bitcoin private keys are stored entirely offline” and keys are split and geographically distributed. Link
  • For someone who stopped following JavaScript when jQuery was all you needed, this State of the JavaScript Landscape: A Map for Newcomers provides a good overview. Their starter kit is also my current frontend development setup (React, Babel, Webpack, ES6). Link
  • Interesting profile of Vitalik Buterin, inventor of Ethereum (before he turned 20!) and universally respected. Link
  • If you want to know someone’s personality, just ask how they perceive others. “The more frequently people rated others as kindhearted, happy, emotionally stable, or courteous, the more likely they were to rate themselves as having these traits, and the more likely outside evaluators were to agree”. Link
  • Minecraft has captured a generation and taught millions of kids to be creative and solve difficult problems. Link

Hello World!

This domain has been empty for too long, so I decided to try blogging to organize and share my thoughts. Who knows I might even end up writing something useful for someone one day.

This blog is made using Jekyll, which means it consists just of static files, and hosted on Github Pages.