Association Rule in R (card.csv) part 2

Customer segmentation

Output Variable Definition -> 输出变量定义

New field: Level (output variable):

VIP: Top 20% of customers with the highest value.

NOT VIP: 80% of customers  who remained with lowest value.

1. VIP customer

Step 1: Generate association rule model -> 建立关联规则模型

tran.VIP<-rc[rc$Level=='VIP',]
# Choose the VIP target
dim(tran.VIP)
tran.VIP0<-tran.VIP[,-1:-9]
#  Delete the demographic data
str(tran.VIP0)
tran.VIP1<-as.matrix(tran.VIP0,"transactions")
#  Transform  the data to transaction data
rules.VIP <- apriori(tran.VIP1, parameter=list(support=0.1, confidence=0.7))
# Generate association rule model

 Step 2: Analyze association rule model -> 分析关联规则模型

# 数据摘要、分别按照支持度和信赖度进行排序1:5
summary(rules.VIP)
inspect(sort(rules.VIP,by="support")[1:5])
inspect(sort(rules.VIP,by="confidence")[1:5])

 Step 3: Visualize the result -> 可视化结果

# 绘制散点图、分组矩阵、连接网
plot(rules) plot(rules.VIP, method
="grouped") plot(rules.VIP, method="graph", interactive=TRUE, control=list(type = "items"))

2. NOTVIP customer

Step 1: Generate association rule model -> 建立关联规则模型

tran.NOTVIP<-rc[rc$Level=='VIP',]
# Choose the VIP target
dim(tran.VIP)
tran.NOTVIP0<-tran.VIP[,-1:-9]
#  Delete the demographic data
str(tran.NOTVIP0)
tran.NOTVIP1<-as.matrix(tran.NOTVIP0,"transactions")
#  Transform  the data to transaction data
rules.NOTVIP <- apriori(tran.NOTVIP1, parameter=list(support=0.1, confidence=0.7))
# Generate association rule model

Step 2: Analyze association rule model -> 分析关联规则模型

# 数据摘要、分别按照支持度和信赖度进行排序1:5
summary(rules.NOTVIP)
inspect(sort(rules.NOTVIP,by="support")[1:5])
inspect(sort(rules.NOTVIP,by="confidence")[1:5])

 Step 3: Visualize the result -> 可视化结果

# 绘制散点图、分组矩阵、连接网
plot(rules)
plot(rules.VIP, method="grouped")
plot(rules.VIP, method="graph", interactive=TRUE, control=list(type = "items"))

 

posted @ 2013-06-10 01:43  jinyulogin  阅读(800)  评论(0)    收藏  举报