Center kernel matrix. Parameters ---------- K : ndarray of shape (n_samples1, n_samples2) Kernel matrix. copy : bool, default=True Set to False to perform inplace computation. Returns ------- K_new : ndarray of shape
(self, K, copy=True)
| 2550 | return self |
| 2551 | |
| 2552 | def transform(self, K, copy=True): |
| 2553 | """Center kernel matrix. |
| 2554 | |
| 2555 | Parameters |
| 2556 | ---------- |
| 2557 | K : ndarray of shape (n_samples1, n_samples2) |
| 2558 | Kernel matrix. |
| 2559 | |
| 2560 | copy : bool, default=True |
| 2561 | Set to False to perform inplace computation. |
| 2562 | |
| 2563 | Returns |
| 2564 | ------- |
| 2565 | K_new : ndarray of shape (n_samples1, n_samples2) |
| 2566 | Returns the instance itself. |
| 2567 | """ |
| 2568 | check_is_fitted(self) |
| 2569 | |
| 2570 | xp, _ = get_namespace(K) |
| 2571 | |
| 2572 | K = validate_data( |
| 2573 | self, |
| 2574 | K, |
| 2575 | copy=copy, |
| 2576 | force_writeable=True, |
| 2577 | dtype=_array_api.supported_float_dtypes(xp, device=device(K)), |
| 2578 | reset=False, |
| 2579 | ) |
| 2580 | |
| 2581 | K_pred_cols = (xp.sum(K, axis=1) / self.K_fit_rows_.shape[0])[:, None] |
| 2582 | |
| 2583 | K -= self.K_fit_rows_ |
| 2584 | K -= K_pred_cols |
| 2585 | K += self.K_fit_all_ |
| 2586 | |
| 2587 | return K |
| 2588 | |
| 2589 | @property |
| 2590 | def _n_features_out(self): |