TIEF.ai is an AI library for research and study purpose. This library is very easy to use. If you found some lack of performance or some issues, just tell me. I'll upgrade it as soon as possible.
Dillinger uses a number of open source projects to work properly:
- [Association Rule] - a rule-based machine learning method for discovering interesting relations between variables
- [KNN, etc] - Coming Soon!
TIEF AI requires Python v3.6+ to run. Make sure you already installed python. Now install
$ pip install tief
a rule-based machine learning method for discovering interesting relations between variables
Make sure you already installed python and tief library. Now import association rule module
from tief.association import apriori
from tief.association import association_rule
This is an example of data transaction. Data should contain list of list of string like example below.
data = [
["bread", "jam", "butter"],
["bread", "butter"],
["bread", "milk", "butter"],
["chocolate", "bread", "milk", "butter"],
["chocolate", "milk"]
]
Now we called apriori module to get apriori itemset with each support values.
apriori_df = apriori(data, min_support=0.3)
apriori_df
ItemSet | Count | Support | |
---|---|---|---|
0 | [bread] | 4 | 0.8 |
1 | [milk] | 3 | 0.6 |
2 | [butter] | 4 | 0.8 |
3 | [chocolate] | 2 | 0.4 |
4 | [bread, milk] | 2 | 0.4 |
5 | [bread, butter] | 4 | 0.8 |
6 | [milk, butter] | 2 | 0.4 |
7 | [milk, chocolate] | 2 | 0.4 |
8 | [bread, milk, butter] | 2 | 0.4 |
Before we called association_rule module, we must convert apriori itemset column into list
itemset = apriori_df['ItemSet'].tolist()
conf_df = association_rule(itemset, min_confidence=0.8)
conf_df
Notasi | Antecedent | Consequents | Antecedent Support | Consequents Support | Confidence | |
---|---|---|---|---|---|---|
0 | ['bread'] --> ['butter'] | [bread] | [butter] | 0.8 | 0.8 | 1.0 |
1 | ['butter'] --> ['bread'] | [butter] | [bread] | 0.8 | 0.8 | 1.0 |
2 | ['chocolate'] --> ['milk'] | [chocolate] | [milk] | 0.4 | 0.6 | 1.0 |
3 | ['bread', 'milk'] --> ['butter'] | [bread, milk] | [butter] | 0.4 | 0.8 | 1.0 |
4 | ['milk', 'butter'] --> ['bread'] | [milk, butter] | [bread] | 0.4 | 0.8 | 1.0 |
MIT
Lest Rock!