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 oftransformersand the automatic step names.For a case this does not cover, write
ColumnTransformerout withbunch.voxel_columnsandbunch.descriptor_columns, which are ordinary slices.- Parameters:
bunch (
sklearn.utils.Bunch) – A bunch fromto_bunch().*transformers (
tuple) –(transformer, columns)pairs, asmake_column_transformer()takes them.columnsmay 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 aColumnTransformeraccepts: a slice, indices, a mask or a callable.transformermay be a scikit-learn transformer,"passthrough","drop", or any atlasMaskerTransformeraccepts, 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 toColumnTransformer.verbose (
bool, default=False) – Passed toColumnTransformer.verbose_feature_names_out (
bool, default=True) – Passed toColumnTransformer.
- Returns:
Unfitted, with the steps named after their transformers.
- Return type:
- 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_transformerThe function this follows.
Examples
>>> preprocessor = make_nimare_column_transformer( ... bunch, ... (MAKernel(MKDAKernel(r=10), source_masker=bunch.masker), "voxels"), ... (SimpleImputer(strategy="median"), "descriptors"), ... )