8000 DOC document "precomputed" kernel for KernelRidge (#11134) · scikit-learn/scikit-learn@20cb37e · GitHub
[go: up one dir, main page]

Skip to content

Commit 20cb37e

Browse files
wesbarnettjnothman
authored andcommitted
DOC document "precomputed" kernel for KernelRidge (#11134)
* document "precomputed" kernel for KernelRidge See #8445. * fix doc for KernelRidge use n_samples_fitted in score
1 parent 5fcf6f4 commit 20cb37e

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

sklearn/base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,10 @@ def score(self, X, y, sample_weight=None):
354354
Parameters
355355
----------
356356
X : array-like, shape = (n_samples, n_features)
357-
Test samples.
357+
Test samples. For some estimators this may be a
358+
precomputed kernel matrix instead, shape = (n_samples,
359+
n_samples_fitted], where n_samples_fitted is the number of
360+
samples used in the fitting for the estimator.
358361
359362
y : array-like, shape = (n_samples) or (n_samples, n_outputs)
360363
True values for X.

sklearn/kernel_ridge.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ class KernelRidge(BaseEstimator, RegressorMixin):
4848
kernel : string or callable, default="linear"
4949
Kernel mapping used internally. A callable should accept two arguments
5050
and the keyword arguments passed to this object as kernel_params, and
51-
should return a floating point number.
51+
should return a floating point number. Set to "precomputed" in
52+
order to pass a precomputed kernel matrix to the estimator
53+
methods instead of samples.
5254
5355
gamma : float, default=None
5456
Gamma parameter for the RBF, laplacian, polynomial, exponential chi2
@@ -73,7 +75,9 @@ class KernelRidge(BaseEstimator, RegressorMixin):
7375
Representation of weight vector(s) in kernel space
7476
7577
X_fit_ : {array-like, sparse matrix}, shape = [n_samples, n_features]
76-
Training data, which is also required for prediction
78+
Training data, which is also required for prediction. If
79+
kernel == "precomputed" this is instead the precomputed
80+
training matrix, shape = [n_samples, n_samples].
7781
7882
References
7983
----------
@@ -130,7 +134,9 @@ def fit(self, X, y=None, sample_weight=None):
130134
Parameters
131135
----------
132136
X : {array-like, sparse matrix}, shape = [n_samples, n_features]
133-
Training data
137+
Training data. If kernel == "precomputed" this is instead
138+
a precomputed kernel matrix, shape = [n_samples,
139+
n_samples].
134140
135141
y : array-like, shape = [n_samples] or [n_samples, n_targets]
136142
Target values
@@ -173,7 +179,10 @@ def predict(self, X):
173179
Parameters
174180
----------
175181
X : {array-like, sparse matrix}, shape = [n_samples, n_features]
176-
Samples.
182+
Samples. If kernel == "precomputed" this is instead a
183+
precomputed kernel matrix, shape = [n_samples,
184+
n_samples_fitted], where n_samples_fitted is the number of
185+
samples used in the fitting for this estimator.
177186
178187
Returns
179188
-------

0 commit comments

Comments
 (0)
0