himalaya.kernel_ridge.KernelCenterer

class himalaya.kernel_ridge.KernelCenterer(force_cpu=False)[source]

Center a kernel matrix.

Adapt sklearn.preprocessing.KernelCenterer to use other backends.

Let K(x, z) be a kernel defined by phi(x)^T phi(z), where phi is a function mapping x to a Hilbert space. KernelCenterer centers (i.e., normalize to have zero mean) the data without explicitly computing phi(x). It is equivalent to centering phi(x) with sklearn.preprocessing.StandardScaler(with_std=False).

Parameters
force_cpubool

If True, computations will be performed on CPU, ignoring the current backend. If False, use the current backend.

Examples

>>> from himalaya.kernel_ridge import KernelCenterer
>>> from himalaya.kernel_ridge import pairwise_kernels
>>> X = [[ 1., -2.,  2.],
...      [ -2.,  1.,  3.],
...      [ 4.,  1., -2.]]
>>> K = pairwise_kernels(X, metric='linear')
>>> K
array([[  9.,   2.,  -2.],
       [  2.,  14., -13.],
       [ -2., -13.,  21.]])
>>> transformer = KernelCenterer().fit(K)
>>> transformer
KernelCenterer()
>>> transformer.transform(K)
array([[  5.,   0.,  -5.],
       [  0.,  14., -14.],
       [ -5., -14.,  19.]])
Attributes
K_fit_rows_array of shape (n_samples,)

Average of each column of kernel matrix.

K_fit_all_float

Average of kernel matrix.

Methods

fit(K[, y])

Fit KernelCenterer

fit_transform(X[, y])

Fit to data, then transform it.

get_params([deep])

Get parameters for this estimator.

set_params(**params)

Set the parameters of this estimator.

transform(K[, copy])

Center kernel matrix.