【问题标题】:Error in as.double(y) : cannot coerce type 'S4' to vector of type 'double'as.double(y) 中的错误:无法将类型“S4”强制转换为“double”类型的向量
【发布时间】:2022-02-19 00:09:47
【问题描述】:

我正在应用 Aprior 算法,并且在绘图时出现错误。

我已经安装了包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

【问题讨论】:

  • 基本上,您的rules 是一个没有plot 方法的S4 对象。最好的办法是提取包含您希望绘制的数据的任何插槽。就像 plot(rules@x,rules@y) 如果 xy 是 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)
  • 您的评论格式不够,无法理解。 slotNames(rules) 返回什么?
  • 当我给 slotNames(rules) [1] "lhs" "rhs" "quality" "info" 。这些是我得到的四个参数。现在,有什么方法可以绘制结果。
  • 我认为这将是:您忘记输入library(arulesViz),因此rules 的绘图方法未激活。

标签: r


【解决方案1】:

我也有这个问题,然后意识到我忘记加载库了

library(arulesViz)

安装包后:

install.packages("arulesViz")

【讨论】:

  • plot() 工作之前,我在 Rgraphviz 上遇到了同样的问题,library(Rgraphviz),tnx。
【解决方案2】:

这个问题是由于库安装不完整引起的(我猜它可能在 arulesViz 的包中放了错误的名称(版本))。

您可以手动下载https://cran.rstudio.com/bin/windows/contrib/3.3/seriation_1.2-1.zip,然后使用“r-studio menu -> tools -> install packages..”来安装上面从网站下载的 zip 文件。

然后尝试重做install.packages("arulesViz")和library(arulesViz),就可以了。 完成。

【讨论】:

    【解决方案3】:

    我遇到了同样的错误,在我的情况下是因为我忘记运行 library(raster)

    【讨论】:

      猜你喜欢
      • 2016-11-21
      • 1970-01-01
      • 1970-01-01
      • 2017-02-16
      • 2021-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多