Размер видео: 1280 X 720853 X 480640 X 360
Показать панель управления
Автовоспроизведение
Автоповтор
import pandas as pdfrom mlxtend.preprocessing import TransactionEncoderbasket = [['Milk', 'Onion', 'Nutmeg', 'Kidney Beans', 'Eggs', 'Yogurt'], ['Dill', 'Onion', 'Nutmeg', 'Kidney Beans', 'Eggs', 'Yogurt'], ['Milk', 'Apple', 'Kidney Beans', 'Eggs'], ['Milk', 'Unicorn', 'Corn', 'Kidney Beans', 'Yogurt'], ['Corn', 'Onion', 'Onion', 'Kidney Beans', 'Ice cream', 'Eggs']]te = TransactionEncoder()te_ary = te.fit(basket).transform(basket)df = pd.DataFrame(te_ary, columns=te.columns_)'fp-growth'from mlxtend.frequent_patterns import fpgrowth,association_rulesres = fpgrowth(df,min_support=0.05, use_colnames=True)out = association_rules(res, metric="confidence", min_threshold=0.7)out["antecedents"] = out["antecedents"].apply(lambda x: list(x)[0]).astype("unicode")out["consequents"] = out["consequents"].apply(lambda x: list(x)[0]).astype("unicode")out.iloc[:,:6]
老師真的好強,大大的幫助到我QQQ
很開心對您有幫助,如果有說錯也歡迎隨時指正我~讓我可以一起進步🥳
import pandas as pd
from mlxtend.preprocessing import TransactionEncoder
basket = [['Milk', 'Onion', 'Nutmeg', 'Kidney Beans', 'Eggs', 'Yogurt'],
['Dill', 'Onion', 'Nutmeg', 'Kidney Beans', 'Eggs', 'Yogurt'],
['Milk', 'Apple', 'Kidney Beans', 'Eggs'],
['Milk', 'Unicorn', 'Corn', 'Kidney Beans', 'Yogurt'],
['Corn', 'Onion', 'Onion', 'Kidney Beans', 'Ice cream', 'Eggs']]
te = TransactionEncoder()
te_ary = te.fit(basket).transform(basket)
df = pd.DataFrame(te_ary, columns=te.columns_)
'fp-growth'
from mlxtend.frequent_patterns import fpgrowth,association_rules
res = fpgrowth(df,min_support=0.05, use_colnames=True)
out = association_rules(res, metric="confidence", min_threshold=0.7)
out["antecedents"] = out["antecedents"].apply(lambda x: list(x)[0]).astype("unicode")
out["consequents"] = out["consequents"].apply(lambda x: list(x)[0]).astype("unicode")
out.iloc[:,:6]
老師真的好強,大大的幫助到我QQQ
很開心對您有幫助,如果有說錯也歡迎隨時指正我~讓我可以一起進步🥳