mojolearn.Isomap#
- class mojolearn.Isomap(*, n_neighbors=5, radius=None, n_components=2, eigen_solver='auto', tol=0, max_iter=None, path_method='auto', neighbors_algorithm='auto', n_jobs=None, metric='minkowski', p=2, metric_params=None, numeric_mode=None)[source]#
Bases:
_BaseIsomap embedding: kernel PCA on geodesic distances.
Follows scikit-learn’s
Isomap: builds a nearest-neighbor (or radius) graph, computes shortest-path distances on it, and embeds the centered kernel-0.5 * D**2by its top eigenvectors. If the graph has more than one connected component, a warning is issued and the components are joined. Shortest paths always use Dijkstra’s algorithm, and the eigenproblem is always solved exactly.- Parameters:
n_neighbors (int or None, default 5) – Neighbors per point. Set to None to use
radiusinstead.radius (float or None, default None) – Connect every point within this distance (inclusive). Only one of
n_neighborsandradiusmay be set.n_components (int, default 2) – Embedding dimension.
eigen_solver ({“auto”, “dense”}, default “auto”) – Both solve exactly.
"arpack"raises NotImplementedError.tol (ignored)
max_iter (ignored)
path_method ({“auto”, “FW”, “D”}, default “auto”) – Accepted for scikit-learn compatibility; every value runs Dijkstra.
neighbors_algorithm (ignored)
n_jobs (ignored)
metric (str, default “minkowski”) – Distance metric:
"euclidean","l2","minkowski"(withp),"manhattan"("cityblock","l1"),"chebyshev"("infinity") or"cosine"; a callable or any other name raises NotImplementedError.p (float, default 2) – Minkowski power (must be positive).
metric_params (dict or None, default None) – Only
{"p": ...}is supported; other keys raise NotImplementedError.numeric_mode ({“identical”, “fast”} or None, default None) – Numeric mode for this estimator. None uses the package default (
"identical"unless changed)."identical"gives the same bits on NVIDIA and AMD GPUs;"fast"applies on Apple GPUs.
- Variables:
- Raises:
ValueError – If both or neither of
n_neighborsandradiusare set,radiusis negative, orpath_methodoreigen_solveris unknown.
Examples
>>> import numpy as np, mojolearn >>> X = np.random.default_rng(0).random((500, 8), dtype=np.float32) >>> Y = mojolearn.Isomap(n_neighbors=10, n_components=2).fit_transform(X)
- __init__(*, n_neighbors=5, radius=None, n_components=2, eigen_solver='auto', tol=0, max_iter=None, path_method='auto', neighbors_algorithm='auto', n_jobs=None, metric='minkowski', p=2, metric_params=None, numeric_mode=None)[source]#
Methods
fit(X[, y])Compute the embedding of X.
fit_transform(X[, y])Fit the model and return
embedding_.get_params([deep])Return this estimator's constructor parameters.
Return the reconstruction error of the embedding.
set_params(**params)Set constructor parameters by keyword.
transform(X)Embed new points.
- fit(X, y=None)[source]#
Compute the embedding of X.
- Parameters:
X (array-like of shape (n_samples, n_features))
y (ignored)
- Returns:
self
- fit_transform(X, y=None)[source]#
Fit the model and return
embedding_.- Parameters:
X (array-like of shape (n_samples, n_features))
y (ignored)
- Returns:
ndarray of shape (n_samples, n_components), float32
- transform(X)[source]#
Embed new points.
Each query’s geodesic distance to the training points goes through its nearest training neighbors (or, with
radius, every training point within the radius), then is projected as in kernel PCA.- Parameters:
X (array-like of shape (n_queries, n_features))
- Returns:
ndarray of shape (n_queries, n_components), float32
- Raises:
ValueError – With
radius, if a query has no training point within it.