surrogate.nystroem.Nystroem
surrogate.nystroem.Nystroem(kernel='rbf', n_components=100, random_state=None)Approximate a feature map of a kernel using a subset of data.
The Nystroem method approximates a kernel map using a subset of the training data. It constructs an approximate feature map X \mapsto X' such that X'.dot(X'.T) \approx K(X, X).
This is particularly useful when: * n (samples) is moderate/large: The exact kernel method scales as O(n^3). Nystroem reduces complexity to O(n * n_components^2) for training. * k (features) is large: By setting n_components such that k < n_components << n, it projects high-dimensional data into a manageable feature space where distance calculations are cheaper (if followed by a linear model).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| kernel | str or callable or Kernel | Kernel map to be approximated. Can be a string (e.g., ‘rbf’), a callable, or a spotoptim.surrogate.kernels.Kernel instance. Defaults to ‘rbf’. |
'rbf' |
| n_components | int | Number of features to construct. This corresponds to the number of samples used to construct the basis. Determines the dimension of the transformed feature space. Defaults to 100. | 100 |
| random_state | int, RandomState instance or None | Pseudo-random number generator to control the uniform sampling without replacement of n_components of the training data. Defaults to None. | None |
Methods
| Name | Description |
|---|---|
| fit | Fit estimator to data. |
| fit_transform | Fit to data, then transform it. |
| transform | Apply feature map to X. |
fit
surrogate.nystroem.Nystroem.fit(X, y=None)Fit estimator to data.
Samples a subset of n_components training points to serve as the basis, computes the kernel matrix on these points, and computes the normalization matrix.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| X | np.ndarray | Training data, shape (n_samples, n_features). | required |
| y | np.ndarray | Target values (ignored). | None |
Returns
| Name | Type | Description |
|---|---|---|
| Nystroem | Nystroem | Returns the instance itself. |
fit_transform
surrogate.nystroem.Nystroem.fit_transform(X, y=None)Fit to data, then transform it.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| X | np.ndarray | Training data. | required |
| y | np.ndarray | Target values. | None |
Returns
| Name | Type | Description |
|---|---|---|
| np.ndarray | np.ndarray: Transformed data. |
transform
surrogate.nystroem.Nystroem.transform(X)Apply feature map to X.
Computes the kernel between X and the basis vectors, multiplied by the normalization. No sample reduction happens here; the output has the same number of samples as X.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| X | np.ndarray | Data to transform, shape (n_samples, n_features). | required |
Returns
| Name | Type | Description |
|---|---|---|
| np.ndarray | np.ndarray: Transformed data, shape (n_samples, n_components). |