__author__ = 'lichaozhang'

print(__doc__)

import numpy as np
from sklearn.svm import SVR
import matplotlib.pyplot as plt

###############################################################################
# Generate sample data
#X = np.sort(5 * np.random.rand(40, 1), axis=0)

X = np.array(0.5,0.5,0.4,0.6,0.4,1.4,1.7,1.8,1.9,2.2)
X = X[:, np.newaxis]
#X =X.T
#y = np.sin(X).ravel()+1
y = [48,45,49,51,52,7.5,8.5,20.5,20.1,8.4]
print X
print y
###############################################################################
# Add noise to targets
#y[::5] += 3 * (0.5 - np.random.rand(8))+1

###############################################################################
# Fit regression model
svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)
svr_lin = SVR(kernel='linear', C=1e3)
svr_poly = SVR(kernel='poly', C=1e3, degree=2)
y_rbf = svr_rbf.fit(X, y).predict(X)
y_lin = svr_lin.fit(X, y).predict(X)
y_poly = svr_poly.fit(X, y).predict(X)

###############################################################################
# look at the results
plt.scatter(X, y, c='k', label='data')
plt.hold('on')
plt.plot(X, y_rbf, c='g', label='RBF model')
plt.plot(X, y_lin, c='r', label='Linear model')
plt.plot(X, y_poly, c='b', label='Polynomial model')
plt.xlabel('data')
plt.ylabel('runtime')
plt.title('Support Vector Regression')
plt.legend()
plt.show()