UseMethod("compute")中的错误:没有适用于"计算"的方法应用于类"nn"的对象

Aks*_*kar 4 r

compute()neuralnetR中的包运行时获取错误

它是否因为数据大小而发生?我无法弄清楚确切的问题.

 df2 <- read.csv("data.csv")
 train_df <- df2[1:3200,]
 test_df <- df2[3201:4004,]

 n <- names(train_df)
 f <- as.formula(paste("tenure ~", paste(n[!n %in% "tenure"], collapse = 
                  "+")))

 model2 <- neuralnet(f,train_df, hidden=3, threshold=0.01, linear.output=T)

 summary(model2)

 #Output
                   Length  Class      Mode    
 call                      6 -none-     call    
 response               3200 -none-     numeric 
 covariate           4118400 -none-     numeric 
 model.list                2 -none-     list    
 err.fct                   1 -none-     function
 act.fct                   1 -none-     function
 linear.output             1 -none-     logical 
 data                   1288 data.frame list    
 net.result                1 -none-     list    
 weights                   1 -none-     list    
 startweights              1 -none-     list    
 generalized.weights       1 -none-     list    
  result.matrix          3871 -none-     numeric 


 results <- compute(model2, test_df)

 #Error
 Error in UseMethod("compute"): no applicable method for 'compute' applied 
 to an object of class "nn"
 Traceback:

 1. compute(model2, test_df)
Run Code Online (Sandbox Code Playgroud)

PS:数据列是数字.

Lat*_*row 7

您使用的是错误的功能.试试results <- neuralnet::compute(model2, test_df).

推理

错误说它使用了该行UseMethod("compute").这行代码不存在neuralnet::compute.因此,您似乎使用compute的是另一个包.当您加载neuralnet包后跟另一个包含compute函数的dplyr包(如包)时,可能会发生这种情况.你可以通过使用:::来避免这种情况neuralnet::compute.