I’ve created a model with SVR and using this csv file as training and test data. I’ve tried following python code snippet but I’m not sure either the model is working or my plots are correct!?
import csv
import pandas as pd
import numpy as np
from sklearn.svm import SVR
import matplotlib.pyplot as plt
from sklearn.cross_validation import train_test_split
with open('model_data.csv', 'r') as f:
dataframe = pd.read_csv(f)
X = dataframe.iloc[:,(0)]
y = dataframe.iloc[:,(1)]
X_train, X_test, y_train, y_test = train_test_split(X, y)
svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)
svr_lin = SVR(kernel='linear', C=1e3)
y_rbf = svr_rbf.fit(X_train.reshape(-1,1),y_train).predict(X_test.reshape(-1,1))
y_lin = svr_lin.fit(X_train.reshape(-1,1),y_train).predict(X_test.reshape(-1,1))
plt.scatter(X, y, c='k', label='data')
plt.hold('on')
plt.plot(X_test.reshape(-1,1), y_rbf, c='g', label='RBF model')
plt.plot(X_test.reshape(-1,1), y_lin, c='r', label='Linear model')
plt.xlabel('data')
plt.ylabel('target')
plt.title('Support Vector Regression')
plt.legend()
plt.show()
I’m not experienced with machine learning techniques.Please let me know if the model is not correct or my data is not prepared well.
Thanks.