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.CBPM#

class julearn.transformers.CBPM(significance_threshold=0.05, corr_method=<function pearsonr>, agg_method=<function sum>, corr_sign='posneg', n_jobs=None, verbose=0)#

Transformer for connectome-based predictive modeling.

It aggregates all features significantly correlated to the target. The significant negative and positive correlations are aggregateed separately and non-significant ones are dropped.

The user can choose to use negative, positive or both correlations. In case that there are no significant correlations and the mean of the target will be returned as the only feature.

This transformer implements the procedure described in [1].

Parameters:
significance_thresholdfloat, default=0.05

Threshold of p value.

corr_methodcallable, default=scipy.stats.pearsonr

Callable which can be used to create tuple of arrays: (correlations, p values). Input has to be X, y.

agg_methodcallable, default=np.sum

Callable to aggregate the features. Has to follow np convention using axis.

corr_signstr , default=’posneg’

Which correlations should be used: Options are:

  • pos: use positive correlations only

  • neg: use negative correlations only

  • posneg: use all correlations

In case you use posneg and there are only pos or neg this will be used instead. The actually used correlation_values can be found in the attribute: used_corr_sign_

n_jobsint, default=None

How many jobs should run in parallel to compute the correlations of each feature to the target. This parameter follows joblib and scikit-learn standards.

verboseint, default=0

How verbose should the log of the parallel computing be. This parameter follows joblib and scikit-learn standards.

References

[1]

Shen, X., Finn, E., Scheinost, D. et al. Using connectome-based predictive modeling to predict individual behavior from brain connectivity. Nat Protoc 12, 506-518 (2017). https://doi.org/10.1038/nprot.2016.178

Attributes:
y_mean_np.array

Contains the mean of the target, to be used for the transformation in case that there are no significant correlations.

used_corr_sign_str

This will show you whether pos, neg or posneg was applied.

X_y_correlations_tuple(np.array, np.array)

Output of the corr_method applied to the target and the features.

significant_mask_np.array of bools

Array of bools showing which of the original features had a significant correlation.

pos_mask_np.array of bools

Array of bools showing which of the original features had a positive correlation.

pos_significant_mask_np.array of bools

Array of bools showing which of the original features had a significant positive correlation.

neg_significant_mask_np.array of bools

Array of bools showing which of the original features had a significant negative correlation.

used_significant_mask_np.array of bools

Array of bools showing which of the original features will be used by this transformer.

__init__(significance_threshold=0.05, corr_method=<function pearsonr>, agg_method=<function sum>, corr_sign='posneg', n_jobs=None, verbose=0)#
fit(X, y)#

Fit the transformer.

Compute the correlations of each feature to the target, threhsold and create the respective masks.

Parameters:
Xnp.array

Input features.

ynp.array

Target.

Returns:
selfCBPM

The fitted transformer.

transform(X)#

Transform the data.

Replace each of the features that had a significant correlation on the training data with the mean of the features (mean is computed per sample).

Parameters:
Xnp.array

Input features.

Returns:
np.array

The transformed features.

aggregate(X, mask)#

Aggregate.

get_feature_names_out(input_features=None)#

Get output feature names.

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_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_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”}, 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.