NuSVR: Nu-Support Vector Regression#

  • Es similar a NuSVC.

  • Para regresión, usa un parámetro nu que controla el número de vectores de soporte.

  • Mientras que NuSVC reemplaza el parámetro C, NuSVR reemplaza el parámetro epsilon del modelo epsilon-SVR.

[1]:
import numpy as np

n_samples, n_features = 10, 5
np.random.seed(0)
y = np.random.randn(n_samples)
X = np.random.randn(n_samples, n_features)
[2]:
from sklearn.svm import NuSVR

nuSVR = NuSVR(
    # ----------------------------------------------------------------------------
    # An upper bound on the fraction of margin errors and a
    # lower bound of the fraction of support vectors. Should be in the interval
    # (0, 1].
    nu=0.5,
    # ----------------------------------------------------------------------------
    # Specifies the kernel type to be used in the algorithm. If none is given,
    # ‘rbf’ will be used.
    # * 'linear'
    # * 'poly'
    # * rbf'
    # * 'sigmoid'
    kernel="rbf",
    # ----------------------------------------------------------------------------
    # Degree of the polynomial kernel function (‘poly’). Must be non-negative.
    # Ignored by all other kernels.
    degree=3,
    # ----------------------------------------------------------------------------
    # Kernel coefficient for ‘rbf’, ‘poly’ and ‘sigmoid’.
    # * if gamma='scale' (default) is passed then it uses
    #   1 / (n_features * X.var()) as value of gamma,
    # * if ‘auto’, uses 1 / n_features
    # * if float, must be non-negative.
    gamma="scale",
    # ----------------------------------------------------------------------------
    # Independent term in kernel function. It is only significant in ‘poly’ and
    # ‘sigmoid’.
    coef0=0.0,
    # ----------------------------------------------------------------------------
    # Tolerance for stopping criterion.
    tol=1e-3,
    # ----------------------------------------------------------------------------
    # Hard limit on iterations within solver, or -1 for no limit.
    max_iter=-1,
)

nuSVR.fit(X, y)
nuSVR.predict(X)
[2]:
array([1.14053108, 1.02412027, 1.10907372, 1.61648827, 1.22006777,
       0.71194418, 1.16836156, 0.47260591, 0.64168051, 0.72338921])
[3]:
nuSVR.score(X, y)
[3]:
0.4068511281330819