【发布时间】:2021-07-09 19:20:19
【问题描述】:
我对 R 很陌生,我想制作一个随机森林。但是我一直收到同样的错误-
Error in model.frame.default, lengths of variables differ.
我知道这个问题已经通过使用as. 公式从字符串构造公式在另一个主题中得到解决,但我真的不知道该怎么做。你能帮我吗?谢谢。
#A vector that has random sample of training values (70% & 30% samples)
index = sample(2,nrow(df), replace = TRUE, prob=c(0.7,0.3))
#Training Date
training = df[index==1,]
#Testing data
testing = df[index==2,]
#Random forest model
RFM = randomForest(df$Rating~., df$Customer_type, data = training)
【问题讨论】:
-
你应该从数据框中调用它,即
randomForest(Rating~., Customer_type, data = training) -
是的,非常感谢!
标签: r random-forest