[英]non-numeric matrix extent error when plotting in R
運行此示例的代碼時,我在最后一行收到以下錯誤:
矩陣中的誤差(平均值(范圍),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"))
在運行代碼后執行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
您看到錯誤了嗎? 我認為您無法在此做任何事情,因為該程序包將graph
, map
和matrix
擴展到了類rules
對象。 因此,這可能與開發人員方面有很大關系。 如果確實如此,可能值得寫/聯系開發人員。
我在挖掘規則時會遇到一些完全相同的數據問題,經過一些測試后,我發現當有更多滿足條件的規則出現時,該錯誤來自使用sort()和head()命令質量措施超出要求。
例如,在您的代碼中,您要求在rulesLandingManual中繪制3個最高置信度規則,但是如果您檢查(rulesLandingManual),則發現有216個置信度為1(最大置信度)的規則,因此,當您要求對頂部置頂時, n(n小於217)時,在新規則對象中生成的矩陣變得混亂,至少對於plot函數中的graph方法而言。
為了測試我要解釋的內容,在您的代碼中,將n更改為217到224之間的任何值(224是rulesLandingManual中的規則數量),它將繪制圖形,而n = 216或更少將引起上述錯誤。
我不知道這是打算以這種方式工作還是它是一個錯誤,我現在正在設法弄清楚,因此進行解釋非常方便。
range
是一個函數。 您是mean(range(x)), ...
嗎?
均值。 嘿。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.