Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
Add Comment
Please, Sign In to add comment