lib/disco/recommender.rb in disco-0.3.1 vs lib/disco/recommender.rb in disco-0.3.2
- old
+ new
@@ -34,10 +34,12 @@
if validation_set
check_ratings(validation_set)
end
end
+ @user_map = {}
+ @item_map = {}
@rated = Hash.new { |hash, key| hash[key] = {} }
input = []
train_set.each do |v|
# update maps and build matrix in single pass
u = (@user_map[v[:user_id]] ||= @user_map.size)
@@ -54,9 +56,12 @@
raise ArgumentError, "Missing item_id" if @item_map.key?(nil)
# TODO improve performance
unless @implicit
@min_rating, @max_rating = train_set.minmax_by { |o| o[:rating] }.map { |o| o[:rating] }
+ else
+ @min_rating = nil
+ @max_rating = nil
end
if @top_items
@item_count = [0] * @item_map.size
@item_sum = [0.0] * @item_map.size