Created
February 22, 2013 01:41
-
-
Save kimihito/5010109 to your computer and use it in GitHub Desktop.
集合知プログラミングのコードをRubyで書く
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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