nimare.ml.MAKernel

class MAKernel(kernel=None, source_masker=None, cache=False)[source]

Bases: TransformerMixin, BaseEstimator

Convolve peak columns into modeled activation maps.

Columns come in over the whole image grid, as to_bunch() reports them, and go out over the source masker’s voxels. Being a transformer, the kernel and its bandwidth are fitted, cloned and tuned like any other pipeline step. See the machine learning documentation.

Parameters:
  • kernel (KernelTransformer, optional) – The kernel to apply, by default None. An instance or a class. There is no default: the choice is scientific.

  • source_masker (NiftiMasker or img_like, optional) – The masker whose image grid the peak columns span, normally the masker a bunch carries, by default None.

  • cache (bool, default=False) – Whether to keep the maps already convolved, so that folds after the first are served rather than recomputed. The maps are held for the process, not for the transformer, which is what lets a clone reuse them; they grow to the whole feature matrix, and clear_map_cache() releases them.

Variables:
  • kernel (KernelTransformer) – The kernel instance doing the work.

  • mask_img (Nifti1Image) – The mask defining the incoming grid and the outgoing voxels.

  • n_voxels (int) – How many voxel columns the maps have.

See also

nimare.studyset.Studyset.to_bunch

Where the peak columns come from.

Examples

>>> step = MAKernel(MKDAKernel(r=10), source_masker=bunch.masker)

Methods

fit(X[, y])

Resolve the kernel and the space its peaks are in.

fit_transform(X[, y])

Fit to data, then transform it.

get_feature_names_out([input_features])

Return one name per voxel of the maps.

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)

Convolve each row's peaks into its MA map.

fit(X, y=None)[source]

Resolve the kernel and the space its peaks are in.

Parameters:
  • X (array_like or sparse matrix) – Analysis-by-grid-voxel peak counts, used only for their width.

  • y (ignored)

Returns:

The fitted transformer.

Return type:

MAKernel

Raises:

ValueError – If no kernel or no source masker was given, if the columns do not span the masker’s grid, or if the kernel derives its width from per-analysis sample sizes, which a feature matrix cannot carry.

fit_transform(X, y=None, **fit_params)[source]

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:
  • X (array-like of shape (n_samples, n_features)) – Input samples.

  • y (array-like of shape (n_samples,) or (n_samples, n_outputs), default=None) – Target values (None for unsupervised transformations).

  • **fit_params (dict) – Additional fit parameters. Pass only if the estimator accepts additional params in its fit method.

Returns:

X_new – Transformed array.

Return type:

ndarray array of shape (n_samples, n_features_new)

get_feature_names_out(input_features=None)[source]

Return one name per voxel of the maps.

Parameters:

input_features (ignored)

Returns:

One name per output voxel column.

Return type:

numpy.ndarray of str

get_metadata_routing()[source]

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:

routing – A MetadataRequest encapsulating routing information.

Return type:

MetadataRequest

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

set_output(*, transform=None)[source]

Set output container.

Refer to the user guide for more details and 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:

self – Estimator instance.

Return type:

estimator instance

set_params(**params)[source]

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:

**params (dict) – Estimator parameters.

Returns:

self – Estimator instance.

Return type:

estimator instance

transform(X)[source]

Convolve each row’s peaks into its MA map.

Parameters:

X (array_like or sparse matrix) – Analysis-by-grid-voxel peak counts.

Returns:

Analysis-by-voxel MA features, in the source masker’s voxel order.

Return type:

scipy.sparse.csr_matrix

Examples using nimare.ml.MAKernel

Machine learning in NiMARE

Machine learning in NiMARE