繁体   English   中英

可变长度与随机森林不同

[英]Variable lengths differ with random forest

我对 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)

那么您的错误是,您的自变量是来自df dataframe 的Rating ,但您选择了data = training 这意味着您的随机森林应该从 2 个不同的数据帧中获取数据,这是不可能的。 我猜randomForest(Rating ~ Customer_type, data = training)会起作用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM