optiml.ml.svm.losses module

class optiml.ml.svm.losses.SVMLoss(svm, X, y)[source]

Bases: OptimizationFunction, ABC

Base abstract class for all SVM loss functions. It defines the primal objective, i.e., the regularization term plus the loss term averaged over the training samples, together with its jacobian.

Subclasses must implement loss, loss_jacobian and step_size.

Parameters:
  • svm (SVM instance) – The SVM estimator this loss is attached to. It provides the hyper-parameters used by the objective, e.g., C and fit_intercept.

  • X (ndarray of shape (n_samples, n_features)) – Training data over which the loss is evaluated.

  • y (ndarray of shape (n_samples,)) – Target values associated with X.

args()[source]
x_star()[source]
f_star()[source]
function(packed_coef_inter, X_batch=None, y_batch=None)[source]
loss(y_pred, y_true)[source]
jacobian(packed_coef_inter, X_batch=None, y_batch=None)[source]

The Jacobian (i.e., the gradient) of the function.

Parameters:

x – 1D array of points at which the Jacobian is to be computed.

Returns:

the Jacobian of the function at x.

loss_jacobian(packed_coef_inter, X_batch, y_batch)[source]
step_size(X_batch, y_batch)[source]
function_jacobian(*args, **kwargs)
hessian(x)

The Hessian matrix of the function.

Parameters:

x – 1D array of points at which the Hessian is to be computed.

Returns:

the Hessian matrix of the function at x.

class optiml.ml.svm.losses.Hinge(svm, X, y)[source]

Bases: SVMLoss

Compute the hinge loss for classification as:

\[L(y_{pred}, y_{true}) = \max(0, 1 - y_{true} \, y_{pred})\]
Parameters:
  • svm (SVM instance) – The SVM estimator this loss is attached to. It provides the hyper-parameters used by the objective, e.g., C and fit_intercept.

  • X (ndarray of shape (n_samples, n_features)) – Training data over which the loss is evaluated.

  • y (ndarray of shape (n_samples,)) – Target values associated with X.

loss(y_pred, y_true)[source]
loss_jacobian(packed_coef_inter, X_batch, y_batch)[source]
step_size(X_batch, y_batch)[source]
args()
f_star()
function(packed_coef_inter, X_batch=None, y_batch=None)
function_jacobian(*args, **kwargs)
hessian(x)

The Hessian matrix of the function.

Parameters:

x – 1D array of points at which the Hessian is to be computed.

Returns:

the Hessian matrix of the function at x.

jacobian(packed_coef_inter, X_batch=None, y_batch=None)

The Jacobian (i.e., the gradient) of the function.

Parameters:

x – 1D array of points at which the Jacobian is to be computed.

Returns:

the Jacobian of the function at x.

x_star()
class optiml.ml.svm.losses.SquaredHinge(svm, X, y)[source]

Bases: Hinge

Compute the squared hinge loss for classification as:

\[L(y_{pred}, y_{true}) = \max(0, 1 - y_{true} \, y_{pred})^2\]
Parameters:
  • svm (SVM instance) – The SVM estimator this loss is attached to. It provides the hyper-parameters used by the objective, e.g., C and fit_intercept.

  • X (ndarray of shape (n_samples, n_features)) – Training data over which the loss is evaluated.

  • y (ndarray of shape (n_samples,)) – Target values associated with X.

loss(y_pred, y_true)[source]
loss_jacobian(packed_coef_inter, X_batch, y_batch)[source]
step_size(X_batch, y_batch)[source]
args()
f_star()
function(packed_coef_inter, X_batch=None, y_batch=None)
function_jacobian(*args, **kwargs)
hessian(x)

The Hessian matrix of the function.

Parameters:

x – 1D array of points at which the Hessian is to be computed.

Returns:

the Hessian matrix of the function at x.

jacobian(packed_coef_inter, X_batch=None, y_batch=None)

The Jacobian (i.e., the gradient) of the function.

Parameters:

x – 1D array of points at which the Jacobian is to be computed.

Returns:

the Jacobian of the function at x.

x_star()
class optiml.ml.svm.losses.EpsilonInsensitive(svm, X, y, epsilon)[source]

Bases: SVMLoss

Compute the epsilon-insensitive loss for regression as:

\[L(y_{pred}, y_{true}) = \max(0, \lvert y_{true} - y_{pred} \rvert - \epsilon)\]
Parameters:
  • svm (SVM instance) – The SVM estimator this loss is attached to.

  • X (ndarray of shape (n_samples, n_features)) – Training data over which the loss is evaluated.

  • y (ndarray of shape (n_samples,)) – Target values associated with X.

  • epsilon (float) – Width of the epsilon-tube within which no penalty is associated with points predicted within a distance epsilon from the actual value.

loss(y_pred, y_true)[source]
loss_jacobian(packed_coef_inter, X_batch, y_batch)[source]
step_size(X_batch, y_batch)[source]
args()
f_star()
function(packed_coef_inter, X_batch=None, y_batch=None)
function_jacobian(*args, **kwargs)
hessian(x)

The Hessian matrix of the function.

Parameters:

x – 1D array of points at which the Hessian is to be computed.

Returns:

the Hessian matrix of the function at x.

jacobian(packed_coef_inter, X_batch=None, y_batch=None)

The Jacobian (i.e., the gradient) of the function.

Parameters:

x – 1D array of points at which the Jacobian is to be computed.

Returns:

the Jacobian of the function at x.

x_star()
class optiml.ml.svm.losses.SquaredEpsilonInsensitive(svm, X, y, epsilon)[source]

Bases: EpsilonInsensitive

Compute the squared epsilon-insensitive loss for regression as:

\[L(y_{pred}, y_{true}) = \max(0, \lvert y_{true} - y_{pred} \rvert - \epsilon)^2\]
Parameters:
  • svm (SVM instance) – The SVM estimator this loss is attached to.

  • X (ndarray of shape (n_samples, n_features)) – Training data over which the loss is evaluated.

  • y (ndarray of shape (n_samples,)) – Target values associated with X.

  • epsilon (float) – Width of the epsilon-tube within which no penalty is associated with points predicted within a distance epsilon from the actual value.

loss(y_pred, y_true)[source]
loss_jacobian(packed_coef_inter, X_batch, y_batch)[source]
step_size(X_batch, y_batch)[source]
args()
f_star()
function(packed_coef_inter, X_batch=None, y_batch=None)
function_jacobian(*args, **kwargs)
hessian(x)

The Hessian matrix of the function.

Parameters:

x – 1D array of points at which the Hessian is to be computed.

Returns:

the Hessian matrix of the function at x.

jacobian(packed_coef_inter, X_batch=None, y_batch=None)

The Jacobian (i.e., the gradient) of the function.

Parameters:

x – 1D array of points at which the Jacobian is to be computed.

Returns:

the Jacobian of the function at x.

x_star()
optiml.ml.svm.losses.hinge

alias of Hinge

optiml.ml.svm.losses.squared_hinge

alias of SquaredHinge

optiml.ml.svm.losses.epsilon_insensitive

alias of EpsilonInsensitive

optiml.ml.svm.losses.squared_epsilon_insensitive

alias of SquaredEpsilonInsensitive