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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c9fe3ebc82e9c1e6c2f2e1f0a987bcb93c3c8da
4
- data.tar.gz: ed83cfffc38e9d2f0f97751b6eafc6fb5d47fdd0
3
+ metadata.gz: fc32f50776319a3b9cc96b83a3a5eab90696f393
4
+ data.tar.gz: 6dfcb3869f168e4e8165bc3924a537ebd395d9ca
5
5
  SHA512:
6
- metadata.gz: 6f0471a8661ee4494157d1d44a96c72d87a1fb01f25eec59ebe26176ac0d3e450d6eeb5be8914e2d8a7e25b137a12fbfae1176237ac0ea5f4301df60a5600b01
7
- data.tar.gz: dc641b5c76dc6a4a4f02793d357519af52a08f61db35591b79061361b9f6a2a08fcc95085748dbe95f5ca6889994a544f64354662ae2b0dfacd84c924d02c22e
6
+ metadata.gz: 0ea965bd5b976ee775be4417131538b0c49213e744369d901795ef54ebd12cda31aa34b25dd3cc83107537c919cc14c85a40537f9cc2fe5874ae2b35cedb6d44
7
+ data.tar.gz: be255225fc628bfcd52b870bcdabc513c96725601141bc197cf805230a00ba52fcb8df604d3d24ee096ae61c40b1828ac28830d1e9c3b6eb5e85b28a9bb680e2
data/README.md CHANGED
@@ -3,6 +3,8 @@ Recommendation
3
3
 
4
4
  **Collaborative filtering for recommender system**
5
5
 
6
+ The gem is intended to implement collaborative filtering alone. (not use KVS.)
7
+
6
8
 
7
9
  What is Recommendation
8
10
  ----------------------
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
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') # => {"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}
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') # => {"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}
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
@@ -1,3 +1,8 @@
1
+ === 0.2.0 / 2013-10-19
2
+
3
+ * Change output format to Array.
4
+
5
+
1
6
  === 0.1.3 / 2013-10-18
2
7
 
3
8
  * First release.
@@ -2,7 +2,7 @@
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
4
  module Recommendation
5
- VERSION = "0.1.3"
5
+ VERSION = "0.2.0"
6
6
  require File.dirname(__FILE__) + "/recommendation/supervisor"
7
7
  require File.dirname(__FILE__) + "/recommendation/engine"
8
8
  end
@@ -23,7 +23,7 @@ module Recommendation
23
23
  rankings[item] = total/sim_sums_h[item]
24
24
  end
25
25
 
26
- Hash[rankings.sort_by{|k, v| -v}]
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
- result = Hash.new
36
+
37
+ result = Array.new
37
38
  scores.sort.reverse[0,n].each do |k, v|
38
- result[v] = k
39
+ result << [v, k]
39
40
  end
40
41
  result
41
42
  end
@@ -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.1.3 ruby lib
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.1.3"
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-18"
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 = {"The Night Listener"=>3.3477895267131017, "Lady in the Water"=>2.8325499182641614, "Just My Luck"=>2.530980703765565}
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]).should be_eql expected
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 ={"Lisa Rose"=>0.9912407071619299, "Mick LaSalle"=>0.9244734516419049, "Claudia Puig"=>0.8934051474415647, "Jack Matthews"=>0.66284898035987, "Gene Seymour"=>0.38124642583151164}
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]).should be_eql expected
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 = {"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}
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]).should be_eql expected
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').should be_eql expected
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 = {"Toby"=>0, "Mick LaSalle"=>0, "Michael Phillips"=>0, "Lisa Rose"=>0, "Jack Matthews"=>0}
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').should be_eql expected
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 = {"item_6" => 220.0}
34
+ expected = [["item_6", 220.0]]
35
35
  result = engine.recommendation(supervisor.table, 'user_4')
36
- result.should be_eql expected
37
36
 
38
- expected = {"user_2"=>1.0, "user_1"=>1.0, "user_3"=>0}
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
- result.should be_eql expected
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.1.3'
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.1.3
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-18 00:00:00.000000000 Z
11
+ date: 2013-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber