输入外部规则到arulesViz

Input external rules to arulesViz

我有一个 excel 规则文件:一列用于前提,另一列用于结果,另一列用于支持等

我正在尝试创建一个 "rules" 对象以使用 arulesViz 绘制它们。

http://www.inside-r.org/packages/cran/arules/docs/rhs

new("rules", ...)

我正在尝试创建插槽

lhs:Object of class itemMatrix; the left-hand-sides of the rules (antecedents)
rhs:Object of class itemMatrix; the right-hand-sides of the rules (consequents)
quality:a data.frame

要创建 itemMatrix,我需要回到稀疏矩阵,但我认为这行不通,有什么方法可以 "import" 规则到 arulesViz 吗?

Excel 文件:

Antec   Conseq      Supp      Conf
MMMMAAA MMAAAA  0.061945    0.5
MMM,MA  MMAAAA  0.071944    0.6
MMMMAAA MMAAA   0.053948    0.5
MMM,MA  MMAAA   0.054948    0.7
AAAAAA  AAAA    0.090909    0.5

一种方法是为规则创建一个 PMML 文件并使用 read.PMML。从头开始创建规则对象有点棘手。这是一个例子:

library("arules")
l <- list(c("MMMMAAA"), c("MMM", "MA"), "MMMMAAA", c("MMM","MA"), "AAAAA")
r <- list("MMAAAA", "MMAAAA", "MMAAA", "MMAAA", "AAAA")
q <- data.frame(
     support = c(0.061945, 0.071944, 0.053948, 0.054948,0.090909), 
     confidence = c(.5, .6, .5, .7, .5),
     lift = c(1,1,1,1,1)
)
### Note that I also added lift since arulesViz uses 
### lift in some visualizations.


### find unique item labels
items <- unique(c(unlist(l), unlist(r)))

### encode data as a rules object
r <- new("rules", lhs = encode(l, items), 
   rhs = encode(r, items), quality = q)

inspect(r)

### use a visualization as a scatter plot.
library("arulesViz")
plot(r)

希望对您有所帮助!