API

Some simple/useful examples are available at Usage, using the following API:

Methods covered:

  • Residualize

  • Augment

  • DummyDeconfounding

Library exceptions:

  • ConfoundsException


class base.Residualize(model='linear')[source]

Bases: base.BaseDeconfound

Deconfounding estimator class that residualizes the input features by subtracting the contributions from the confound variables

Example methods: Linear, Kernel Ridge, Gaussian Process Regression etc

fit(self, X, y=None)[source]

Fits the residualizing model (estimates the contributions of confounding variables (y) to the given [training] feature set X. Variable names X, y had to be used to pass sklearn conventions. y here refers to the confound variables, and NOT the target. See examples in docs!

Parameters
X{array-like, sparse matrix}, shape (n_samples, n_features)

The training input samples.

yndarray

Array of covariates, shape (n_samples, n_covariates) This does not refer to target as is typical in scikit-learn.

Returns
selfobject

Returns self

transform(self, X, y=None)[source]

Transforms the given feature set by residualizing the [test] features by subtracting the contributions of their confounding variables.

Variable names X, y had to be used to pass scikit-learn conventions. y here refers to the confound variables for the [test] to be transformed, and NOT their target values. See examples in docs!

Parameters
X{array-like, sparse matrix}, shape (n_samples, n_features)

The training input samples.

yndarray

Array of covariates, shape (n_samples, n_covariates) This does not refer to target as is typical in scikit-learn.

Returns
selfobject

Returns self

class base.Augment[source]

Bases: base.BaseDeconfound

Deconfounding estimator class that simply augments/concatenates the confounding variables to input features prior to prediction.

fit(self, X, y=None)[source]

Learns the dimensionality of confounding variables to be augmented.

Variable names X, y had to be used to pass sklearn conventions. y here refers to the confound variables, and NOT the target. See examples in docs!

Parameters
X{array-like, sparse matrix}, shape (n_samples, n_features)

The training input samples.

yndarray

Array of covariates, shape (n_samples, n_covariates) This does not refer to target as is typical in scikit-learn.

Returns
selfobject

Returns self

transform(self, X, y=None)[source]

Transforms the given feature set by augmenting the confounding variables.

Variable names X, y had to be used to pass sklearn conventions. y here refers to the confound variables for the [test] to be transformed, and NOT their target values. See examples in docs!

Parameters
X{array-like, sparse matrix}, shape (n_samples, n_features)

The training input samples.

yndarray

Array of covariates, shape (n_samples, n_covariates) This does not refer to target as is typical in scikit-learn.

Returns
selfobject

Returns self

class base.DummyDeconfounding[source]

Bases: base.BaseDeconfound

A do-nothing dummy method, to serve as a reference for methodological comparisons

fit(self, X, y=None)[source]

A do-nothing fit method.

Parameters
X{array-like, sparse matrix}, shape (n_samples, n_features)

The training input samples.

yndarray

Array of covariates, shape (n_samples, n_covariates)

Returns
selfobject

Returns self.

transform(self, X, y=None)[source]

A do-nothing transform method.

Parameters
X{array-like, sparse-matrix}, shape (n_samples, n_features)

The input samples.

yndarray

Array of covariates, shape (n_samples, n_covariates)

Returns
X_transformedarray, shape (n_samples, n_features)

Same as the input X.

exception base.ConfoundsException[source]

Bases: BaseException

Custom exception to indicate confounds-library specific issues.