KernelCenterer#
- class cuml.preprocessing.KernelCenterer(*args, **kwargs)[source]#
Center a kernel matrix
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 cuml.preprocessing.StandardScaler(with_std=False).
- Attributes:
- K_fit_rows_array, shape (n_samples,)
Average of each column of kernel matrix
- K_fit_all_float
Average of kernel matrix
Methods
Examples
>>> import cupy as cp >>> from cuml.preprocessing import KernelCenterer >>> from cuml.metrics import pairwise_kernels >>> X = cp.array([[ 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.]])
- fit(K, y=None) KernelCenterer[source]#
Fit KernelCenterer
- Parameters:
- Knumpy array of shape [n_samples, n_samples]
Kernel matrix.
- Returns:
- selfreturns an instance of self.
- transform(K, copy=True) CumlArray[source]#
Center kernel matrix.
- Parameters:
- Knumpy array of shape [n_samples1, n_samples2]
Kernel matrix.
- copyboolean, optional, default True
Whether a forced copy will be triggered. If copy=False, a copy might be triggered by a conversion.
- Returns:
- K_newnumpy array of shape [n_samples1, n_samples2]