我们怎么知道在Rule中生成的项目的ColumnName/属性 [英] How could we know the ColumnName /attribute of items generated in Rules
问题描述
使用arules包,"apriori"返回一个"rules"对象.
Using arules package, 'apriori' returns a 'rules' object.
我们如何进行查询-规则{lhs,rhs}中的项目是从哪一列来的?
How can we make a query that - What exact column does the item(s) in rules {lhs, rhs} come from ?
示例:
我在文件"input.csv"中以表格形式存储了一些数据,并希望将返回的规则项集与文件中的列标题关联/解释.我该怎么办?
Example:
I've some data in a tabular manner in file "input.csv" and want to associate/interpret the returned rule itemsets with the column headers in the file. How can I possibly do that?
任何指针都值得赞赏. 谢谢,
Any pointers are appreciated. Thanks,
可复制的示例:
input.csv
A reproducible example:
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条
Now, I want to make a distinction between the items of say, rule No.13
13 {0} => {1} 0.6153846 0.6666667 1.083333
{0} => {1}
表示维度"GHI"
中的0
值表示"JKL"
中的1
值,反之亦然?
{0} => {1}
means, a value of 0
in dimension "GHI"
implies a value of 1
in "JKL"
or vice versa ?
那么,有没有办法获取规则对象中返回的项目集值的列名/id?
so, Is there a way we can get the column name/id of the values of itemsets returned in rules object ?
推荐答案
lhs =左侧,rhs =右侧
lhs = Left Hand Side, rhs = Right Hand Side
将其读取为lhs => rhs
.
{0} => {1}
的意思是:如果事务包含0
,则它在某处也有1
.
{0} => {1}
means: if the transaction contains a 0
, it also has a 1
somewhere.
但是,由于您没有适当地预处理数据,因此结果毫无意义.在我看来,您的数据绝对不像basket
输入格式.
However, as you have not preprocessed your data appropriately, the results are meaningless. You data definitely does not look like basket
input format to me.
这篇关于我们怎么知道在Rule中生成的项目的ColumnName/属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!