public
Description: Collaborative Filtering for Rails
Homepage:
Clone URL: git://github.com/maccman/acts_as_recommendable.git
100644 124 lines (91 sloc) 3.503 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
ActsAsRecommendable
===================
 
ActsAsRecommendable is a plugin for Rails that simplifies collaborative filtering
 
The plugin provides a mechanism for finding loose associations between users and items which we can tell you
* Given a user, return other similar users based on what items they have all bought/bookmarked/rated/etc
* Given a user, return recommended items based on the items bought/bookmarked/rated/etc by that user and the items bought/bookmarked/rated/etc by other users.
 
The plugin calculations can be made online and offline and stored using the rails cache (such as memcache) for online retrieval. Online retrieval of recommendations uses item-based collaborative filtering using the offline items similarity matrix stored in the cache. This can give up-to-date results with a much lower processing overhead.
 
Much thanks to Toby Segaran and his excellent book Programming Collective Intelligence (http://oreilly.com/catalog/9780596529321/).
 
Features
========
 
Use join rating scores
Using abitary calculated scores
Similar Items
Recommended Users
Cached dataset
 
Current Release
===============
 
v0.1 should be considered early alpha and not ready for production applications.
 
Lots of performance optimisations still to be done.
 
Example
=======
 
class Book < ActiveRecord::Base
  has_many :user_books
  has_many :users, :through => :user_books
end
 
class UserBook < ActiveRecord::Base
  belongs_to :book
  belongs_to :user
end
 
class User < ActiveRecord::Base
  has_many :user_books
  has_many :books, :through => :user_books
  acts_as_recommendable :books, :through => :user_books
end
 
user = User.find(:first)
user.similar_users #=> [...]
user.recommended_books #=> [...]
 
book = Book.find(:first)
book.similar_books #=> [...]
 
Example 2
=========
 
class Movie < ActiveRecord::Base
  has_many :user_movies
  has_many :users, :through => :user_movies
end
 
class UserMovie < ActiveRecord::Base
  belongs_to :movie
  belongs_to :user
end
 
class User < ActiveRecord::Base
  has_many :user_movies
  has_many :movies, :through => :user_movies
  acts_as_recommendable :movies, :through => :user_movies, :score => :score
  # 'score' is an attribute on the users_movies table
end
 
user = User.find(:first)
user.similar_users #=> [...]
user.recommended_movies #=> [...]
 
Example 3
=========
 
class Book < ActiveRecord::Base
  has_many :user_books
  has_many :users, :through => :user_books, :use_dataset => true
  # Uses cached dataset
end
 
class UserBook < ActiveRecord::Base
  belongs_to :book
  belongs_to :user
end
 
class User < ActiveRecord::Base
  has_many :user_books
  has_many :books, :through => :user_books
  acts_as_recommendable :books, :through => :user_books
end
 
user = User.find(:first)
user.recommended_books #=> [...]
 
# The example above uses a cached dataset.
# You need to generate a cached dataset every so often (depending on how much your content changes)
# You can do that by calling the rake task recommendations:build, you should run this with a cron job every so often.
 
  
# If you only want to use the dataset in production put this in production.rb:
  User.aar_options[:use_dataset] = true
  
# Note:
# user.similar_users doesn't use the dataset
#
# The advantage of using a dataset is that you don't need to load all the users & items into
# memory (which you do normally). The disadvantage is that you won't get as accurate results.
#
 
Contact
=======
alex@madebymany.co.uk
 
 
Copyright (c) 2008 Made by Many Ltd, released under the MIT license