Association Rule in R (card.csv) part 1
Credit Card Purchases
Data Set -> 数据集
- Data Download Link:card.csv
- The number of records: 9999
- twenty-eight 28 Variables can be used for decision tree generation
- 28 Input Variable: Airlines ~ Travel

Step 1: Read Data -> 读取数据
# 读取数据并删除1-9列的数据集
file.choose()
rc<-read.csv("card.csv",header=T)
set.rc<-rc[,-1:-9]
str(set.rc)
Step 2: Transform data -> 转换数据
# 把原有数据转换为交易数据,从数据框(data.frame)形式转换为矩阵(matrix)形式
library(arules)
tran<-as.matrix(set.rc,"transactions")
str(tran)

Step 3: Generate association rule model -> 建立关联规则模型
rules <- apriori(tran,parameter=list(support=0.1, confidence=0.8))
# There is no rules can be found then define the support to 0.1
rules <- apriori(tran,parameter=list(support=0.01, confidence=0.8))
# There are 42 rules can be found then define the support to 0.01

Step 4: Analyze association rule model -> 分析关联规则模型
# 数据摘要、分别按照支持度和信赖度进行排序1:5
summary(rules)
inspect(sort(rules,by="support")[1:5])
inspect(sort(rules,by="confidence")[1:5])


Step 5: Visualize the result -> 可视化结果
# 绘制散点图、分组矩阵、连接网
library(arulesViz)
plot(rules)
plot(rules, method="grouped")
plot(rules, method="graph", interactive=TRUE, control=list(type = "items"))



浙公网安备 33010602011771号