# SpectralEmbedding

### *class* cuml.manifold.SpectralEmbedding(n_components=2, affinity='nearest_neighbors', random_state=None, n_neighbors=None, verbose=False, output_type=None)

Spectral embedding for non-linear dimensionality reduction.

Forms an affinity matrix given by the specified function and
applies spectral decomposition to the corresponding graph laplacian.
The resulting transformation is given by the value of the
eigenvectors for each data point.

Note : Laplacian Eigenmaps is the actual algorithm implemented here.

* **Parameters:**
  **n_components**
  : The dimension of the projected subspace.

  **affinity**
  : How to construct the affinity matrix.
    : - ‘nearest_neighbors’ : construct the affinity matrix by computing a
        graph of nearest neighbors.
      - ‘precomputed’ : interpret `X` as a precomputed affinity matrix.

  **random_state**
  : A pseudo random number generator used for the initialization.
    Use an int to make the results deterministic across calls.

  **n_neighbors**
  : Number of nearest neighbors for nearest_neighbors graph building.
    If None, n_neighbors will be set to max(n_samples/10, 1).

  **verbose**
  : Sets logging level. It must be one of `cuml.common.logger.level_*`.
    See [Verbosity Levels](../../cuml/index.html.md#verbosity-levels) for more info.

  **output_type**
  : Return results and set estimator attributes to the indicated output
    type. If None, the output type set at the module level
    (`cuml.global_settings.output_type`) will be used. See
    [Output Data Type Configuration](../../cuml/index.html.md#output-data-type-configuration) for more info.
* **Attributes:**
  **embedding_**
  : Spectral embedding of the training matrix.

  **n_neighbors_**
  : Number of nearest neighbors effectively used.

### Methods

| [`fit`](#cuml.manifold.SpectralEmbedding.fit)(self, X[, y])           | Fit the model from data in X.                 |
|------------------------------------------------------------------------------|-----------------------------------------------|
| [`fit_transform`](#cuml.manifold.SpectralEmbedding.fit_transform)(self, X[, y]) | Fit the model from data in X and transform X. |

### Notes

Spectral Embedding (Laplacian Eigenmaps) is most useful when the graph
has one connected component. If there graph has many components, the first
few eigenvectors will simply uncover the connected components of the graph.

### Examples

```pycon
>>> import cupy as cp
>>> from cuml.manifold import SpectralEmbedding
>>> X = cp.random.rand(100, 20, dtype=cp.float32)
>>> embedding = SpectralEmbedding(n_components=2, random_state=42)
>>> X_transformed = embedding.fit_transform(X)
>>> X_transformed.shape
(100, 2)
```

<!-- !! processed by numpydoc !! -->

#### as_sklearn()[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/interop.py#L206)

Convert this estimator into an equivalent scikit-learn (or scikit-learn
extension) estimator.

* **Returns:**
  sklearn.base.BaseEstimator
  : A scikit-learn compatible estimator instance that mirrors the trained
    state of the current estimator.

<!-- !! processed by numpydoc !! -->

#### fit(self, X, y=None) → 'SpectralEmbedding'[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/manifold/spectral_embedding.pyx#L213)

Fit the model from data in X.

* **Parameters:**
  **X**
  : Training vector, where `n_samples` is the number of samples
    and `n_features` is the number of features. If affinity is
    ‘precomputed’, X is the affinity matrix. Supported formats for
    precomputed affinity: scipy sparse (CSR, CSC, COO), cupy sparse
    (CSR, CSC, COO), dense numpy arrays, or dense cupy arrays.

  **y**
  : Not used, present for API consistency by convention.
* **Returns:**
  **self**
  : Returns the instance itself.

<!-- !! processed by numpydoc !! -->

#### fit_transform(self, X, y=None)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/manifold/spectral_embedding.pyx#L189)

Fit the model from data in X and transform X.

* **Parameters:**
  **X**
  : Training vector, where `n_samples` is the number of samples
    and `n_features` is the number of features. If affinity is
    ‘precomputed’, X is the affinity matrix. Supported formats for
    precomputed affinity: scipy sparse (CSR, CSC, COO), cupy sparse
    (CSR, CSC, COO), dense numpy arrays, or dense cupy arrays.

  **y**
  : Not used, present for API consistency by convention.
* **Returns:**
  **X_new**
  : Spectral embedding of the training matrix.

<!-- !! processed by numpydoc !! -->

#### *classmethod* from_sklearn(model)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/interop.py#L222)

Create a cuml estimator from a scikit-learn estimator.

* **Parameters:**
  **model**
  : A compatible scikit-learn (or scikit-learn extension) estimator.
* **Returns:**
  cls
  : A new instance of this cuml estimator class that mirrors the
    state of the input estimator.

### Notes

`output_type` of the estimator is set to “numpy” by default, as these
cannot be inferred from training arguments. If something different is
required, then please use cuml’s output_type configuration utilities.

<!-- !! processed by numpydoc !! -->

#### get_feature_names_out(input_features=None)

Get output feature names for transformation.

The feature names out will prefixed by the lowercased class name. For
example, if the transformer outputs 3 features, then the feature names
out are: `["class_name0", "class_name1", "class_name2"]`.

* **Parameters:**
  **input_features**
  : Only used to validate feature names with the names seen in [`fit`](#cuml.manifold.SpectralEmbedding.fit).
* **Returns:**
  **feature_names_out**
  : Transformed feature names.

<!-- !! processed by numpydoc !! -->

#### get_params(deep=True)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L191)

Returns a dict of all params owned by this class. If the child class
has appropriately overridden the `_get_param_names` method and does not
need anything other than what is there in this method, then it doesn’t
have to override this method

<!-- !! processed by numpydoc !! -->

#### set_params(\*\*params)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L200)

Accepts a dict of params and updates the corresponding ones owned by
this class. If the child class has appropriately overridden the
`_get_param_names` method and does not need anything other than what is,
there in this method, then it doesn’t have to override this method

<!-- !! processed by numpydoc !! -->
