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.

Parameters:

Name Type Description Default
**params Any

Constructor arguments to replace, by name.

{}

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 pipeline runs in, apart from the neighbour search, which is float32 on every backend bar "exhaustive".

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
TypeError

If X or the kNN arrays do not hold numbers.

ValueError

If X or the kNN arrays have the wrong shape or hold non-finite values, if only one of the two kNN arrays was given, or if verbose is not 0, 1 or 2.

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 float type the

ndarray

pipeline ran in. See fit.

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