ENH Adding n_jobs to kernel_approximation.Nystroem
* Update kernel_approximation.py
component_indices_ is not needed
* adding n_jobs to nystroem
* adding description for n_jobs for nystroem
* undo changes of component_indices_
* n_jobs: adding more detailed description
@@ -670,6 +670,17 @@ class Nystroem(TransformerMixin, BaseEstimator):
Pass an int for reproducible output across multiple function calls.
See :term:`Glossary <random_state>`.
+ n_jobs : int, default=None
+ The number of jobs to use for the computation. This works by breaking
+ down the kernel matrix into n_jobs even slices and computing them in
+ parallel.
+
+ ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
+ ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
+ for more details.
+
+ .. versionadded:: 0.24
+
Attributes
----------
components_ : ndarray of shape (n_components, n_features)
@@ -719,7 +730,9 @@ class Nystroem(TransformerMixin, BaseEstimator):
"""
@_deprecate_positional_args
def __init__(self, kernel="rbf", *, gamma=None, coef0=None, degree=None,
- kernel_params=None, n_components=100, random_state=None):
+ kernel_params=None, n_components=100, random_state=None,
+ n_jobs=None):
+
self.kernel = kernel
self.gamma = gamma
self.coef0 = coef0
@@ -727,6 +740,7 @@ class Nystroem(TransformerMixin, BaseEstimator):
self.kernel_params = kernel_params
self.n_components = n_components
self.random_state = random_state
+ self.n_jobs = n_jobs
def fit(self, X, y=None):
"""Fit estimator to data.
@@ -760,6 +774,7 @@ class Nystroem(TransformerMixin, BaseEstimator):
basis_kernel = pairwise_kernels(basis, metric=self.kernel,
filter_params=True,
+ n_jobs=self.n_jobs,
**self._get_kernel_params())
# sqrt of kernel matrix on basis vectors
@@ -793,6 +808,7 @@ class Nystroem(TransformerMixin, BaseEstimator):
embedded = pairwise_kernels(X, self.components_,
metric=self.kernel,
filter_params=True,
+ n_jobs=self.n_jobs,
**kernel_params)
return np.dot(embedded, self.normalization_.T)
