首页 文章

在R中绘图时出现非数字矩阵范围错误

提问于
浏览
1

运行此示例的代码时,我在最后一行收到以下错误:

矩阵误差(均值(范围),ncol = ncol(x),nrow = nrow(x),dimnames = dimnames(x)):非数字矩阵范围

但是,我记得几个月前看过其他案例,其中库arulesViz使用了whit分类数据类型 .

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"))

3 回答

  • 0

    在运行代码后执行 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"))
    

    所以,基本上错误来自 6: . 并且错误意味着任何参数 matrix(.) 都不是数字 . 为了说明这一点:

    > 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
    

    你看错了吗?因为包裹将 graphmapmatrix 扩展到类 rules 的对象,所以我不会在这里做任何事情 . 所以,这可能与开发者方面有很大关系 . 如果确实如此,可能值得写/联系开发人员 .

  • -1

    我对挖掘规则的一些数据有完全相同的问题,并且在做了一些测试后我发现这个错误来自使用sort()和head()命令,当有更多规则满足条件时质量措施超过要求 .

    例如,在您的代码中,您要求在rulesLandingManual中绘制3个最高置信度规则,但是如果您检查(rulesLandingManual),您会发现216个规则具有置信度1(最大置信度),因此,当您要求对顶部进行子集化时n(n小于217),在这个新规则对象中生成的矩阵变得混乱,至少对于绘图函数中的图形方法而言 .

    为了测试我解释的内容,在你的代码中,将n更改为217到224之间的任何值(224是rulesLandingManual中的规则数),它将绘制图形,而n = 216或更小将导致上述错误 .

    我不知道这是打算以这种方式工作还是它是一个bug,我现在试图解决这个问题,所以解释会变得非常方便 .

  • 2

    range 是一个功能 . 你的意思是 mean(range(x)), ...

    平均值 . 嘿 .

相关问题