<jupyter_start><jupyter_text>apriori 進行關聯分析<jupyter_code>#關聯 patern 和其 機率/條件機率
frequent_items = apriori(df,min_support = 0.6,use_colnames = True)
frequent_items
#關聯分析 #lift 表示相關程度 >1 表示正相關  =1 表示獨立
rules = association_rules(frequent_items,metric="confidence",min_threshold=0.6)
rules<jupyter_output><empty_output><jupyter_text>FP Growth algorithm 進行關聯分析<jupyter_code>#fpgrowth找出來的關聯樣式和機率
table1 = fpgrowth(df, min_support=0.6, use_colnames=True)
table1
#再找一次關聯性同apriori
rules = association_rules(table1,metric="confidence",min_threshold=0.6)
rules
#設定自訂關聯規則
rules = association_rules(table1,metric="lift",min_threshold=1)
rules<jupyter_output><empty_output><jupyter_text>練習<jupyter_code>import pandas as pd
from mlxtend.preprocessing import TransactionEncoder
from mlxtend.frequent_patterns import association_rules
from mlxtend.frequent_patterns import fpgrowth

dataset = [['a', 'c', 'd', 'f', 'g', 'i','m','p'],
 ['a', 'b', 'c', 'f', 'i', 'm','o'],
 ['b', 'f', 'h', 'j','o'],
 ['b', 'c', 'k', 's', 'p'],
 ['a', 'c', 'e', 'f', 'l', 'm','n','p']]

te = TransactionEncoder()
te_ary = te.fit(dataset).transform(dataset)
df = pd.DataFrame(te_ary, columns=te.columns_)

table = fpgrowth(df, min_support=0.5, use_colnames=True)

#rules = association_rules(table,metric="confidence",min_threshold=0.6)
rules = association_rules(table,metric="lift",min_threshold=1)
rules<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17132616487455196, 'fraction_numerical': 0.014336917562724014, 'mean_word_length': 9.575757575757576, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '631353', 'license': 'MIT', 'n_tokens_mistral': 630, 'n_tokens_neox': 624, 'n_words': 95, 'path': 'data_mining/data_mining_exercise.ipynb', 'repo_name': 'leon123858/python_exercise', 'size': '1395'}