2014-02-17 837 views
5

我正在應用Aprior算法,並在繪製時出現錯誤。as.double(y)中的錯誤:無法將類型'S4'強制爲類型'double'的向量

我已經安裝了包arulesarulesviz

該數據有3個屬性。兩個因子分解,一個屬性沒有分解。我分別採用了該屬性屬性和應用因子函數。代碼如下:

New_Train_Wifi = read.xlsx("D:/Train_Test.xls",1) 

str(New_Train_Wifi) 
'data.frame': 2201 obs. of 3 variables: 
$ Wifi_ID: Factor w/ 4 levels "1st","2nd","3rd",..: 3 3 3 3 3 3 3 3 3 3 ... 
$ Store : Factor w/ 5 levels "Book_Store","Clothing",..: 3 3 3 3 3 3 3 3 3 3 ... 
$ Mac_ID : num 125 125 125 125 125 125 125 125 125 125 ... 

A <- as.factor(Test_ARM_ABC$Wifi_ID) 
C <- as.factor(New_Train_Wifi$Mac_ID) 
New_Train_Wifi$MacID <- NULL 
New_Train_Wifi$MacID <- C 
New_Train_Wifi$Mac_ID <- NULL 

class(New_Train_Wifi) 
[1] "data.frame" 
[1] "Wifi_ID" "Store" "MacID" 
str(New_Train_Wifi) 
'data.frame': 2201 obs. of 3 variables: 
$ Wifi_ID: Factor w/ 4 levels "1st","2nd","3rd",..: 3 3 3 3 3 3 3 3 3 3 ... 
$ Store : Factor w/ 5 levels "Book_Store","Clothing",..: 3 3 3 3 3 3 3 3 3 3 ... 
$ MacID : Factor w/ 6 levels "100","125","254",..: 2 2 2 2 2 2 2 2 2 2 ... 

rules <- apriori(New_Train_Wifi) 
inspect(rules) 
rules <- apriori(New_Train_Wifi, parameter = list(minlen = 2, supp = 0.10, conf = 0.8), 
       appearance = list(rhs = c("Wifi_ID=1st", "Wifi_ID=2nd", "Wifi_ID=3rd", 
       "Wifi_ID=4th"), default="lhs"), control = list(verbose = F)) 

> inspect(rules.sorted) 

#/*Now wen I give below statement in r console */ 
> plot(rules) 
Error in as.double(y) : 
cannot coerce type 'S4' to vector of type 'double' 

上面的語句我試圖錯誤,但未能解決。如果有人能解決它,我會非常感激。

,我所提到的網站:http://www.rdatamining.com/examples/association-rules

+0

基本上,你的'rules'是一個沒有'plot'方法的S4對象。最好的辦法是提取任何包含您想繪製數據的插槽。像'plot(rules @ x,rules @ y)'一樣,如果'x'和'y'是slotNames。 –

+0

lhs rhs支持信心提升1 {Store = Food_Court} => {Wifi_ID = 3rd} 0.1004089 1.0000000 3.117564 2 {Store = Food Court} => {Wifi_ID = 4th} 0.2158110 0.8333333 2.072505。這些是規則。我應該給出的情節(規則@ Wifi_ID,規則@ Mac_ID) – user3292373

+0

您的評論格式不夠明白。 'slotNames(rules)'返回什麼? –

回答

3

這個問題是由庫安裝不完整引起的(我想它可能會在arulesViz包中輸入錯誤的名稱(版本))。

您可以手動下載https://cran.rstudio.com/bin/windows/contrib/3.3/seriation_1.2-1.zip,然後用 「的R-Studio菜單 - >工具 - >安裝軟件包..」 安裝上述從網站上下載的zip文件。

然後嘗試重做install.packages("arulesViz")和庫(arulesViz),它將是可行的。 完成。

15

我有這個問題太,然後實現了與安裝包後,我忘記帶

library(arulesViz) 

加載庫:

install.packages("arulesViz") 
+0

非常感謝它的工作 – user3292373

+0

我有同樣的問題與Rgraphviz,'圖書館(Rgraphviz)'之前'plot ()'工作了,tnx。 – maja

相關問題