apriori-ruby 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +0 -1
- data/README.md +1 -1
- data/lib/apriori/item_set.rb +16 -17
- data/lib/apriori/version.rb +1 -1
- data/spec/factories/apriori/apriori.rb +6 -7
- data/spec/lib/apriori/item_set_spec.rb +2 -2
- metadata +13 -15
- data/.ruby-version +0 -1
- data/Gemfile.lock +0 -46
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8220249daec5efad651f9ccf7907cdd45b069969
|
|
4
|
+
data.tar.gz: 2b443b21b6b270ec7e042f29fb4a7b66a502b1c5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ef373588718fda497258e5b09c395c2d46cd4122f611d34e130efc56ff7810933a30a45c65440d7813ae6ed3aca160b9b03ce05e9540071256dac1896901ab08
|
|
7
|
+
data.tar.gz: e0fcdb9c5ebf93ef5bb5a70d54c5a4a831c66c4d4726cff8447e7a238c67ac8f08ba91094ce4b51bf616e3664a82e163fcb1188ba88b9b43941c0d57ea04405a
|
data/.rspec
CHANGED
data/README.md
CHANGED
data/lib/apriori/item_set.rb
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
module Apriori
|
|
2
2
|
class ItemSet
|
|
3
|
-
attr_reader :
|
|
3
|
+
attr_reader :transactions, :min_support, :min_confidence
|
|
4
4
|
|
|
5
|
-
def initialize(
|
|
6
|
-
@
|
|
5
|
+
def initialize(transactions)
|
|
6
|
+
@transactions = transactions
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def mine(min_support=0, min_confidence=0)
|
|
10
|
-
@min_support, @min_confidence = min_support, min_confidence
|
|
10
|
+
@min_support, @min_confidence, @candidates = min_support, min_confidence, nil
|
|
11
11
|
create_frequent_item_sets(min_support)
|
|
12
12
|
create_association_rules(min_confidence)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def create_frequent_item_sets min_support
|
|
16
16
|
@min_support = min_support
|
|
17
|
-
make_item_sets
|
|
17
|
+
make_item_sets
|
|
18
18
|
frequent_item_sets
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def create_association_rules min_confidence
|
|
22
22
|
make_association_rules unless frequent_item_sets.empty?
|
|
23
|
-
association_rules.select{ |name,
|
|
23
|
+
association_rules.select{ |name, rule| rule >= min_confidence }
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def support item
|
|
27
|
-
(count_frequency(item).to_f /
|
|
27
|
+
(count_frequency(item).to_f / transactions.size) * 100
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def confidence set1, set2
|
|
@@ -32,18 +32,20 @@ module Apriori
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def count_frequency set
|
|
35
|
-
|
|
35
|
+
transactions.map do |items|
|
|
36
36
|
contains_all?(items, set)
|
|
37
|
-
end.reject {|item| item == false }.size
|
|
37
|
+
end.reject { |item| item == false }.size
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
private
|
|
41
|
-
|
|
41
|
+
|
|
42
|
+
def candidates
|
|
43
|
+
@candidates ||= transactions.flatten.uniq.map { |item| [item] }
|
|
44
|
+
end
|
|
42
45
|
|
|
43
46
|
def make_item_sets
|
|
44
|
-
@candidates = initial_data_set
|
|
45
47
|
while candidates.any?
|
|
46
|
-
list = List.new(
|
|
48
|
+
list = List.new(new_candidates)
|
|
47
49
|
frequent_item_sets << list
|
|
48
50
|
@candidates = list.make_candidates
|
|
49
51
|
end
|
|
@@ -74,12 +76,9 @@ module Apriori
|
|
|
74
76
|
set.to_set.superset? subset.to_set
|
|
75
77
|
end
|
|
76
78
|
|
|
77
|
-
def
|
|
78
|
-
candidates.reject{|item| support(item) < min_support}
|
|
79
|
+
def new_candidates
|
|
80
|
+
candidates.reject{ |item| support(item) < min_support }
|
|
79
81
|
end
|
|
80
82
|
|
|
81
|
-
def initial_data_set
|
|
82
|
-
@initial_data_set ||= @data_set.values.flatten.uniq.map{|item| [item]}
|
|
83
|
-
end
|
|
84
83
|
end
|
|
85
84
|
end
|
data/lib/apriori/version.rb
CHANGED
|
@@ -3,12 +3,11 @@ FactoryGirl.define do
|
|
|
3
3
|
initialize_with {new(FactoryGirl.build(:sample_data))}
|
|
4
4
|
end
|
|
5
5
|
|
|
6
|
-
factory :sample_data, class:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
initialize_with { attributes }
|
|
6
|
+
factory :sample_data, class: Array do
|
|
7
|
+
initialize_with { [['Mango', 'Onion', 'Nintendo', 'Keychain', 'Eggs', 'Yoyo'],
|
|
8
|
+
['Doll', 'Onion', 'Nintendo', 'Keychain', 'Eggs', 'Yoyo'],
|
|
9
|
+
['Mango', 'Apple', 'Keychain', 'Eggs'],
|
|
10
|
+
['Mango', 'Umbrella', 'Corn', 'Keychain', 'Yoyo'],
|
|
11
|
+
['Corn', 'Onion', 'Onion', 'Keychain', 'Icecream', 'Eggs']] }
|
|
13
12
|
end
|
|
14
13
|
end
|
|
@@ -33,14 +33,14 @@ describe Apriori::ItemSet do
|
|
|
33
33
|
|
|
34
34
|
context '#create_frequent_item_sets' do
|
|
35
35
|
it 'creates frequent item sets for a given support' do
|
|
36
|
-
@set = Apriori::ItemSet.new(
|
|
36
|
+
@set = Apriori::ItemSet.new([['1','2','3'], ['1','2','4'], ['1','4','5']])
|
|
37
37
|
expect(@set.create_frequent_item_sets(60).first.sets).to eql([['1'],['2'],['4']])
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
context '#create_association_rules' do
|
|
42
42
|
it 'creates association rules for all combinations' do
|
|
43
|
-
@set = Apriori::ItemSet.new(
|
|
43
|
+
@set = Apriori::ItemSet.new([['1','2','3'], ['1','2','4'], ['1','4','5']])
|
|
44
44
|
@set.create_frequent_item_sets(60)
|
|
45
45
|
expect(@set.create_association_rules(60)).to eql({"1=>2"=>66.66666666666666, "2=>1"=>100.0, "1=>4"=>66.66666666666666, "4=>1"=>100.0})
|
|
46
46
|
end
|
metadata
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: apriori-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bryan Mulvihill
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2015-07-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- -
|
|
17
|
+
- - ~>
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
19
|
version: '1.7'
|
|
20
20
|
type: :development
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- -
|
|
24
|
+
- - ~>
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '1.7'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: rake
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- -
|
|
31
|
+
- - ~>
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
33
|
version: '10.0'
|
|
34
34
|
type: :development
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- -
|
|
38
|
+
- - ~>
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '10.0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: rspec
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- -
|
|
45
|
+
- - '>='
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
47
|
version: '0'
|
|
48
48
|
type: :development
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- -
|
|
52
|
+
- - '>='
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '0'
|
|
55
55
|
description:
|
|
@@ -59,11 +59,9 @@ executables: []
|
|
|
59
59
|
extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
|
61
61
|
files:
|
|
62
|
-
-
|
|
63
|
-
-
|
|
64
|
-
- ".ruby-version"
|
|
62
|
+
- .gitignore
|
|
63
|
+
- .rspec
|
|
65
64
|
- Gemfile
|
|
66
|
-
- Gemfile.lock
|
|
67
65
|
- LICENSE.txt
|
|
68
66
|
- README.md
|
|
69
67
|
- Rakefile
|
|
@@ -86,17 +84,17 @@ require_paths:
|
|
|
86
84
|
- lib
|
|
87
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
86
|
requirements:
|
|
89
|
-
- -
|
|
87
|
+
- - '>='
|
|
90
88
|
- !ruby/object:Gem::Version
|
|
91
89
|
version: '0'
|
|
92
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
91
|
requirements:
|
|
94
|
-
- -
|
|
92
|
+
- - '>='
|
|
95
93
|
- !ruby/object:Gem::Version
|
|
96
94
|
version: '0'
|
|
97
95
|
requirements: []
|
|
98
96
|
rubyforge_project:
|
|
99
|
-
rubygems_version: 2.
|
|
97
|
+
rubygems_version: 2.0.14
|
|
100
98
|
signing_key:
|
|
101
99
|
specification_version: 4
|
|
102
100
|
summary: Ruby implementation of Apriori Algorithm
|
data/.ruby-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
2.1.2
|
data/Gemfile.lock
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: .
|
|
3
|
-
specs:
|
|
4
|
-
apriori (0.0.1)
|
|
5
|
-
|
|
6
|
-
GEM
|
|
7
|
-
remote: https://rubygems.org/
|
|
8
|
-
specs:
|
|
9
|
-
activesupport (4.1.5)
|
|
10
|
-
i18n (~> 0.6, >= 0.6.9)
|
|
11
|
-
json (~> 1.7, >= 1.7.7)
|
|
12
|
-
minitest (~> 5.1)
|
|
13
|
-
thread_safe (~> 0.1)
|
|
14
|
-
tzinfo (~> 1.1)
|
|
15
|
-
diff-lcs (1.2.5)
|
|
16
|
-
factory_girl (4.4.0)
|
|
17
|
-
activesupport (>= 3.0.0)
|
|
18
|
-
i18n (0.6.11)
|
|
19
|
-
json (1.8.1)
|
|
20
|
-
minitest (5.4.0)
|
|
21
|
-
rake (10.3.2)
|
|
22
|
-
rspec (3.0.0)
|
|
23
|
-
rspec-core (~> 3.0.0)
|
|
24
|
-
rspec-expectations (~> 3.0.0)
|
|
25
|
-
rspec-mocks (~> 3.0.0)
|
|
26
|
-
rspec-core (3.0.4)
|
|
27
|
-
rspec-support (~> 3.0.0)
|
|
28
|
-
rspec-expectations (3.0.4)
|
|
29
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
|
30
|
-
rspec-support (~> 3.0.0)
|
|
31
|
-
rspec-mocks (3.0.4)
|
|
32
|
-
rspec-support (~> 3.0.0)
|
|
33
|
-
rspec-support (3.0.4)
|
|
34
|
-
thread_safe (0.3.4)
|
|
35
|
-
tzinfo (1.2.2)
|
|
36
|
-
thread_safe (~> 0.1)
|
|
37
|
-
|
|
38
|
-
PLATFORMS
|
|
39
|
-
ruby
|
|
40
|
-
|
|
41
|
-
DEPENDENCIES
|
|
42
|
-
apriori!
|
|
43
|
-
bundler (~> 1.7)
|
|
44
|
-
factory_girl
|
|
45
|
-
rake (~> 10.0)
|
|
46
|
-
rspec
|