disco 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +3 -5
- data/lib/disco/model.rb +1 -0
- data/lib/disco/recommender.rb +8 -2
- data/lib/disco/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ec370f448c5cc8aebb2860b0580466687874eb34c165e1a3d0254a1c6e701d7
|
4
|
+
data.tar.gz: 1b080c37206371ee59ce184ae420c5fa1de60da0714ef17ea9459b31fcdd22ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1802e0fbf68ee489891f94e468c3b24df0eb8463de4e55a7f50a9dbc86bda7631ca15d5b84d0d584dbd341e994db84a82f00f6753c70eda4a7400376f0443df5
|
7
|
+
data.tar.gz: bee0645357a5fc4eb226e75d4b56208e7377952911dd19ccad8f3072eee3eaf4d4a318933dcb4ec4d75273630e278dbf98b3ac21f5987baea90261d15cc2d851
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -44,6 +44,8 @@ recommender.fit([
|
|
44
44
|
])
|
45
45
|
```
|
46
46
|
|
47
|
+
> Each `user_id`/`item_id` combination should only appear once
|
48
|
+
|
47
49
|
Get user-based recommendations - “users like you also liked”
|
48
50
|
|
49
51
|
```ruby
|
@@ -97,11 +99,7 @@ recommender.item_recs("Star Wars (1977)")
|
|
97
99
|
[Ahoy](https://github.com/ankane/ahoy) is a great source for implicit feedback
|
98
100
|
|
99
101
|
```ruby
|
100
|
-
views = Ahoy::Event.
|
101
|
-
where(name: "Viewed post").
|
102
|
-
group(:user_id).
|
103
|
-
group("properties->>'post_id'"). # postgres syntax
|
104
|
-
count
|
102
|
+
views = Ahoy::Event.where(name: "Viewed post").group(:user_id).group_prop(:post_id).count
|
105
103
|
|
106
104
|
data =
|
107
105
|
views.map do |(user_id, post_id), _|
|
data/lib/disco/model.rb
CHANGED
@@ -10,6 +10,7 @@ module Disco
|
|
10
10
|
|
11
11
|
has_many :"recommended_#{name}", -> { where("disco_recommendations.context = ?", name).order("disco_recommendations.score DESC") }, through: :recommendations, source: :item, source_type: class_name
|
12
12
|
|
13
|
+
# TODO use fetch for item_id and score in 0.3.0
|
13
14
|
define_method("update_recommended_#{name}") do |items|
|
14
15
|
now = Time.now
|
15
16
|
items = items.map { |item| {subject_type: model_name.name, subject_id: id, item_type: class_name, item_id: item[:item_id], context: name, score: item[:score], created_at: now, updated_at: now} }
|
data/lib/disco/recommender.rb
CHANGED
@@ -185,7 +185,13 @@ module Disco
|
|
185
185
|
else
|
186
186
|
require "wilson_score"
|
187
187
|
|
188
|
-
range =
|
188
|
+
range =
|
189
|
+
if @min_rating == @max_rating
|
190
|
+
# TODO remove temp fix
|
191
|
+
(@min_rating - 1)..@max_rating
|
192
|
+
else
|
193
|
+
@min_rating..@max_rating
|
194
|
+
end
|
189
195
|
scores = Numo::DFloat.cast(@item_sum.zip(@item_count).map { |s, c| WilsonScore.rating_lower_bound(s / c, c, range) })
|
190
196
|
|
191
197
|
# TODO uncomment in 0.3.0
|
@@ -195,7 +201,7 @@ module Disco
|
|
195
201
|
# range = @max_rating - @min_rating
|
196
202
|
# n = Numo::DFloat.cast(@item_count)
|
197
203
|
# phat = (Numo::DFloat.cast(@item_sum) - (@min_rating * n)) / range / n
|
198
|
-
# phat = (phat - (1 / 2 * n)).clip(0,
|
204
|
+
# phat = (phat - (1 / (2 * n))).clip(0, nil) # continuity correction
|
199
205
|
# scores = (phat + z**2 / (2 * n) - z * Numo::DFloat::Math.sqrt((phat * (1 - phat) + z**2 / (4 * n)) / n)) / (1 + z**2 / n)
|
200
206
|
# scores = scores * range + @min_rating
|
201
207
|
end
|
data/lib/disco/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: disco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: libmf
|
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
requirements: []
|
79
|
-
rubygems_version: 3.
|
79
|
+
rubygems_version: 3.3.7
|
80
80
|
signing_key:
|
81
81
|
specification_version: 4
|
82
82
|
summary: Recommendations for Ruby and Rails using collaborative filtering
|