[英]non-numeric matrix extent error when plotting in R
When running the code of this example I'm getting the following error in the last line: 运行此示例的代码时,我在最后一行收到以下错误:
Error in matrix(mean(range), ncol = ncol(x), nrow = nrow(x), dimnames = dimnames(x)) : non-numeric matrix extent
矩阵中的误差(平均值(范围),ncol = ncol(x),nrow = nrow(x),dimnames = dimnames(x)):非数字矩阵范围
However, I remember having seen other cases some months ago where the library arulesViz worked whit categorical data type. 但是,我记得几个月前曾见过其他案例,其中库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"))
Doing a traceback()
after running your code gives this: 在运行代码后执行
traceback()
做到这一点:
6: matrix(mean(range), ncol = ncol(x), nrow = nrow(x), dimnames = dimnames(x))
5: map(m, c(5, 20))
4: graph_arules(x, measure = measure, shading = shading, control,
...)
3: plot.rules(head(sort(rulesLandingManual, by = "confidence"),
n = 3), method = "graph", control = list(type = "items"))
2: plot(head(sort(rulesLandingManual, by = "confidence"), n = 3),
method = "graph", control = list(type = "items"))
1: plot(head(sort(rulesLandingManual, by = "confidence"), n = 3),
method = "graph", control = list(type = "items"))
So, basically the error comes from 6:
. 因此,基本上错误来自
6:
And the error implies that any of the argument matrix(.)
are not numeric. 该错误表明任何参数
matrix(.)
都不是数字。 To illustrate this: 为了说明这一点:
> matrix(1:4, ncol=2)
# [,1] [,2]
# [1,] 1 3
# [2,] 2 4
> matrix(1:4, ncol="x")
# Error in matrix(1:4, ncol = "x") : non-numeric matrix extent
You see the error? 您看到错误了吗? I don't think there's nothing much YOU can do here as the package extends
graph
, map
and matrix
to objects of class rules
. 我认为您无法在此做任何事情,因为该程序包将
graph
, map
和matrix
扩展到了类rules
对象。 So, this probably has a lot to do with the developer side. 因此,这可能与开发人员方面有很大关系。 If it is indeed the case, probably it is worth writing/contacting the developers.
如果确实如此,可能值得写/联系开发人员。
I had exactly the same problem with some data I was mining rules for, and after doing some tests I found out that this error comes from the use of the sort() and head() commands when there are more rules that met the condition for quality measures than required. 我在挖掘规则时会遇到一些完全相同的数据问题,经过一些测试后,我发现当有更多满足条件的规则出现时,该错误来自使用sort()和head()命令质量措施超出要求。
For instance, in your code, you ask to plot the 3 top confidence rules in rulesLandingManual, but if you inspect(rulesLandingManual) you find that there are 216 rules with confidence 1 (max confidence) , so, when you ask to subset the top n (with n less than 217), the matrix generated in this new rules object goes messy, at least for the graph method in the plot function. 例如,在您的代码中,您要求在rulesLandingManual中绘制3个最高置信度规则,但是如果您检查(rulesLandingManual),则发现有216个置信度为1(最大置信度)的规则,因此,当您要求对顶部置顶时, n(n小于217)时,在新规则对象中生成的矩阵变得混乱,至少对于plot函数中的graph方法而言。
To test what I´m explaining, in your code, change n to anything between 217 to 224 (224 is the number of rules in rulesLandingManual) and it will draw the graph, while n = 216 or less will cause the mentioned error. 为了测试我要解释的内容,在您的代码中,将n更改为217到224之间的任何值(224是rulesLandingManual中的规则数量),它将绘制图形,而n = 216或更少将引起上述错误。
I don´t know if this is intended to work this way or it is a bug, I am trying to figure it out at the moment, so an explanation will come really handy. 我不知道这是打算以这种方式工作还是它是一个错误,我现在正在设法弄清楚,因此进行解释非常方便。
range
is a function. range
是一个函数。 Did you mean mean(range(x)), ...
? 您是
mean(range(x)), ...
吗?
Mean mean. 均值。 Heh.
嘿。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.