我可以使用randomforest的預測功能嗎? PFB我創建迴歸模型的隨機森林是否可以在r中使用randomforest模型的預測函數?
Subsales<-read.csv('Sales.csv')
head(Subsales)
樣本數據集
Date SKU City Sales
<date> <chr> <chr> <dbl>
1 2014-08-11 Vaseline Petroleum Jelly Pure 60 ml Jeddah1 378
2 2014-08-18 Vaseline Petroleum Jelly Pure 60 ml Jeddah1 348
3 2014-08-25 Vaseline Petroleum Jelly Pure 60 ml Jeddah1 314
4 2014-09-01 Vaseline Petroleum Jelly Pure 60 ml Jeddah1 324
5 2014-09-08 Vaseline Petroleum Jelly Pure 60 ml Jeddah1 352
6 2014-09-15 Vaseline Petroleum Jelly Pure 60 ml Jeddah1 453
代碼
train_len=round(nrow(SubSales)*0.8)
test_len=nrow(SubSales)
######Splitting dataset into training and testing#####
#### Training Set
training<-slice(SubSales,1:train_len)
#### Testing Set
testing<-slice(SubSales,train_len+1:test_len)
training=training[c(1,4)]
testing=testing[c(1,4)]
library(randomForest)
set.seed(1234)
regressor = randomForest(formula=Sales~.,
data=training,
ntree=100)
y_pred = predict(regressor,newdata = testing)
我可以使用預測功能,而不是預測的代碼?
請閱讀有關的信息[如何提出一個很好的問題(http://stackoverflow.com/help/how-to-ask),以及如何給一個[可重現的例子](http://stackoverflow.com/questions/5963269)。這會讓其他人更容易幫助你。 – zx8754
@ zx8754我怎麼給的東西我不知道,即使作品重複的例子?我只想知道當我使用隨機森林訓練模型時,我可以使用預測功能。我所見過的每個地方都預測RF的功能只是好奇它是否可以與預測一起工作。 –
@ zx8754我已經編輯了所有細節的問題,如果它以前不清楚。乾杯。 –