我正在應用Aprior算法,並在繪製時出現錯誤。as.double(y)中的錯誤:無法將類型'S4'強制爲類型'double'的向量
我已經安裝了包arules
和arulesviz
。
該數據有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
基本上,你的'rules'是一個沒有'plot'方法的S4對象。最好的辦法是提取任何包含您想繪製數據的插槽。像'plot(rules @ x,rules @ y)'一樣,如果'x'和'y'是slotNames。 –
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
您的評論格式不夠明白。 'slotNames(rules)'返回什麼? –