Professional Documents
Culture Documents
DA 11
DA 11
CODE:
Genera ng Associa on Rules: Once frequent item sets have been iden fied,
the next step is to generate associa on rules based on these item sets. This is
done using the associa on_rules func on from the same module. We can
specify metrics such as confidence or li to evaluate the strength of the
associa on rules. In your code, using the li metric and specifying a
min_threshold of 1.
rules = associa on_rules(frequent_itemsets, metric="li ", min_threshold=1)
Displaying the Results: Finally, you can examine the generated associa on
rules. The head() func on is used to display the first few rows of the resul ng
DataFrame containing the associa on rules.
rules.head()
In this example:
import pandas as pd
# Sample transac onal data (replace this with your actual dataset)
transac ons = [
basket_sets = pd.get_dummies(df)
# Find frequent item sets with minimum support of 0.4 (adjust as needed)
print(rules)