Guest User

Untitled

a guest
Nov 18th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. import numpy as np
  2. from sklearn.svm import SVR
  3. import matplotlib.pyplot as plt
  4.  
  5. # Generate sample data
  6. X = np.sort(5 * np.random.rand(40, 1), axis=0)
  7. y = np.sin(X).ravel()
  8.  
  9. # Add noise to targets
  10. y[::5] += 3 * (0.5 - np.random.rand(8))
  11.  
  12. # Fit regression model
  13. svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)
  14. y_rbf = svr_rbf.fit(X, y).predict(X)
  15.  
  16. # Look at the results
  17. lw = 2
  18. plt.scatter(X, y, color='darkorange', label='data')
  19. plt.plot(X, y_rbf, color='navy', lw=lw, label='RBF model')
  20. plt.xlabel('data')
  21. plt.ylabel('target')
  22. plt.title('Support Vector Regression')
  23. plt.legend()
  24. plt.show()
Add Comment
Please, Sign In to add comment