title: How do you forecast future values using support vector regression in R
body: <p>I am trying to forecast for future values of a periodic position dependent on time (x ~ time), univariate forecasting using support vector regression. The model fits well on train data but then trails into a straight line when evaluated on test data. In the code below, I used 50 observations for train (the first half of the red periodic curve, where SVR fits perfectly) and 50 observations for test (the second half of the red curve, where SVR fails to predict).</p>
  <pre><code>library(lubridate)
  library(purrr)
  library(ggplot2)
  library(Metrics)
  library(caret)
  library(dplyr)
  library(e1071)
  
  # train_data has 50 observations
  # eval_data has 100 observations (the first half is train_data)
   
  func &lt;- x ~ abs_time # position x dependent on time
  svr_model &lt;- svm(func, train_data, type = &quot;eps-regression&quot;, 
                   kernel=&quot;radial&quot;, gamma=13, cost=10, epsilon = 0.01)
  
  k_hat &lt;- predict(svr_model, eval_data)
    
  plot(x = eval_data$abs_time, y = eval_data$x, type = &quot;l&quot;, col=&quot;red&quot;) # true position
  points(x = eval_data$abs_time, y = k_hat, col = &quot;blue&quot;) # SVR predicted position
  </code></pre>
  <p><a href="https://i.stack.imgur.com/VzsCa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VzsCa.png" alt="enter image description here" /></a></p>
  <p>I looked at this post:
  <a href="https://stackoverflow.com/questions/49081801/time-series-forecasting-using-support-vector-machine-svm-in-r">Time Series Forecasting using Support Vector Machine (SVM) in R</a> and tried out the suggestion of combining both train and test data together and evaluating the model on it.</p>
  <p>Would like to know what is going on here. My hunch is that the choice of kernel is unable to generalize to periodic patterns in the future. How would I construct a kernel such that the SVR model is able to predict for periodic data in the future?</p>