Returns a dictionary of (set(features), frequency)-items. The given support (0.0-1.0) is the relative amount of documents in which a combination of feature must appear.
(self, sets, support=0.5)
| 1239 | return dict((s, f) for s, f in Lk.items() if f >= support) |
| 1240 | |
| 1241 | def __call__(self, sets, support=0.5): |
| 1242 | """ Returns a dictionary of (set(features), frequency)-items. |
| 1243 | The given support (0.0-1.0) is the relative amount of documents |
| 1244 | in which a combination of feature must appear. |
| 1245 | """ |
| 1246 | C1 = self.C1(sets) |
| 1247 | L1 = self.Lk(sets, C1, support) |
| 1248 | self._candidates = [L1.keys()] |
| 1249 | self._support = L1 |
| 1250 | while True: |
| 1251 | # Terminate when no further extensions are found. |
| 1252 | if len(self._candidates[-1]) == 0: |
| 1253 | break |
| 1254 | # Extend frequent subsets one item at a time. |
| 1255 | Ck = self.Ck(self._candidates[-1]) |
| 1256 | Lk = self.Lk(sets, Ck, support) |
| 1257 | self._candidates.append(Lk.keys()) |
| 1258 | self._support.update(Lk) |
| 1259 | return self._support |
| 1260 | |
| 1261 | apriori = Apriori() |
| 1262 |