基于 ruby/redis 的推薦引擎:recommendify
recommendify 是基于 ruby/redis 的推薦引擎 (協同過濾)。
# Our similarity matrix, we calculate the similarity via co-concurrence
# of products in "orders" using the jaccard similarity measure.
class MyRecommender < Recommendify::Base
# store only the top fifty neighbors per item
max_neighbors 50
# define an input data set "order_items". we'll add "order_id->product_id"
# pairs to this input and use the jaccard coefficient to retrieve a
# "customers that ordered item i1 also ordered item i2" statement and apply
# the result to the item<->item similarity matrix with a weight of 5.0
input_matrix :order_items,
# :native => true,
:similarity_func => :jaccard,
:weight => 5.0
end
recommender = MyRecommender.new
# add `order_id->product_id` interactions to the order_item_sim input
# you can add data incrementally and call RecommendedItem.process! to update
# the similarity matrix at any time.
recommender.order_items.add_set("order1", ["product23", "product65", "productm23"])
recommender.order_items.add_set("order2", ["product14", "product23"])
# Calculate all elements of the similarity matrix
recommender.process!
# ...or calculate a specific row of the similarity matrix (a specific item)
# use this to avoid re-processing the whole matrix after incremental updates
recommender.process_item!("product65")
# retrieve similar products to "product23"
recommender.for("item23")
=> [ <Recommendify::Neighbor item_id:"product65" similarity:0.23>, (...) ]
# remove "product23" from the similarity matrix and the input matrices. you should
# do this if your items 'expire', since it will speed up the calculation
recommender.delete_item!("product23")
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!