Skip to content

Instantly share code, notes, and snippets.

@kimihito
Created February 22, 2013 01:41
Show Gist options
  • Save kimihito/5010109 to your computer and use it in GitHub Desktop.
Save kimihito/5010109 to your computer and use it in GitHub Desktop.
集合知プログラミングのコードをRubyで書く
Lisa_Rose:
Lady_in_the_Water: 2.5
Snakes_on_a_Plane : 3.5
Just_My_Luck: 3.0
Superman_Returns: 3.5
You_Me_and_Dupree: 2.5
The_Night_Litener: 3.0
Gene_Seymour:
Lady_in_the_Water: 3.0
Snakes_on_a_Plane : 3.5
Just_My_Luck: 1.5
Superman_Returns: 5.0
You_Me_and_Dupree: 3.5
The_Night_Litener: 3.0
Michael_Phillips:
Lady_in_the_Water: 2.5
Snakes_on_a_Plane : 3.0
Superman_Returns: 3.5
The_Night_Litener: 4.0
Claudia_Puig:
Snakes_on_a_Plane : 3.5
Just_My_Luck: 3.0
Superman_Returns: 4.0
You_Me_and_Dupree: 2.5
The_Night_Litener: 4.5
Mick_LaSalle:
Lady_in_the_Water: 3.0
Snakes_on_a_Plane : 4.0
Just_My_Luck: 2.0
Superman_Returns: 3.0
You_Me_and_Dupree: 2.0
The_Night_Litener: 3.0
Jack_Matthews:
Lady_in_the_Water: 3.0
Snakes_on_a_Plane : 4.0
Superman_Returns: 5.0
You_Me_and_Dupree: 3.5
The_Night_Litener: 3.0
Toby:
Snakes_on_a_Plane : 4.5
You_Me_and_Dupree: 1.0
Superman_Returns: 4.0
#!/usr/bin/env ruby
#-*- coding: utf-8 -*-
require "yaml"
data = YAML.load_file "data.yml"
def sim_distance(prefs,person1,person2)
si = {}
prefs[person1].each do |item|
if prefs[person2] != item
si[item] = 1
end
end
if si.length == 0
return 0
end
sum_of_squares = 0
prefs[person1].each do |item,point|
if prefs[person2].has_key?(item)
s_item = prefs[person1][item] - prefs[person2][item]
sum_of_squares += s_item ** 2
end
end
1 / (1 + sum_of_squares)
end
puts sim_distance(data, "Lisa_Rose","Gene_Seymour")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment