archetypes.BiAA#

class archetypes.BiAA(n_archetypes, max_iter=300, tol=0.0001, init='uniform', init_kwargs=None, save_init=False, verbose=False, random_state=None, method='nnls', method_kwargs=None)#

Biarchetype Analysis with Numpy backend.

Parameters:
n_archetypestuple

The number of archetypes to compute.

max_iterint, default=300

Maximum number of iterations of the archetype analysis algorithm for a single run.

tolfloat, default=1e-4

Relative tolerance of two consecutive iterations to declare convergence.

initstr or callable, default=’uniform’

Method used to initialize the archetypes. If a string, it must be one of the following: ‘uniform’, ‘furthest_sum’, ‘furthest_first’ or ‘aa_plus_plus’. See Initialization Methods.

init_kwargsdict, default=None

Additional keyword arguments to pass to the initialization method.

save_initbool, default=False

If True, save the initial coefficients in the attribute B_init_.

method: str, default=’nnls’

The optimization method to use for the archetypes and the coefficients. It must be one of the following: ‘nnls’, ‘pgd’.

method_kwargsdict, default=None

Additional arguments to pass to the optimization method. See Optimization Methods.

verbosebool, default=False

Verbosity mode.

random_stateint, RandomState instance or None, default=None

Determines random number generation of coefficients. Use an int to make the randomness deterministic.

Attributes:
archetypes_np.ndarray of shape (*n_archetypes)

The computed archetypes.

archetypes_init_np.ndarray

The initial archetypes. It is only available if save_init=True.

similarity_degree_list[np.ndarray]

The similarity degree of each sample to each archetype in each dimension. Each array has shape (n_samples, n_archetypes).

archetypes_similarity_degree_list[np.ndarray]

The similarity degree of each archetype to each sample in each dimension. Each array has shape (n_archetypes, n_samples).

labels_list[np.ndarray]

The label of each sample in each dimension. It is the index of the closest archetype. Each array has shape (n_samples,).

loss_list

The loss at each iteration.

Methods

fit(X[, y])

Compute Archetype Analysis.

fit_transform(X[, y])

Fit to data, then transform it.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

set_output(*[, transform])

Set output container.

set_params(**params)

Set the parameters of this estimator.

transform(X)

Transform X to the archetypal space.

References

[1]

“Archetypal Analysis” by Cutler, A. and Breiman, L. (1994).

[2]

“Biarchetype Analysis: Simultaneous Learning of Observations and Features Based on Extremes” by Alcacer, A., Epifanio, I. and Gual-Arnau, X. (2024).

fit(X, y=None, **fit_params)#

Compute Archetype Analysis.

Parameters:
X{array-like, sparse matrix} of shape (n_samples, n_features)

Training instances to compute the archetypes. It must be noted that the data will be converted to C ordering, which will cause a memory copy if the given data is not C-contiguous. If a sparse matrix is passed, a copy will be made if it’s not in CSR format.

yIgnored

Not used, present here for API consistency by convention.

Returns:
selfobject

Fitted estimator.

fit_transform(X, y=None, **fit_params)#

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters:
Xarray-like of shape (n_samples, n_features)

Input samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).

**fit_paramsdict

Additional fit parameters.

Returns:
X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

get_metadata_routing()#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)#

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

set_output(*, transform=None)#

Set output container.

See Introducing the set_output API for an example on how to use the API.

Parameters:
transform{“default”, “pandas”, “polars”}, default=None

Configure output of transform and fit_transform.

  • “default”: Default output format of a transformer

  • “pandas”: DataFrame output

  • “polars”: Polars output

  • None: Transform configuration is unchanged

Added in version 1.4: “polars” option was added.

Returns:
selfestimator instance

Estimator instance.

set_params(**params)#

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

transform(X)#

Transform X to the archetypal space.

In the new space, each dimension is the distance to the archetypes. Note that even if X is sparse, the array returned by transform will typically be dense.

Parameters:
X{array-like, sparse matrix} of shape (n_samples, n_features)

New data to transform.

Returns:
X_newndarray of shape (n_samples, n_archetypes)

X transformed in the new space.