optiml.ml.svm.kernels module

class optiml.ml.svm.kernels.Kernel[source]

Bases: BaseEstimator, ABC

Base abstract class for all kernel functions. A kernel computes the pairwise similarities (i.e., the Gram matrix) between two sets of samples.

Subclasses must implement __call__.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:

routing – A MetadataRequest encapsulating routing information.

Return type:

MetadataRequest

get_params(deep=True)

Get parameters for this estimator.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:

**params (dict) – Estimator parameters.

Returns:

self – Estimator instance.

Return type:

estimator instance

class optiml.ml.svm.kernels.LinearKernel[source]

Bases: Kernel

Compute the linear kernel between X and Y:

\[K(X, Y) = \langle X, Y \rangle\]
get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:

routing – A MetadataRequest encapsulating routing information.

Return type:

MetadataRequest

get_params(deep=True)

Get parameters for this estimator.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:

**params (dict) – Estimator parameters.

Returns:

self – Estimator instance.

Return type:

estimator instance

class optiml.ml.svm.kernels.PolyKernel(degree=3, gamma='scale', coef0=0.0)[source]

Bases: Kernel

Compute the polynomial kernel between X and Y:

\[K(X, Y) = (\gamma \langle X, Y \rangle + coef_0)^{degree}\]
Parameters:
  • degree (int, default=3) – Degree of the polynomial kernel function.

  • gamma ({'scale', 'auto'} or float, default='scale') –

    Kernel coefficient for kernel function.

    • if gamma=’scale’ (default) is passed then it uses 1 / (n_features * X.var()) as value of gamma,

    • if gamma=’auto’, uses 1 / n_features.

  • coef0 (float, default=0.0) – Independent term in kernel function.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:

routing – A MetadataRequest encapsulating routing information.

Return type:

MetadataRequest

get_params(deep=True)

Get parameters for this estimator.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:

**params (dict) – Estimator parameters.

Returns:

self – Estimator instance.

Return type:

estimator instance

class optiml.ml.svm.kernels.GaussianKernel(gamma='scale')[source]

Bases: Kernel

Compute the gaussian RBF kernel between X and Y:

\[K(X, Y) = e^{-\gamma \lVert X - Y \rVert_2^2}\]
Parameters:

gamma ({'scale', 'auto'} or float, default='scale') –

Kernel coefficient for kernel function.

  • if gamma=’scale’ (default) is passed then it uses 1 / (n_features * X.var()) as value of gamma,

  • if gamma=’auto’, uses 1 / n_features.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:

routing – A MetadataRequest encapsulating routing information.

Return type:

MetadataRequest

get_params(deep=True)

Get parameters for this estimator.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:

**params (dict) – Estimator parameters.

Returns:

self – Estimator instance.

Return type:

estimator instance

class optiml.ml.svm.kernels.LaplacianKernel(gamma='scale')[source]

Bases: Kernel

Compute the laplacian RBF kernel between X and Y:

\[K(X, Y) = e^{-\gamma \lVert X - Y \rVert_1}\]
Parameters:

gamma ({'scale', 'auto'} or float, default='scale') –

Kernel coefficient for kernel function.

  • if gamma=’scale’ (default) is passed then it uses 1 / (n_features * X.var()) as value of gamma,

  • if gamma=’auto’, uses 1 / n_features.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:

routing – A MetadataRequest encapsulating routing information.

Return type:

MetadataRequest

get_params(deep=True)

Get parameters for this estimator.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:

**params (dict) – Estimator parameters.

Returns:

self – Estimator instance.

Return type:

estimator instance

class optiml.ml.svm.kernels.SigmoidKernel(gamma='scale', coef0=0.0)[source]

Bases: Kernel

Compute the sigmoid kernel between X and Y:

\[K(X, Y) = \tanh(\gamma \langle X, Y \rangle + coef_0)\]
Parameters:
  • gamma ({'scale', 'auto'} or float, default='scale') –

    Kernel coefficient for kernel function.

    • if gamma=’scale’ (default) is passed then it uses 1 / (n_features * X.var()) as value of gamma,

    • if gamma=’auto’, uses 1 / n_features.

  • coef0 (float, default=0.0) – Independent term in kernel function.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:

routing – A MetadataRequest encapsulating routing information.

Return type:

MetadataRequest

get_params(deep=True)

Get parameters for this estimator.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:

**params (dict) – Estimator parameters.

Returns:

self – Estimator instance.

Return type:

estimator instance