Skip to content

Estimator base

Shared by every estimator. You would only reach for this directly to type-annotate something that takes any of them.

BaseEmbedding

Common fit plumbing for every embedding.

Subclasses supply an __init__ that stores its arguments verbatim, a _params hook returning the payload the core reads, and the core function itself.

embedding_ property

embedding_: ndarray

The fitted embedding, (n_samples, n_components).

Raises:

Type Description
NotFittedError

If fit has not run.

get_params

get_params(deep: bool = True) -> dict[str, Any]

Parameters this estimator was constructed with.

Parameters:

Name Type Description Default
deep bool

Accepted for scikit-learn compatibility; these estimators hold no nested estimators, so it makes no difference. The parameter groups are frozen dataclasses, not estimators, and come back whole.

True

Returns:

Type Description
dict[str, Any]

Constructor parameters, keyed by name.

set_params

set_params(**params: Any) -> BaseEmbedding

Set constructor parameters, discarding any fitted embedding.

Returns:

Type Description
BaseEmbedding

self.

Raises:

Type Description
ValueError

If a name is not a parameter of this estimator.

fit

fit(
    X: Any,
    y: Any = None,
    *,
    knn_indices: Any = None,
    knn_distances: Any = None,
) -> BaseEmbedding

Embed X.

Parameters:

Name Type Description Default
X Any

Array-like of shape (n_samples, n_features). float32 and float64 are used as-is; other numeric types are promoted to float64. The element type picks the precision the whole pipeline runs in.

required
y Any

Ignored, present for scikit-learn pipeline compatibility.

None
knn_indices Any

Optional (n_samples, k) precomputed neighbour indices, excluding self. Skips the neighbour search, which on anything large is most of the runtime. See manifolds_rs.knn_graph.

None
knn_distances Any

Distances matching knn_indices, as true distances in the same metric. knn_graph returns exactly that.

None

Returns:

Type Description
BaseEmbedding

self.

Raises:

Type Description
ValueError

If only one of the two kNN arrays was given.

fit_transform

fit_transform(
    X: Any,
    y: Any = None,
    *,
    knn_indices: Any = None,
    knn_distances: Any = None,
) -> ndarray

Embed X and return the result.

Parameters:

Name Type Description Default
X Any

Array-like of shape (n_samples, n_features).

required
y Any

Ignored, present for scikit-learn pipeline compatibility.

None
knn_indices Any

Optional precomputed neighbour indices. See fit.

None
knn_distances Any

Distances matching knn_indices.

None

Returns:

Type Description
ndarray

The embedding, (n_samples, n_components), in the same float type

ndarray

as the input.

transform

transform(X: Any) -> ndarray

Not available: none of these algorithms projects new points.

Raises:

Type Description
NotImplementedError

Always. Embedding new data means refitting on the whole set, which changes the existing coordinates too.

NotFittedError

Bases: ValueError, AttributeError

Raised when embedding_ is read before fit.

Inherits from both ValueError and AttributeError to match sklearn.exceptions.NotFittedError, so code catching either still works.

ManifoldsRsError

Bases: Exception

ConvergenceError