title: Modeling-Support Vector Regression (SVR) vs. Linear Regression
body: <p>I'm a little new with modeling techniques and I'm trying to compare SVR and Linear Regression. I've used f(x) = 5x+10 linear function to generate training and test data set. I've written following code snippet so far:</p>
  
  <pre><code>import csv 
  import pandas as pd
  import numpy as np 
  import matplotlib.pyplot as plt 
  from sklearn.linear_model import LinearRegression
  
  with open('test.csv', 'r') as f1:
    train_dataframe = pd.read_csv(f1)
  
  X_train = train_dataframe.iloc[:30,(0)]
  y_train = train_dataframe.iloc[:30,(1)]
  
  with open('test.csv','r') as f2:
       test_dataframe = pd.read_csv(f2)
  
  X_test = test_dataframe.iloc[30:,(0)]
  y_test = test_dataframe.iloc[30:,(1)]
  
  svr = svm.SVR(kernel="rbf", gamma=0.1)
  log = LinearRegression()
  svr.fit(X_train.reshape(-1,1),y_train)
  log.fit(X_train.reshape(-1,1), y_train)
  
  predSVR = svr.predict(X_test.reshape(-1,1))
  predLog = log.predict(X_test.reshape(-1,1))
  
  plt.plot(X_test, y_test, label='true data')
  plt.plot(X_test, predSVR, 'co', label='SVR')
  plt.plot(X_test, predLog, 'mo', label='LogReg')
  plt.legend()
  plt.show()
  </code></pre>
  
  <p>As you can see in the picture, Linear Regression works fine but SVM has poor prediction accuracy. </p>
  
  <p><a href="https://i.stack.imgur.com/gwIie.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gwIie.png" alt="enter image description here"></a></p>
  
  <p>Please let me know if you any suggestion to tackle this issue. </p>
  
  <p>Thanks</p>