【发布时间】:2020-05-11 02:14:32
【问题描述】:
我对 R 很陌生,正在尝试为一组事务运行 apriori 函数。我在检查遇到问题的规则时发现,LHS 是空的。我究竟做错了什么?
下面是我使用的代码。我还附上了两张我使用过的不同文件格式的图片。数据格式1、数据格式2、数据格式3。下面的代码使用的是格式3。
> dianacsv <- read.csv("diana.csv")
> dianatrans <- read.transactions(file="diana.csv", format = c("basket"), header = TRUE, sep = ",")
> summary(dianatrans)
transactions as itemMatrix in sparse format with
114091 rows (elements/itemsets/transactions) and
114149 columns (items) and a density of 3.32023e-05
most frequent items:
CS12 PS12 BU12 GB12 CC12 (Other)
23819 18268 16166 15544 14452 344157
element (itemset/transaction) length distribution:
sizes
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
65024 26446 13237 5185 2243 873 435 250 133 83 65 47 26 8 17
18 19 20 21 22 23 24
3 3 6 3 1 2 1
Min. 1st Qu. Median Mean 3rd Qu. Max.
3.00 3.00 3.00 3.79 4.00 24.00
includes extended item information - examples:
labels
1 1
2 10
3 100
> dianarules <- apriori(dianatrans, parameter = list(supp = 0.01, conf = 0.01, target = "rules"))
Apriori
Parameter specification:
confidence minval smax arem aval originalSupport maxtime support minlen maxlen target
0.01 0.1 1 none FALSE TRUE 5 0.01 1 10 rules
ext
FALSE
Algorithmic control:
filter tree heap memopt load sort verbose
0.1 TRUE TRUE FALSE TRUE 2 TRUE
Absolute minimum support count: 1140
set item appearances ...[0 item(s)] done [0.00s].
set transactions ...[114149 item(s), 114091 transaction(s)] done [0.23s].
sorting and recoding items ... [38 item(s)] done [0.01s].
creating transaction tree ... done [0.04s].
checking subsets of size 1 2 3 done [0.00s].
writing ... [237 rule(s)] done [0.00s].
creating S4 object ... done [0.02s].
> inspect(dianarules[1:5])
lhs rhs support confidence lift count
[1] {} => {BBK16} 0.01076334 0.01076334 1 1228
[2] {} => {CS4} 0.01036892 0.01036892 1 1183
[3] {} => {BU4} 0.01196413 0.01196413 1 1365
[4] {} => {CHK16} 0.01362071 0.01362071 1 1554
[5] {} => {PJK16} 0.01575059 0.01575059 1 1797
数据格式1
数据格式2
数据格式3
【问题讨论】:
-
嗯...您的规则子集有一个空的 LHS。我猜如果你检查更多规则,你会用非空 LHS 来处理一些规则。
标签: r associations data-mining apriori market-basket-analysis