nimare.ml.make_nimare_column_transformer

make_nimare_column_transformer(bunch, *transformers, remainder='drop', sparse_threshold=1.0, n_jobs=None, verbose=False, verbose_feature_names_out=True)[source]

Construct a ColumnTransformer over the blocks of bunch.

make_column_transformer() with the bunch filled in: the column spans of the two blocks, the masker an atlas needs, the column names each transformer is given, and the categories a categorical descriptor code stands for. Everything else is scikit-learn’s, including the shape of transformers and the automatic step names.

For a case this does not cover, write ColumnTransformer out with bunch.voxel_columns and bunch.descriptor_columns, which are ordinary slices.

Parameters:
  • bunch (sklearn.utils.Bunch) – A bunch from to_bunch().

  • *transformers (tuple) –

    (transformer, columns) pairs, as make_column_transformer() takes them.

    columns may be a name, or a list of names, as it may be for a ColumnTransformer reading a frame: "voxels" and "descriptors" name the two blocks, and a descriptor may be named by its own field name. It may equally be anything a ColumnTransformer accepts: a slice, indices, a mask or a callable.

    transformer may be a scikit-learn transformer, "passthrough", "drop", or any atlas MaskerTransformer accepts, which is built against the bunch’s masker.

  • remainder ({"drop", "passthrough"} or estimator, default="drop") – What happens to columns no transformer claims, as in scikit-learn. Claim both blocks under "drop"; say ("drop", "voxels") to drop one on purpose.

  • sparse_threshold (float, default=1.0) – Scikit-learn defaults this to 0.3, which would densify an unreduced voxel block – about 6.5 GB at 902,629 columns – so the default here keeps the result sparse whenever any block is.

  • n_jobs (int, optional) – Passed to ColumnTransformer.

  • verbose (bool, default=False) – Passed to ColumnTransformer.

  • verbose_feature_names_out (bool, default=True) – Passed to ColumnTransformer.

Returns:

Unfitted, with the steps named after their transformers.

Return type:

ColumnTransformer

Raises:

ValueError – If a pair is malformed, if a block name is not one of the bunch’s, if either block would be dropped without being named, or if a coded categorical descriptor would reach a model unencoded.

See also

sklearn.compose.make_column_transformer

The function this follows.

Examples

>>> preprocessor = make_nimare_column_transformer(
...     bunch,
...     (MAKernel(MKDAKernel(r=10), source_masker=bunch.masker), "voxels"),
...     (SimpleImputer(strategy="median"), "descriptors"),
... )

Examples using nimare.ml.make_nimare_column_transformer

Machine learning in NiMARE

Machine learning in NiMARE