运行此示例的代码时,我在最后一行收到以下错误:
矩阵中的错误(平均值(范围),ncol = ncol(x),nrow = nrow(x),dimnames = dimnames(x)):非数字矩阵范围
但是,我记得几个月前看到过其他案例,其中库 arulesViz 使用分类数据类型。
landing.data=read.csv2("http://archive.ics.uci.edu/ml/machine-learning-databases/shuttle-landing-control/shuttle-landing-control.data",
sep=",", header=F, dec=".")
landing.data=as.data.frame(sapply(landing.data,gsub,pattern="\\*",replacement=10))
library(arules)
landing.system <- as(landing.data, "transactions")
rules <- apriori(landing.system, parameter=list(support=0.01, confidence=0.6))
rulesLandingManual <- subset(rules, subset=rhs %in% "V1=1" & lift>1.2)
library(arulesViz)
plot(head(sort(rulesLandingManual, by="confidence"), n=3),
method="graph",control=list(type="items"))