recommendation 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/VERSION +1 -1
- data/demo.rb +5 -4
- data/doc/ChangeLog +5 -0
- data/lib/recommendation.rb +1 -1
- data/lib/recommendation/engine.rb +4 -3
- data/recommendation.gemspec +3 -3
- data/spec/lib/recommendation/engine_spec.rb +77 -11
- data/spec/lib/recommendation/supervisor_spec.rb +14 -4
- data/spec/lib/recommendation_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc32f50776319a3b9cc96b83a3a5eab90696f393
|
4
|
+
data.tar.gz: 6dfcb3869f168e4e8165bc3924a537ebd395d9ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ea965bd5b976ee775be4417131538b0c49213e744369d901795ef54ebd12cda31aa34b25dd3cc83107537c919cc14c85a40537f9cc2fe5874ae2b35cedb6d44
|
7
|
+
data.tar.gz: be255225fc628bfcd52b870bcdabc513c96725601141bc197cf805230a00ba52fcb8df604d3d24ee096ae61c40b1828ac28830d1e9c3b6eb5e85b28a9bb680e2
|
data/README.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/demo.rb
CHANGED
@@ -10,12 +10,13 @@ def demo
|
|
10
10
|
supervisor.train(new_comer)
|
11
11
|
engine = Recommendation::Engine.new
|
12
12
|
|
13
|
-
p engine.recommendation(supervisor.table, 'Toby') # =>
|
14
|
-
|
15
|
-
p engine.top_matches(supervisor.table, 'Toby') # =>
|
13
|
+
p engine.recommendation(supervisor.table, 'Toby') # => [["The Night Listener", 3.3477895267131017], ["Lady in the Water", 2.8325499182641614], ["Just My Luck", 2.530980703765565]]
|
14
|
+
|
15
|
+
p engine.top_matches(supervisor.table, 'Toby') # => [["Lisa Rose", 0.9912407071619299], ["Mick LaSalle", 0.9244734516419049], ["Claudia Puig", 0.8934051474415647], ["Jack Matthews", 0.66284898035987], ["Gene Seymour", 0.38124642583151164]]
|
16
16
|
|
17
17
|
movies = supervisor.transform_table
|
18
|
-
p engine.top_matches(movies, 'Superman Returns') # =>
|
18
|
+
p engine.top_matches(movies, 'Superman Returns') # => [["You, Me and Dupree", 0.6579516949597695], ["Lady in the Water", 0.4879500364742689], ["Snake on the Plane", 0.11180339887498941], ["The Night Listener", -0.1798471947990544], ["Just My Luck", -0.42289003161103106]]
|
19
|
+
|
19
20
|
end
|
20
21
|
|
21
22
|
def new_comer
|
data/doc/ChangeLog
CHANGED
data/lib/recommendation.rb
CHANGED
@@ -23,7 +23,7 @@ module Recommendation
|
|
23
23
|
rankings[item] = total/sim_sums_h[item]
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
rankings.sort_by{|k, v| -v}
|
27
27
|
end
|
28
28
|
|
29
29
|
def top_matches(table, user, n=5, similarity=:sim_pearson)
|
@@ -33,9 +33,10 @@ module Recommendation
|
|
33
33
|
scores << [__send__(similarity, table, user,key), key]
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
|
+
result = Array.new
|
37
38
|
scores.sort.reverse[0,n].each do |k, v|
|
38
|
-
result[v
|
39
|
+
result << [v, k]
|
39
40
|
end
|
40
41
|
result
|
41
42
|
end
|
data/recommendation.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: recommendation 0.
|
5
|
+
# stub: recommendation 0.2.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "recommendation"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.2.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.authors = ["id774"]
|
13
|
-
s.date = "2013-10-
|
13
|
+
s.date = "2013-10-19"
|
14
14
|
s.description = "Collaborative filtering for recommender system"
|
15
15
|
s.email = "idnanashi@gmail.com"
|
16
16
|
s.extra_rdoc_files = [
|
@@ -6,28 +6,57 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|
6
6
|
describe 'Recommendation::Engine' do
|
7
7
|
describe 'recommendation' do
|
8
8
|
it 'should be suggesting interesting products' do
|
9
|
-
expected =
|
10
|
-
|
9
|
+
expected = [
|
10
|
+
["The Night Listener", 3.3477895267131017],
|
11
|
+
["Lady in the Water", 2.8325499182641614],
|
12
|
+
["Just My Luck", 2.530980703765565]
|
13
|
+
]
|
11
14
|
|
12
15
|
supervisor = Recommendation::Supervisor.new(visitors)
|
13
16
|
supervisor.train(new_comer)
|
14
17
|
engine = Recommendation::Engine.new
|
15
18
|
|
16
19
|
new_comer.keys[0].should be_eql 'Toby'
|
17
|
-
engine.recommendation(supervisor.table, new_comer.keys[0])
|
20
|
+
result = engine.recommendation(supervisor.table, new_comer.keys[0])
|
21
|
+
|
22
|
+
result.length.should be_eql 3
|
23
|
+
result[0][0].should be_eql expected[0][0]
|
24
|
+
result[0][1].should be_eql expected[0][1]
|
25
|
+
result[1][0].should be_eql expected[1][0]
|
26
|
+
result[1][1].should be_eql expected[1][1]
|
27
|
+
result[2][0].should be_eql expected[2][0]
|
28
|
+
result[2][1].should be_eql expected[2][1]
|
18
29
|
end
|
19
30
|
end
|
20
31
|
|
21
32
|
describe 'top_matches' do
|
22
33
|
it 'should be finding similar users' do
|
23
|
-
expected =
|
34
|
+
expected = [
|
35
|
+
["Lisa Rose", 0.9912407071619299],
|
36
|
+
["Mick LaSalle", 0.9244734516419049],
|
37
|
+
["Claudia Puig", 0.8934051474415647],
|
38
|
+
["Jack Matthews", 0.66284898035987],
|
39
|
+
["Gene Seymour", 0.38124642583151164]
|
40
|
+
]
|
24
41
|
|
25
42
|
supervisor = Recommendation::Supervisor.new(visitors)
|
26
43
|
supervisor.train(new_comer)
|
27
44
|
engine = Recommendation::Engine.new
|
28
45
|
|
29
46
|
new_comer.keys[0].should be_eql 'Toby'
|
30
|
-
engine.top_matches(supervisor.table, new_comer.keys[0])
|
47
|
+
result = engine.top_matches(supervisor.table, new_comer.keys[0])
|
48
|
+
|
49
|
+
result.length.should be_eql 5
|
50
|
+
result[0][0].should be_eql expected[0][0]
|
51
|
+
result[0][1].should be_eql expected[0][1]
|
52
|
+
result[1][0].should be_eql expected[1][0]
|
53
|
+
result[1][1].should be_eql expected[1][1]
|
54
|
+
result[2][0].should be_eql expected[2][0]
|
55
|
+
result[2][1].should be_eql expected[2][1]
|
56
|
+
result[3][0].should be_eql expected[3][0]
|
57
|
+
result[3][1].should be_eql expected[3][1]
|
58
|
+
result[4][0].should be_eql expected[4][0]
|
59
|
+
result[4][1].should be_eql expected[4][1]
|
31
60
|
end
|
32
61
|
end
|
33
62
|
|
@@ -44,7 +73,13 @@ describe 'Recommendation::Engine' do
|
|
44
73
|
|
45
74
|
describe 'reversed critics' do
|
46
75
|
it 'should be found similar items' do
|
47
|
-
expected =
|
76
|
+
expected = [
|
77
|
+
["You, Me and Dupree", 0.6579516949597695],
|
78
|
+
["Lady in the Water", 0.4879500364742689],
|
79
|
+
["Snake on the Plane", 0.11180339887498941],
|
80
|
+
["The Night Listener", -0.1798471947990544],
|
81
|
+
["Just My Luck", -0.42289003161103106]
|
82
|
+
]
|
48
83
|
|
49
84
|
supervisor = Recommendation::Supervisor.new(visitors)
|
50
85
|
supervisor.train(new_comer)
|
@@ -53,31 +88,62 @@ describe 'Recommendation::Engine' do
|
|
53
88
|
movies = supervisor.transform_table
|
54
89
|
|
55
90
|
new_comer.values[0].keys[2].should be_eql 'Superman Returns'
|
56
|
-
engine.top_matches(movies, new_comer.values[0].keys[2])
|
91
|
+
result = engine.top_matches(movies, new_comer.values[0].keys[2])
|
92
|
+
|
93
|
+
result.length.should be_eql 5
|
94
|
+
result[0][0].should be_eql expected[0][0]
|
95
|
+
result[0][1].should be_eql expected[0][1]
|
96
|
+
result[1][0].should be_eql expected[1][0]
|
97
|
+
result[1][1].should be_eql expected[1][1]
|
98
|
+
result[2][0].should be_eql expected[2][0]
|
99
|
+
result[2][1].should be_eql expected[2][1]
|
100
|
+
result[3][0].should be_eql expected[3][0]
|
101
|
+
result[3][1].should be_eql expected[3][1]
|
102
|
+
result[4][0].should be_eql expected[4][0]
|
103
|
+
result[4][1].should be_eql expected[4][1]
|
57
104
|
end
|
58
105
|
end
|
59
106
|
|
60
107
|
describe 'recommendation for the unexisting user' do
|
61
108
|
it 'should return empty array' do
|
62
|
-
expected =
|
109
|
+
expected = []
|
63
110
|
|
64
111
|
supervisor = Recommendation::Supervisor.new(visitors)
|
65
112
|
supervisor.train(new_comer)
|
66
113
|
engine = Recommendation::Engine.new
|
67
114
|
|
68
|
-
engine.recommendation(supervisor.table, 'hoge')
|
115
|
+
result = engine.recommendation(supervisor.table, 'hoge')
|
116
|
+
result.length.should be_eql 0
|
69
117
|
end
|
70
118
|
end
|
71
119
|
|
72
120
|
describe 'top_matches for the unexisting item' do
|
73
121
|
it 'should return all zero score' do
|
74
|
-
expected =
|
122
|
+
expected = [
|
123
|
+
["Toby", 0],
|
124
|
+
["Mick LaSalle", 0],
|
125
|
+
["Michael Phillips", 0],
|
126
|
+
["Lisa Rose", 0],
|
127
|
+
["Jack Matthews", 0]
|
128
|
+
]
|
75
129
|
|
76
130
|
supervisor = Recommendation::Supervisor.new(visitors)
|
77
131
|
supervisor.train(new_comer)
|
78
132
|
engine = Recommendation::Engine.new
|
79
133
|
|
80
|
-
engine.top_matches(supervisor.table, 'fuga')
|
134
|
+
result = engine.top_matches(supervisor.table, 'fuga')
|
135
|
+
|
136
|
+
result.length.should be_eql 5
|
137
|
+
result[0][0].should be_eql expected[0][0]
|
138
|
+
result[0][1].should be_eql expected[0][1]
|
139
|
+
result[1][0].should be_eql expected[1][0]
|
140
|
+
result[1][1].should be_eql expected[1][1]
|
141
|
+
result[2][0].should be_eql expected[2][0]
|
142
|
+
result[2][1].should be_eql expected[2][1]
|
143
|
+
result[3][0].should be_eql expected[3][0]
|
144
|
+
result[3][1].should be_eql expected[3][1]
|
145
|
+
result[4][0].should be_eql expected[4][0]
|
146
|
+
result[4][1].should be_eql expected[4][1]
|
81
147
|
end
|
82
148
|
end
|
83
149
|
end
|
@@ -31,13 +31,23 @@ describe 'Recommendation::Supervisor' do
|
|
31
31
|
supervisor = Recommendation::Supervisor.new(merged_data)
|
32
32
|
engine = Recommendation::Engine.new
|
33
33
|
|
34
|
-
expected =
|
34
|
+
expected = [["item_6", 220.0]]
|
35
35
|
result = engine.recommendation(supervisor.table, 'user_4')
|
36
|
-
result.should be_eql expected
|
37
36
|
|
38
|
-
|
37
|
+
result.length.should be_eql 1
|
38
|
+
result[0][0].should be_eql expected[0][0]
|
39
|
+
result[0][1].should be_eql expected[0][1]
|
40
|
+
|
41
|
+
expected = [["user_2", 1.0], ["user_1", 1.0], ["user_3", 0]]
|
39
42
|
result = engine.top_matches(supervisor.table, 'user_4')
|
40
|
-
|
43
|
+
|
44
|
+
result.length.should be_eql 3
|
45
|
+
result[0][0].should be_eql expected[0][0]
|
46
|
+
result[0][1].should be_eql expected[0][1]
|
47
|
+
result[1][0].should be_eql expected[1][0]
|
48
|
+
result[1][1].should be_eql expected[1][1]
|
49
|
+
result[2][0].should be_eql expected[2][0]
|
50
|
+
result[2][1].should be_eql expected[2][1]
|
41
51
|
end
|
42
52
|
end
|
43
53
|
end
|
@@ -5,7 +5,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
5
5
|
describe Recommendation do
|
6
6
|
context 'const get :VERSION should' do
|
7
7
|
it "return right version number" do
|
8
|
-
expect = '0.
|
8
|
+
expect = '0.2.0'
|
9
9
|
Recommendation.const_get(:VERSION).should be_true
|
10
10
|
Recommendation.const_get(:VERSION).should == expect
|
11
11
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recommendation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- id774
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cucumber
|