Skip to content

Instantly share code, notes, and snippets.

@kairess
Created November 16, 2017 09:07
Show Gist options
  • Save kairess/95da930b5afbbaf4540cb360cee08a96 to your computer and use it in GitHub Desktop.
Save kairess/95da930b5afbbaf4540cb360cee08a96 to your computer and use it in GitHub Desktop.
Support Vector Regression
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)
y = np.sin(X).ravel()
# Add noise to targets
y[::5] += 3 * (0.5 - np.random.rand(8))
# Fit regression model
svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)
y_rbf = svr_rbf.fit(X, y).predict(X)
# Look at the results
lw = 2
plt.scatter(X, y, color='darkorange', label='data')
plt.plot(X, y_rbf, color='navy', lw=lw, label='RBF model')
plt.xlabel('data')
plt.ylabel('target')
plt.title('Support Vector Regression')
plt.legend()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment