2017-04-04 60 views
-1

我可以使用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) 

我可以使用預測功能,而不是預測的代碼?

+1

請閱讀有關的信息[如何提出一個很好的問題(http://stackoverflow.com/help/how-to-ask),以及如何給一個[可重現的例子](http://stackoverflow.com/questions/5963269)。這會讓其他人更容易幫助你。 – zx8754

+0

@ zx8754我怎麼給的東西我不知道,即使作品重複的例子?我只想知道當我使用隨機森林訓練模型時,我可以使用預測功能。我所見過的每個地方都預測RF的功能只是好奇它是否可以與預測一起工作。 –

+0

@ zx8754我已經編輯了所有細節的問題,如果它以前不清楚。乾杯。 –

回答

-1

既然你問一個非常寬泛的問題,我會給你一個廣闊的答案。你必須從訓練隨機森林模型開始。隨後選擇與訓練的模型預測功能是預測

+0

嗨,我很抱歉,如果之前還不清楚,我已經訓練了一個隨機森林模型。我有一個訓練和測試集。到處都有使用射頻預測功能的地方。我只是好奇,如果我可以使用我的隨機森林模型預測功能。 –

+0

感謝您的澄清。答案是否定的 - 在「預測」功能是具體到預測軟件包,並不會從隨機森林包或隨機森林模型從插入符包隨機森林型號。 請注意,ARIMA模型是專門設計能夠處理時間序列數據。隨機森林並非如此。因此,如果沒有關於您的使用場景的任何其他信息,這些算法的組合似乎很奇怪。 – WHoekstra

+0

謝謝你解釋它。 :) –

相關問題