问题
Using arules package, 'apriori' returns a 'rules' object.
How can we make a query that - What exact column does the item(s) in rules {lhs, rhs} come from ?
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,
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
Call to 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"))
Returned result:
> 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
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}
means, a value of 0
in dimension "GHI"
implies a value of 1
in "JKL"
or vice versa ?
so, Is there a way we can get the column name/id of the values of itemsets returned in rules object ?
回答1:
lhs = Left Hand Side, rhs = Right Hand Side
To be read as lhs => rhs
.
{0} => {1}
means: if the transaction contains a 0
, it also has a 1
somewhere.
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.
来源:https://stackoverflow.com/questions/16399068/how-could-we-know-the-columnname-attribute-of-items-generated-in-rules