In [1]:
Copied!
from krmining.association_rules import apriori
from krmining.datasets import make_fruit_sold_dummy_association_rules
from krmining.association_rules import apriori
from krmining.datasets import make_fruit_sold_dummy_association_rules
Using dummy data¶
In [2]:
Copied!
df = make_fruit_sold_dummy_association_rules()
df.head()
df = make_fruit_sold_dummy_association_rules()
df.head()
Out[2]:
| Description | apple | banana | mango | strawberry |
|---|---|---|---|---|
| InvoiceNo | ||||
| 1 | 1 | 1 | 1 | 0 |
| 2 | 1 | 1 | 1 | 1 |
| 3 | 0 | 1 | 1 | 1 |
In [3]:
Copied!
df.info()
df.info()
<class 'pandas.core.frame.DataFrame'> Int64Index: 3 entries, 1 to 3 Data columns (total 4 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 apple 3 non-null int64 1 banana 3 non-null int64 2 mango 3 non-null int64 3 strawberry 3 non-null int64 dtypes: int64(4) memory usage: 120.0 bytes
In [4]:
Copied!
apriori(df)
apriori(df)
C:\Users\Bina Umat\anaconda3\lib\site-packages\krmining\association_rules\_apriori.py:96: UserWarning: The model still in maintaining in slow or extended memory warnings.warn(
Out[4]:
array([[('apple',), 0.6666666666666666],
[('banana',), 1.0],
[('mango',), 1.0],
[('strawberry',), 0.6666666666666666],
[('apple', 'banana'), 0.6666666666666666],
[('apple', 'mango'), 0.6666666666666666],
[('banana', 'mango'), 1.0],
[('banana', 'strawberry'), 0.6666666666666666],
[('mango', 'strawberry'), 0.6666666666666666],
[('apple', 'banana', 'mango'), 0.6666666666666666],
[('banana', 'mango', 'strawberry'), 0.6666666666666666]],
dtype=object)
In [5]:
Copied!
apriori(df, return_df=True)
apriori(df, return_df=True)
Out[5]:
| Combinations | Supports | |
|---|---|---|
| 0 | (apple,) | 0.666667 |
| 1 | (banana,) | 1.0 |
| 2 | (mango,) | 1.0 |
| 3 | (strawberry,) | 0.666667 |
| 4 | (apple, banana) | 0.666667 |
| 5 | (apple, mango) | 0.666667 |
| 6 | (banana, mango) | 1.0 |
| 7 | (banana, strawberry) | 0.666667 |
| 8 | (mango, strawberry) | 0.666667 |
| 9 | (apple, banana, mango) | 0.666667 |
| 10 | (banana, mango, strawberry) | 0.666667 |