nimare.ml.MAKernel
- class MAKernel(kernel=None, source_masker=None, cache=False)[source]
Bases:
TransformerMixin,BaseEstimatorConvolve 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 (
NiftiMaskeror img_like, optional) – The masker whose image grid the peak columns span, normally themaskera 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, andclear_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_bunchWhere 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 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:
- 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
fitmethod.
- 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.ndarrayofstr
- get_metadata_routing()[source]
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing – A
MetadataRequestencapsulating routing information.- Return type:
MetadataRequest
- 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
transformandfit_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