Created
April 19, 2014 06:50
-
-
Save tishibas/11076250 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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