我有一个excel文件规则:一个用于前因的列,另一个用于Consequents,另一个用于支持等等
我试图创建一个"规则"使用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,我需要回到稀疏矩阵,但我认为这不会起作用,是否有某种方法可以导入"导入" 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
答案 0 :(得分:1)
一种方法是为规则创建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)
希望这有帮助!