Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tishibas/11076250 to your computer and use it in GitHub Desktop.
Save tishibas/11076250 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- encoding: utf-8 -*-
import matplotlib.pyplot as plt
import numpy as np
from sklearn import linear_model
from sklearn import svm
sigma = 0.1
x = np.arange(0,np.pi * 2,0.1)
y = np.sin(x) + sigma * np.random.randn(x.size)
#print x.reshape(x.size,1)
X = x.reshape(x.size,1)
Y = y.reshape(y.size)
clf = linear_model.LinearRegression()
clf.fit(X,Y)
reg = svm.SVR(kernel='rbf', C=10000, gamma=0.01).fit(X,Y)
plt.plot(x,y, 'ro', x, np.sin(x),'-', x, x*clf.coef_[0] + clf.intercept_, 'g-', x, reg.predict(X), 'y^')
plt.show()
print 'score:' , reg.score(X,Y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment