[英]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.