From 8983ef88a5ad1085921c93163fc5e3889227082d Mon Sep 17 00:00:00 2001 From: zStupan Date: Sat, 17 Dec 2022 16:10:17 +0100 Subject: [PATCH] added rule example --- examples/make_rule.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 examples/make_rule.py diff --git a/examples/make_rule.py b/examples/make_rule.py new file mode 100644 index 0000000..760d53d --- /dev/null +++ b/examples/make_rule.py @@ -0,0 +1,16 @@ +from niaarm import Dataset, Feature, Rule + +# load the Abalone dataset +data = Dataset("datasets/Abalone.csv") + +# make the rule Shell weight([0.15, 0.35]) => Rings([5, 10]) +antecedent = [Feature('Shell weight', dtype='float', min_val=0.15, max_val=0.35)] +consequent = [Feature('Rings', dtype='int', min_val=5, max_val=10)] + +# pass the transaction data to the Rule constructor to enable the calculation of metrics +rule = Rule(antecedent, consequent, transactions=data.transactions) + +print(rule) +print(f'Support: {rule.support}') +print(f'Confidence: {rule.confidence}') +print(f'Lift: {rule.lift}')