title: Time Series Forecasting using Random Forest in R
body: <p>I'm trying to do a time series analysis using randomforest. PFB my code </p>
  
  <pre><code>Subsales&lt;-read.csv('Sales.csv')
  head(Subsales)
  </code></pre>
  
  <p>Sample Data:   </p>
  
  <pre><code>Date               SKU                            City   Sales
        &lt;date&gt;                               &lt;chr&gt;   &lt;chr&gt; &lt;dbl&gt;
  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
  
  
  ####Length of training &amp; testing set Splitting it 80-20####
  
  train_len=round(nrow(SubSales)*0.8) 
  test_len=nrow(SubSales)
  
  
  
  ######Splitting dataset into training and testing#####
  
  #### Training Set
  training&lt;-slice(SubSales,1:train_len) 
  #### Testing Set
  testing&lt;-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)
  </code></pre>
  
  <p>I'm getting a stationary result when I use the predict function on test data set.All predicted values are 369, I've tried for another data set I got the same result. Can anyone tell me what am I doing wrong here?</p>