使用 arules 包,'apriori' 返回一个 'rules' 对象。
我们如何进行查询 - 规则 {lhs, rhs} 中的项目来自哪个确切列?
示例:
我在文件“input.csv”中有一些表格形式的数据,并希望将返回的规则项集与文件中的列标题关联/解释。我怎么可能做到这一点?
任何指针表示赞赏。谢谢,
一个可重现的例子:
input.csv
ABC,DEF,GHI,JKL,MNO
11,56789,1,0,10
12,57685,0,0,10
11,56789,0,1,11
10,57689,1,0,12
11,56789,0,1,12
10,57685,1,0,12
10,57689,1,0,10
11,56789,0,1,12
11,56789,0,0,10
11,56789,0,0,10
11,56789,0,1,10
11,56789,0,0,10
致电 Apriori:
transactions <- read.transactions("input.csv", format="basket", sep = ',', cols = NULL, rm.duplicates = TRUE)
Rules <- apriori(transactions, parameter = list(supp = 0.45, conf = 0.50, target = "rules"))
返回结果:
> inspect(Rules)
lhs rhs support confidence lift
1 {} => {11} 0.6153846 0.6153846 1.000000
2 {} => {56789} 0.6153846 0.6153846 1.000000
3 {} => {1} 0.6153846 0.6153846 1.000000
4 {} => {10} 0.6923077 0.6923077 1.000000
5 {} => {0} 0.9230769 0.9230769 1.000000
6 {11} => {56789} 0.6153846 1.0000000 1.625000
7 {56789} => {11} 0.6153846 1.0000000 1.625000
8 {11} => {0} 0.6153846 1.0000000 1.083333
9 {0} => {11} 0.6153846 0.6666667 1.083333
10 {56789} => {0} 0.6153846 1.0000000 1.083333
11 {0} => {56789} 0.6153846 0.6666667 1.083333
12 {1} => {0} 0.6153846 1.0000000 1.083333
13 {0} => {1} 0.6153846 0.6666667 1.083333
14 {10} => {0} 0.6923077 1.0000000 1.083333
15 {0} => {10} 0.6923077 0.7500000 1.083333
16 {11, 56789} => {0} 0.6153846 1.0000000 1.083333
17 {0, 11} => {56789} 0.6153846 1.0000000 1.625000
18 {0, 56789} => {11} 0.6153846 1.0000000 1.625000
现在,我想对规则 13 的项目进行区分
13 {0} => {1} 0.6153846 0.6666667 1.083333
{0} => {1}
意味着,0
in 维度"GHI"
的值意味着 in 的值,1
反之亦然"JKL"
?
那么,有没有一种方法可以获取规则对象中返回的项集值的列名/ID?