当前位置:网站首页>Data mining -- code implementation of association analysis example (Part 2)
Data mining -- code implementation of association analysis example (Part 2)
2022-07-29 03:53:00 【Bubble Yi】
1. Guide pack
from mlxtend.preprocessing import TransactionEncoder
from mlxtend.frequent_patterns import apriori
from mlxtend.frequent_patterns import association_rules
import pandas as pd
2. Read the file
my_data=pd.read_excel("D:/ Great / data mining /basket.xlsx")
df_data=my_data.iloc[:,7:].copy()
df_data.head()
3. data display
my_data.describe()
The result is shown in Fig. :
4. Data processing :
dict_data={'F':False,'T':True}
df_data['fruitveg']=df_data['fruitveg'].map(dict_data)
df_data['freshmeat']=df_data['freshmeat'].map(dict_data)
df_data['dairy']=df_data['dairy'].map(dict_data)
df_data['cannedveg']=df_data['cannedveg'].map(dict_data)
df_data['cannedmeat']=df_data['cannedmeat'].map(dict_data)
df_data['frozenmeal']=df_data['frozenmeal'].map(dict_data)
df_data['beer']=df_data['beer'].map(dict_data)
df_data['wine']=df_data['wine'].map(dict_data)
df_data['softdrink']=df_data['softdrink'].map(dict_data)
df_data['fish']=df_data['fish'].map(dict_data)
df_data['confectionery']=df_data['confectionery'].map(dict_data)
give the result as follows :
5. Set support to find frequent itemsets
frequent_itemsets = apriori(df_data,min_support=0.1,use_colnames= True)
frequent_itemsets
give the result as follows :
6.
# Find association rules , Set the minimum confidence to 0.15
rules = association_rules(frequent_itemsets,metric = 'confidence',min_threshold = 0.15)
# Set the minimum lift
rules = rules.drop(rules[rules.lift <1.0].index)
# Set the title index and print the results
rules.rename(columns = {'antecedents':'from','consequents':'to','support':'sup','confidence':'conf'},inplace = True)
rules = rules[['from','to','sup','conf','lift']]
rules
give the result as follows :
边栏推荐
- Typescript from entry to mastery (XXI) generic types in classes
- The digitalization of the consumer industry is upgraded to "rigid demand", and weiit's new retail SaaS empowers enterprises!
- 5年多工作经验,工资给15k,要是你,你会接受吗?
- Big manufacturers finally can't stand "adding one second", and companies such as Microsoft, Google meta propose to abolish leap seconds
- Typescript from getting started to mastering (XXIII) namespace namespace (Part 2)
- Several cases of word wrapping in div
- 实例搭建Flask服务(简易版)
- RHCE's at, crontab's basic operations, the Chrony service, symmetric encryption and asymmetric encryption
- Connect with third-party QQ login
- (newcoder 15079) irrelevant (inclusion exclusion principle)
猜你喜欢
UCOS任务切换过程
消费行业数字化升级成 “刚需”,weiit 新零售 SaaS 为企业赋能!
Solve the delay in opening the console of Google browser
面试必备!TCP协议经典十五连问!
(2022 Hangdian multi school III) 1002 boss rush (pressure dp+ dichotomy)
tron OUT_ OF_ ENERGY
(2022杭电多校三)1011-Link is as bear(思维+线性基)
The latest second edition of comic novels, listening to books, three in one, complete source code / integrated visa free interface / building tutorials / with acquisition interface
Instance setup flask service (simple version)
从2019 年开始,你一定停止使用了这个营销策略…
随机推荐
The list is not updated in real time when JS V-for data changes
无法一次粘贴多张图片
初识C语言(3)
Shopify卖家:EDM营销就要搭配SaleSmartly,轻松搞定转化率
"The programming is not standardized, and my colleagues are in tears!"
Connect with third-party QQ login
What you see and think in Microsoft
Sunflower senior product director technology sharing: "how to apply national remote control" in AD domain environment
Several cases of word wrapping in div
消费行业数字化升级成 “刚需”,weiit 新零售 SaaS 为企业赋能!
How do programmers use code to completely end those things in the system?
How fast does it take to implement a super simple language
[introduction to C language] zzulioj 1031-1035
[redis series] string data structure
第一个ALV程序2
Simple use of eventbus
安装抓包证书
In depth C language (2) -- definition and use of structure
Simple cases of inner connection and left connection
LDP --- 标签分发协议