title: How do I propagate the errors of my time series data through the python/scikit-learn/SVR fit?
body: <p>Normally when doing a fit to some time series data (e.g., a polynomial fit), functions will return an associated error with each fitted point. I'm now trying out scikit-learn's support vector regression (SVR) fitting instead, which doesn't have any such return. There is a handy function in scikit-learn called <code>validation_score</code> that can tell me the accuracy score of various fits, from which I select the best one. That's not ideal because it doesn't allow me to continue propagating errors through any subsequent manipulations of the data. </p>
  
  <p>How do I propagate the errors of my time series data through the python/scikit-learn/SVR fit?</p>
  
  <pre><code>import numpy as np
  from sklearn.pipeline import make_pipeline
  from sklearn.model_selection import validation_curve, ShuffleSplit
  from sklearn.svm import SVR
  
  # Create some fake data
  times = np.linspace(0, 10, 10)[:, None]
  data = np.sin(times).ravel()
  uncertainty = np.linspace(0.05, 0.1, num=10)
  np.random.shuffle(uncertainty)
  sample_weight = 1 / uncertainty
  
  
  # Quick helper function
  def jpm_svr(gamma=1e-6, **kwargs):
      return make_pipeline(SVR(kernel='rbf', C=1e3, gamma=gamma, **kwargs))
  
  # Find the best value of gamma
  gamma = np.logspace(-2, 5, num=11, base=10)
  shuffle_split = ShuffleSplit(n_splits=20, train_size=0.5, test_size=0.5, random_state=None)
  # In the next line I also want to input the sample_weight but can't
  train_score, val_score = validation_curve(jpm_svr(), X, y, #sample_weight :(
                                            'svr__gamma',
                                            gamma, cv=shuffle_split, scoring=evs)
  score = np.median(val_score, axis=1)
  best_score_index = np.argmax(score)
  
  # Generate model with best value of gamma
  # Also note that I can now pass in sample_weight
  # But there aren't any direct returns from SVR for uncertainty
  model = SVR(kernel='rbf', C=1e3, gamma=gamma[best_score_index]).fit(times, data, sample_weight)
  X_test = np.linspace(0, 10, 50)[:, None]
  y_test = model.predict(X_test)
  </code></pre>