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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d476a1f153c942bce7b6ab5bcb6e3482547fa01b
4
- data.tar.gz: 0cd9fe4e61335cb42e00ee7934ede7d8cd896658
3
+ metadata.gz: 8220249daec5efad651f9ccf7907cdd45b069969
4
+ data.tar.gz: 2b443b21b6b270ec7e042f29fb4a7b66a502b1c5
5
5
  SHA512:
6
- metadata.gz: 945a4ef7009955375496c5666133a7e56929b33171a7336e0614160442793db8874367c55c5d1a58d7890e150f0fc99adbf680a162886d6c536d72f078b4296f
7
- data.tar.gz: 141573132f47069e3504a86be9b68d0cd3765204894b37d069afe1768a5d0de9a41967e32bea4b785790b2c11f7e2458d15bc3519dc09cdb927aa04befd6cddc
6
+ metadata.gz: ef373588718fda497258e5b09c395c2d46cd4122f611d34e130efc56ff7810933a30a45c65440d7813ae6ed3aca160b9b03ce05e9540071256dac1896901ab08
7
+ data.tar.gz: e0fcdb9c5ebf93ef5bb5a70d54c5a4a831c66c4d4726cff8447e7a238c67ac8f08ba91094ce4b51bf616e3664a82e163fcb1188ba88b9b43941c0d57ea04405a
data/.rspec CHANGED
@@ -1,4 +1,3 @@
1
1
  --color
2
- --warnings
3
2
  --format documentation
4
3
  --require spec_helper
data/README.md CHANGED
@@ -16,7 +16,7 @@ gem 'apriori-ruby'
16
16
 
17
17
  Sample Usage
18
18
  ```ruby
19
- test_data = {t1: [1,2,3,4], t2:[1,2,4,5], t3: [2,3,4,5]}
19
+ test_data = [[1,2,3,4], [1,2,4,5], [2,3,4,5]]
20
20
  item_set = Apriori::ItemSet.new(test_data)
21
21
  support = 50
22
22
  confidence = 60
@@ -1,30 +1,30 @@
1
1
  module Apriori
2
2
  class ItemSet
3
- attr_reader :data_set, :min_support, :min_confidence
3
+ attr_reader :transactions, :min_support, :min_confidence
4
4
 
5
- def initialize(data_set)
6
- @data_set = data_set
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 unless frequent_item_sets.any?
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, confidence| confidence >= min_confidence }
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 / data_set.size) * 100
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
- data_set.map do |transaction, items|
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
- attr_reader :candidates
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(reject_candidates)
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 reject_candidates
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
@@ -1,3 +1,3 @@
1
1
  module Apriori
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -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: Hash do
7
- t1 ['Mango', 'Onion', 'Nintendo', 'Keychain', 'Eggs', 'Yoyo']
8
- t2 ['Doll', 'Onion', 'Nintendo', 'Keychain', 'Eggs', 'Yoyo']
9
- t3 ['Mango', 'Apple', 'Keychain', 'Eggs']
10
- t4 ['Mango', 'Umbrella', 'Corn', 'Keychain', 'Yoyo']
11
- t5 ['Corn', 'Onion', 'Onion', 'Keychain', 'Icecream', 'Eggs']
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({:t1 => ['1','2','3'], :t2 => ['1','2','4'], :t3 => ['1','4','5']})
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({:t1 => ['1','2','3'], :t2 => ['1','2','4'], :t3 => ['1','4','5']})
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.8
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: 2014-10-06 00:00:00.000000000 Z
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
- - ".gitignore"
63
- - ".rspec"
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.2.2
97
+ rubygems_version: 2.0.14
100
98
  signing_key:
101
99
  specification_version: 4
102
100
  summary: Ruby implementation of Apriori Algorithm
@@ -1 +0,0 @@
1
- 2.1.2
@@ -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