Fit Kernel Ridge regression model. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) Training data. If kernel == "precomputed" this is instead a precomputed kernel matrix, of shape (n_samples, n_samples).
(self, X, y, sample_weight=None)
| 179 | |
| 180 | @_fit_context(prefer_skip_nested_validation=True) |
| 181 | def fit(self, X, y, sample_weight=None): |
| 182 | """Fit Kernel Ridge regression model. |
| 183 | |
| 184 | Parameters |
| 185 | ---------- |
| 186 | X : {array-like, sparse matrix} of shape (n_samples, n_features) |
| 187 | Training data. If kernel == "precomputed" this is instead |
| 188 | a precomputed kernel matrix, of shape (n_samples, n_samples). |
| 189 | |
| 190 | y : array-like of shape (n_samples,) or (n_samples, n_targets) |
| 191 | Target values. |
| 192 | |
| 193 | sample_weight : float or array-like of shape (n_samples,), default=None |
| 194 | Individual weights for each sample, ignored if None is passed. |
| 195 | |
| 196 | Returns |
| 197 | ------- |
| 198 | self : object |
| 199 | Returns the instance itself. |
| 200 | """ |
| 201 | # Convert data |
| 202 | X, y = validate_data( |
| 203 | self, X, y, accept_sparse=("csr", "csc"), multi_output=True, y_numeric=True |
| 204 | ) |
| 205 | if sample_weight is not None and not isinstance(sample_weight, float): |
| 206 | sample_weight = _check_sample_weight(sample_weight, X) |
| 207 | |
| 208 | K = self._get_kernel(X) |
| 209 | alpha = np.atleast_1d(self.alpha) |
| 210 | |
| 211 | ravel = False |
| 212 | if len(y.shape) == 1: |
| 213 | y = y.reshape(-1, 1) |
| 214 | ravel = True |
| 215 | |
| 216 | copy = self.kernel == "precomputed" |
| 217 | self.dual_coef_ = _solve_cholesky_kernel(K, y, alpha, sample_weight, copy) |
| 218 | if ravel: |
| 219 | self.dual_coef_ = self.dual_coef_.ravel() |
| 220 | |
| 221 | self.X_fit_ = X |
| 222 | |
| 223 | return self |
| 224 | |
| 225 | def predict(self, X): |
| 226 | """Predict using the kernel ridge model. |
nothing calls this directly
no test coverage detected