2013-02-10 86 views
1

繪製當運行本實施例的代碼我得到在最後一行下面的錯誤時:非數字矩陣程度誤差中的R

錯誤矩陣(平均(範圍),NcoI位= NcoI位(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")) 

回答

1

否則運行代碼後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 

您看到錯誤?我認爲這裏沒有什麼可以做的,因爲這個包將,mapmatrix擴展到rules類的對象。所以,這可能與開發者有很大關係。如果確實如此,可能值得編寫/聯繫開發人員。

+0

感謝您的幫助 – nopeva 2013-02-11 07:40:07

-1

range是函數。你的意思是mean(range(x)), ...

平均值。嘿。

+0

感謝您的回覆,我從我的控制檯複製並粘貼了錯誤,這正是我得到的錯誤。也許你可以嘗試代碼並查看錯誤。 – nopeva 2013-02-10 09:40:31

0

我和我正在挖掘規則的一些數據有完全相同的問題,在做了一些測試後,我發現這個錯誤來自使用sort()和head()命令,當有更多的規則滿足質量要求超出要求的條件。例如,在您的代碼中,您要求在rulesLandingManual中繪製3條最高置信度規則,但是如果您檢查(rulesLandingManual),則會發現有216條置信度爲1(最高置信度),因此,當您詢問爲了對頂部n(n小於217)進行子集化,在這個新規則對象中生成的矩陣會變得混亂,至少對於plot函數中的圖形方法來說。

爲了測試我的解釋,在代碼中,將n更改爲217到224之間的任何值(224是rulesLandingManual中的規則數),它將繪製圖形,而n = 216或更少將導致提到的錯誤。

我不知道這是打算以這種方式工作,還是一個錯誤,我現在想弄清楚,所以一個解釋會非常方便。