# KernelCenterer

### *class* cuml.preprocessing.KernelCenterer(\*args, \*\*kwargs)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py#L2186)

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_**
  : Average of each column of kernel matrix

  **K_fit_all_**
  : Average of kernel matrix

### Methods

| [`fit`](#cuml.preprocessing.KernelCenterer.fit)(K[, y])          | Fit KernelCenterer    |
|-----------------------------------------------------------------------|-----------------------|
| [`transform`](#cuml.preprocessing.KernelCenterer.transform)(K[, copy]) | Center kernel matrix. |

### Examples

```pycon
>>> 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.]])
```

<!-- !! processed by numpydoc !! -->

#### fit(K, y=None) → [KernelCenterer](#cuml.preprocessing.KernelCenterer)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py#L2242)

Fit KernelCenterer

* **Parameters:**
  **K**
  : Kernel matrix.
* **Returns:**
  **self**

<!-- !! processed by numpydoc !! -->

#### fit_transform(X, y=None, \*\*fit_params)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/utils/skl_dependencies.py#L42)

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params
and returns a transformed version of X.

* **Parameters:**
  **X**

  **y**
  : Target values.

  **\*\*fit_params**
  : Additional fit parameters.
* **Returns:**
  **X_new**
  : Transformed array.

<!-- !! processed by numpydoc !! -->

#### get_feature_names_out(input_features=None)

Get output feature names for transformation.

The feature names out will prefixed by the lowercased class name. For
example, if the transformer outputs 3 features, then the feature names
out are: `["class_name0", "class_name1", "class_name2"]`.

* **Parameters:**
  **input_features**
  : Only used to validate feature names with the names seen in [`fit`](#cuml.preprocessing.KernelCenterer.fit).
* **Returns:**
  **feature_names_out**
  : Transformed feature names.

<!-- !! processed by numpydoc !! -->

#### get_params(deep=True)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L191)

Returns a dict of all params owned by this class. If the child class
has appropriately overridden the `_get_param_names` method and does not
need anything other than what is there in this method, then it doesn’t
have to override this method

<!-- !! processed by numpydoc !! -->

#### set_params(\*\*params)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L200)

Accepts a dict of params and updates the corresponding ones owned by
this class. If the child class has appropriately overridden the
`_get_param_names` method and does not need anything other than what is,
there in this method, then it doesn’t have to override this method

<!-- !! processed by numpydoc !! -->

#### transform(K, copy=True)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py#L2267)

Center kernel matrix.

* **Parameters:**
  **K**
  : Kernel matrix.

  **copy**
  : Whether a forced copy will be triggered. If copy=False,
    a copy might be triggered by a conversion.
* **Returns:**
  **K_new**

<!-- !! processed by numpydoc !! -->
