Skip to content

Commit dd8130a

Browse files
committed
Change rules array schema
1 parent 26c852b commit dd8130a

File tree

2 files changed

+74
-24
lines changed

2 files changed

+74
-24
lines changed

README.md

Lines changed: 73 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ Where key is itemset, value is support of that itemset
4747
Rules returns as array of arrays like:
4848

4949
[
50-
['ITEM_1,ITEM_2' => ['ITEM_3',0.7]],
51-
['ITEM_4' => ['ITEM_5',0.7]],
50+
['ITEM_1,ITEM_2', 'ITEM_3', 0.7],
51+
['ITEM_4','ITEM_5', 0.7],
5252
...
5353
]
5454

55-
Where keys is left path of rule, value is array, where first item is right path of the rule and second item is confidence of that rule
55+
Where first value is left path of that rule, second value is right path of that rule and third value is confidence of that rule
5656

5757
#### Result with example transactions
5858

@@ -83,54 +83,104 @@ Where keys is left path of rule, value is array, where first item is right path
8383

8484
`var_dump($rules);`
8585

86-
array(7) {
87-
["M"]=>
88-
array(2) {
86+
array(11) {
87+
[0]=>
88+
array(3) {
8989
[0]=>
90-
string(1) "K"
90+
string(1) "M"
9191
[1]=>
92+
string(1) "K"
93+
[2]=>
9294
float(1)
9395
}
94-
["Y"]=>
95-
array(2) {
96+
[1]=>
97+
array(3) {
9698
[0]=>
99+
string(1) "Y"
100+
[1]=>
97101
string(1) "K"
102+
[2]=>
103+
float(1)
104+
}
105+
[2]=>
106+
array(3) {
107+
[0]=>
108+
string(1) "O"
98109
[1]=>
110+
string(1) "E"
111+
[2]=>
99112
float(1)
100113
}
101-
["O"]=>
102-
array(2) {
114+
[3]=>
115+
array(3) {
103116
[0]=>
104117
string(1) "K"
105118
[1]=>
106-
float(1)
119+
string(1) "E"
120+
[2]=>
121+
float(0.8)
107122
}
108-
["K"]=>
109-
array(2) {
123+
[4]=>
124+
array(3) {
110125
[0]=>
111-
string(1) "O"
126+
string(1) "K"
112127
[1]=>
128+
string(3) "E,O"
129+
[2]=>
113130
float(0.8)
114131
}
115-
["E,K"]=>
116-
array(2) {
132+
[5]=>
133+
array(3) {
117134
[0]=>
118135
string(1) "O"
119136
[1]=>
137+
string(3) "E,K"
138+
[2]=>
120139
float(1)
121140
}
122-
["E,O"]=>
123-
array(2) {
141+
[6]=>
142+
array(3) {
124143
[0]=>
125-
string(1) "K"
144+
string(3) "E,K"
126145
[1]=>
146+
string(1) "O"
147+
[2]=>
127148
float(1)
128149
}
129-
["K,O"]=>
130-
array(2) {
150+
[7]=>
151+
array(3) {
152+
[0]=>
153+
string(3) "E,O"
154+
[1]=>
155+
string(1) "K"
156+
[2]=>
157+
float(1)
158+
}
159+
[8]=>
160+
array(3) {
131161
[0]=>
162+
string(3) "K,O"
163+
[1]=>
132164
string(1) "E"
165+
[2]=>
166+
float(1)
167+
}
168+
[9]=>
169+
array(3) {
170+
[0]=>
171+
string(1) "K"
172+
[1]=>
173+
string(1) "O"
174+
[2]=>
175+
float(0.8)
176+
}
177+
[10]=>
178+
array(3) {
179+
[0]=>
180+
string(1) "O"
133181
[1]=>
182+
string(1) "K"
183+
[2]=>
134184
float(1)
135185
}
136-
}
186+
}

src/FPGrowth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ protected function generateAssociationRules($patterns, $confidence_threshold)
106106
$lower_support = $patterns[$antecedentStr];
107107
$confidence = (floatval($upper_support) / $lower_support);
108108
if ($confidence >= $confidence_threshold) {
109-
$rules[$antecedentStr] = [$consequentStr, $confidence];
109+
$rules[] = [$antecedentStr, $consequentStr, $confidence];
110110
}
111111
}
112112
}

0 commit comments

Comments
 (0)