Svr_epsilons_demo.svg


Summary

Description
English: SVR with different epsilons. The data was generated by normally perturbing a sine curve. The plot was prepared using scikit-learn.
Date
Source Own work
Author Shiyu Ji

Python Source Code

# Note: the original version of this demo is in sklearn doc:
# http://scikit-learn.org/stable/auto_examples/gaussian_process/plot_compare_gpr_krr.html
# http://scikit-learn.org/stable/auto_examples/plot_kernel_ridge_regression.html
# Authors: Jan Hendrik Metzen <[email protected]>
# License: BSD 3 clause

import time

import numpy as np
import matplotlib
matplotlib.use('svg')
import matplotlib.pyplot as plt

from sklearn.svm import SVR
from sklearn.kernel_ridge import KernelRidge
from sklearn.model_selection import GridSearchCV
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import WhiteKernel, ExpSineSquared

rng = np.random.RandomState(0)

# Generate sample data
X = 15 * rng.rand(100, 1)
y = np.sin(X).ravel()
y[::2] += rng.normal(scale = 1.0, size = X.shape[0] // 2)  # add noise

# epsilon = 0.01
svr_e001 = SVR(kernel="rbf", epsilon=0.01, C=1)
svr_e001.fit(X, y)

# epsilon = 0.1
svr_e01 = SVR(kernel="rbf", epsilon=0.1, C=1)
svr_e01.fit(X, y)

# epsilon = 1.0
svr_e10 = SVR(kernel="rbf", epsilon=1.0, C=1)
svr_e10.fit(X, y)

# epsilon = 2.0
svr_e20 = SVR(kernel="rbf", epsilon=2.0, C=1)
svr_e20.fit(X, y)

X_plot = np.linspace(0, 20, 10000)[:, None]
# Predict using SVR
y_e001 = svr_e001.predict(X_plot)
y_e01 = svr_e01.predict(X_plot)
y_e10 = svr_e10.predict(X_plot)
y_e20 = svr_e20.predict(X_plot)

# Plot results
plt.figure(figsize=(10, 5))
lw = 2
plt.scatter(X, y, c='k', label='Data')
plt.plot(X_plot, np.sin(X_plot), color='navy', lw=lw, label='True')
plt.plot(X_plot, y_e001,color='brown', lw=lw, label = 'epsilon = 0.01')
plt.plot(X_plot, y_e01, color='turquoise', lw=lw,
         label='epsilon = 0.1')
plt.plot(X_plot, y_e10, color='orange', lw=lw,
         label='epsilon = 1.0')
plt.plot(X_plot, y_e20, color='red', lw=lw,
         label='epsilon = 2.0')
plt.xlabel('data')
plt.ylabel('target')
plt.xlim(0, 20)
plt.ylim(-3, 5)
plt.title('SVR (rbf kernel) with Different Epsilons')
plt.legend(loc="best",  scatterpoints=1, prop={'size': 8})

plt.savefig('svr_epsilons_demo.svg', format='svg')

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

3 July 2017