Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
64 lines (45 sloc) 1.04 KB
require "redis"
threshold = 0.0000000001
f = File.open(ARGV[1], "r")
recs = {}
count = 0
f.each_line do|line|
prefs = line.strip!.split(",")
user_id = prefs[0].to_i
item_id = prefs[1].to_i
pref = prefs[2].to_f
count +=1
if(count.remainder(10000) ==0)
puts count
end
if(recs[user_id].nil?)
recs[user_id] = {item_id => pref}
else
recs[user_id][item_id] = pref
end
end
threshold = ARGV[0].to_i
#ARGV.each do |arg|
# threshold = arg.to_i
#end
puts recs.count
total = 0
recs.each_pair do |user_id, prefs|
rec_bigger = []
rec_smaller = []
prefs.each_pair do |item_id, pref|
if pref > threshold
rec_bigger << pref
else
rec_smaller << pref
end
end
sum_bigger = rec_bigger.inject(0){|sum,x| sum + x}
sum_smaller = rec_smaller.inject(0){|sum, x| sum + x}
avg_bigger = sum_bigger / rec_bigger.count.to_f
avg_smaller = sum_smaller / rec_smaller.count.to_f
distance = avg_bigger - avg_smaller
total += distance
end
puts "Distance between filtered and kept recommendations."
puts total / recs.count.to_f