Support Vector Regression (SVR) using linear and non-linear kernelsΒΆ
Toy example of 1D regression using linear, polynomial and RBF kernels.
print(__doc__)
import numpy as np
from sklearn.svm import SVR
import matplotlib.pyplot as plt
Generate sample data
Add noise to targets
y[::5] += 3 * (0.5 - np.random.rand(8))
Fit regression model
look at the results
lw = 2
plt.scatter(X, y, color='darkorange', label='data')
plt.hold('on')
plt.plot(X, y_rbf, color='navy', lw=lw, label='RBF model')
plt.plot(X, y_lin, color='c', lw=lw, label='Linear model')
plt.plot(X, y_poly, color='cornflowerblue', lw=lw, label='Polynomial model')
plt.xlabel('data')
plt.ylabel('target')
plt.title('Support Vector Regression')
plt.legend()
plt.show()
Total running time of the script: (0 minutes 0.778 seconds)
Download Python source code:
plot_svm_regression.py
Download IPython notebook:
plot_svm_regression.ipynb