-
-
Save goncalossilva/1115856 to your computer and use it in GitHub Desktop.
| require 'rubygems' | |
| require 'json' | |
| require 'net/http' | |
| require 'statistics2' | |
| # from http://www.evanmiller.org/how-not-to-sort-by-average-rating.html | |
| def ci_lower_bound(pos, n, power) | |
| return 0 if n == 0 | |
| z = Statistics2.pnormaldist(1-power/2) | |
| phat = 1.0*pos/n | |
| (phat + z*z/(2*n) - z * Math.sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n) | |
| end | |
| url = "http://services.sapo.pt/Codebits/calltalks" | |
| response = Net::HTTP.get_response(URI.parse(url)) | |
| results = JSON.parse(response.body) | |
| results.each do |result| | |
| result["score"] = ci_lower_bound(result["up"].to_i, result["up"].to_i+result["down"].to_i, 0.05) | |
| result["up"].to_f/result["down"].to_f | |
| end | |
| results.sort! { |a,b| b["score"] <=> a["score"] } | |
| results.each_with_index do |result, index| | |
| puts "##{index+1}" | |
| puts "Title: #{result["title"]}" | |
| puts "Votes: #{result["up"]} - #{result["down"]}" | |
| puts "Score: #{result["score"]}" | |
| puts | |
| end |
@SHAD3R that doesn't seem appropriate in this case... talks with more votes are more likely to be accurate than talks with less votes. At the same time, if:
Talk 1: +100 -70
Talk 2: +25 -0
then Talk 1 would be better ranked than Talk 2, and it doesn't seem right IMHO.
@goncalossilva you can give weights to the upvotes according to the downvotes.
If 0 < n downvotes < 25 then n upvotes * 1 end
if 25 < n downvotes < 50 then n upvotes * 0.9 end
Then it's a question of fine tuning this weights
Yeah, I think I'll do something like that... I was waiting for someone to provide me with an already reliable ranking system :)
Apparently what you want is the lower bound of Wilson score confidence interval for a Bernoulli parameter :D
There you go my friend http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
Now that's what I'm talking about! I've seen that before... I think it had something to do with @paulozoom's MSc thesis. Oh well, time for some coding. Thanks!
I'd be glad if someone pointed me to a decent performance index for this kind of data (upvote/downvote)... ratio doesn't make much sense :)