milia.represent.reduce#
Dimensionality reduction by name, and choosing how many components to keep.
Module Attributes
Functions
|
How many components to keep from an ordered explained-variance spectrum. |
|
Zhu and Ghodsi (2006) profile-likelihood change point of an ordered spectrum. |
|
PCA truncated at the number of components |
|
Two-dimensional projection for plotting. |
|
An unfitted dimensionality reducer by name. |
- milia.represent.reduce.REDUCERS = ('none', 'pca', 'kernelpca', 'tsne', 'umap', 'pacmap')#
Reducer names accepted by
reducer().
- milia.represent.reduce.likelihood(values)#
Zhu and Ghodsi (2006) profile-likelihood change point of an ordered spectrum.
The leading
qvalues and the rest are modelled as two Gaussian samples with a shared variance; theqmaximising the profile log-likelihood separates signal from noise, with no threshold to choose.- Parameters:
values (
ArrayLike) – Descending eigenvalues or explained-variance ratios, at least 3.- Return type:
- Returns:
(q, scores)– the number of components to keep and the log-likelihood at every candidateq = 1, ..., p - 1.- Raises:
ValueError – If fewer than 3 values are given.
Examples
>>> likelihood([10.0, 9.0, 8.5, 0.3, 0.2, 0.1])[0] 3
- milia.represent.reduce.components(ratios, method='likelihood', threshold=0.9)#
How many components to keep from an ordered explained-variance spectrum.
- Parameters:
ratios (
ArrayLike) – Descending explained-variance ratios (or eigenvalues).method (
Literal['likelihood','variance']) –"variance"keeps the fewest components whose cumulative share reachesthreshold;"likelihood"finds the profile likelihood change point (seelikelihood()).threshold (
float) – Cumulative share formethod="variance".
- Return type:
- Returns:
Number of components, at least 1.
- Raises:
ValueError – If
ratiosis empty ormethodis unknown.
Examples
>>> ratios = [0.5, 0.2, 0.1, 0.08, 0.05, 0.04, 0.03] >>> components(ratios, "variance", threshold=0.75), components(ratios, "likelihood") (3, 1)
- milia.represent.reduce.pca(X, method='variance', threshold=0.9, random_state=0)#
PCA truncated at the number of components
components()chooses.- Parameters:
X (
ArrayLike) – Data, shape(n_samples, n_features).method (
Literal['likelihood','variance']) –"variance"or"likelihood"(seecomponents()).threshold (
float) – Cumulative share for"variance".random_state (
int) – Seed of the PCA solver.
- Return type:
- Returns:
(embedding, n)– the reduced data and the number of components kept.
Examples
>>> X = np.random.default_rng(0).normal(size=(50, 4)) @ np.diag([10.0, 1.0, 0.1, 0.1]) >>> embedding, n = pca(X, threshold=0.9) >>> embedding.shape, n ((50, 1), 1)
- milia.represent.reduce.reducer(name, n_components=2, random_state=0, **params)#
An unfitted dimensionality reducer by name.
- Parameters:
- Return type:
- Returns:
A scikit-learn-compatible reducer, or
Nonefor"none". t-SNE switches to the exact method above three components.- Raises:
ValueError – If the name is unknown.
MissingExtraError – For UMAP or PaCMAP without the
tuningextra.
Examples
>>> type(reducer("pca", 3)).__name__, reducer("tsne", 4).method ('PCA', 'exact')
- milia.represent.reduce.project(X, method='pacmap', random_state=0, **params)#
Two-dimensional projection for plotting.
- Parameters:
- Return type:
- Returns:
Coordinates, shape
(n_samples, 2).
Examples
>>> project(np.random.default_rng(0).normal(size=(20, 5)), "pca").shape (20, 2)