Note

This page is a reference documentation. It only explains the class signature, and not how to use it. Please refer to the What you really need to know section for the big picture.

julearn.transformers.confound_remover.ConfoundRemover#

class julearn.transformers.confound_remover.ConfoundRemover(apply_to='continuous', model_confound=None, confounds='confound', threshold=None, keep_confounds=False, row_select_col_type=None, row_select_vals=None)#

Remove confounds from specific features.

Transformer which removes the confounds from specific features by subtracting the predicted features given the confounds from the actual features.

Parameters:
apply_toColumnTypesLike, optional

From which feature types (‘X_types’) to remove confounds. If not specified, ‘apply_to’ defaults to ‘continuous’. To apply confound removal to all features, you can use the ‘*’ regular expression syntax.

model_confoundModelLike, optional

Sklearn compatible model used to predict specified features independently using the confounds as features. The predictions of these models are then subtracted from each of the specified features, defaults to LinearRegression().

confoundsstr or list of str, optional

The name of the ‘confounds’ type(s), i.e. which column type(s) represents the confounds. By default this is set to ‘confounds’.

thresholdfloat, optional

All residual values after confound removal which fall under the threshold will be set to 0. None (default) means that no threshold will be applied.

keep_confoundsbool, optional

Whether you want to return the confound together with the confound removed features, default is False.

row_select_col_typestr or list of str or set of str or ColumnTypes

The column types needed to select rows (default is None)

row_select_valsstr, int, bool or list of str, int, bool

The value(s) which should be selected in the row_select_col_type to select the rows used for training (default is None)

__init__(apply_to='continuous', model_confound=None, confounds='confound', threshold=None, keep_confounds=False, row_select_col_type=None, row_select_vals=None)#
transform(X)#

Remove confounds from data.

Parameters:
Xpd.DataFrame

Data to be deconfounded.

Returns:
outpd.DataFrame

Deconfounded data.

get_support(indices=False)#

Get the support mask.

Parameters:
indicesbool

If true, return indices.

Returns:
support_masknumpy.array

The support mask

get_feature_names_out(input_features=None)#

Get names of features to be returned.

Parameters:
input_featuresNone

Parameter to ensure scikit-learn compatibility. It is not used by the method.

Returns:
list

Names of features to be kept in the output pd.DataFrame.

filter_columns(X)#

Get the apply_to columns of a pandas DataFrame.

Parameters:
Xpd.DataFrame

The DataFrame to filter.

Returns:
pd.DataFrame

The DataFrame with only the apply_to columns.

fit(X, y=None, **fit_params)#

Fit the model.

This method will fit the model using only the columns selected by apply_to.

Parameters:
Xpd.DataFrame

The data to fit the model on.

yDataLike, optional

The target data (default is None).

**fit_paramsAny

Additional parameters to pass to the model’s fit method.

Returns:
JuTransformer

The fitted model.

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_apply_to()#

Get the column types the estimator applies to.

Returns:
ColumnTypes

The column types the estimator applies to.

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_needed_types()#

Get the column types needed by the estimator.

Returns:
ColumnTypes

The column types needed by the estimator.

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_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”, “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

New 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.