Note

This page is a reference documentation. It only explains the class signature, and not how to use it. Please refer to the user guide for the big picture.

nilearn.regions.ReNA

class nilearn.regions.ReNA(mask_img, n_clusters=2, scaling=False, n_iter=10, threshold=1e-07, memory=None, memory_level=1, verbose=0)[source]

Recursive Neighbor Agglomeration (ReNA).

Recursively merges the pair of clusters according to 1-nearest neighbors criterion. See Hoyos-Idrobo et al.[1].

Parameters:
mask_imgNiimg-like object

Object used for masking the data.

n_clustersint, default=2

The number of clusters to find.

scalingbool, default=False

If scaling is True, each cluster is scaled by the square root of its size, preserving the l2-norm of the image.

n_iterint, default=10

Number of iterations of the recursive neighbor agglomeration.

thresholdfloat in the open interval (0., 1.), default=1e-7

Threshold used to handle eccentricities.

memoryNone, instance of joblib.Memory, str, or pathlib.Path

Used to cache the masking process. By default, no caching is done. If a str is given, it is the path to the caching directory.

memory_levelint, default=1

Rough estimator of the amount of memory used by caching. Higher value means more memory for caching. Zero means no caching.

verboseint, default=0

Verbosity level (0 means no message).

Attributes:
labels_numpy.ndarray, shape = [n_features]

Cluster labels for each feature.

n_clusters_int

Number of clusters.

sizes_numpy.ndarray, shape = [n_features]

It contains the size of each cluster.

References

__init__(mask_img, n_clusters=2, scaling=False, n_iter=10, threshold=1e-07, memory=None, memory_level=1, verbose=0)[source]
fit(X, y=None)[source]

Compute clustering of the data.

Parameters:
Xnumpy.ndarray, shape = [n_samples, n_features]

Training data.

yIgnored
Returns:
selfReNA object
transform(X, y=None)[source]

Apply clustering, reduce the dimensionality of the data.

Parameters:
Xnumpy.ndarray, shape = [n_samples, n_features]

Data to transform with the fitted clustering.

Returns:
X_rednumpy.ndarray, shape = [n_samples, n_clusters]

Data reduced with agglomerated signal for each cluster.

inverse_transform(X_red)[source]

Send the reduced 2D data matrix back to the original feature space (voxels).

Parameters:
X_rednumpy.ndarray, shape = [n_samples, n_clusters]

Data reduced with agglomerated signal for each cluster.

Returns:
X_invnumpy.ndarray, shape = [n_samples, n_features]

Data reduced expanded to the original feature space.

fit_predict(X, y=None, **kwargs)

Perform clustering on X and returns cluster labels.

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

Input data.

yIgnored

Not used, present for API consistency by convention.

**kwargsdict

Arguments to be passed to fit.

Added in version 1.4.

Returns:
labelsndarray of shape (n_samples,), dtype=np.int64

Cluster labels.

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_inverse_transform_request(*, X_red='$UNCHANGED$')

Request metadata passed to the inverse_transform method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to inverse_transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to inverse_transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
X_redstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for X_red parameter in inverse_transform.

Returns:
selfobject

The updated object.

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”}, 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.