Note
This page is a reference documentation. It only explains the class signature, and not how to use it. Please refer to the user guide for the big picture.
7.1.1. nilearn.connectome.ConnectivityMeasure¶

class
nilearn.connectome.
ConnectivityMeasure
(cov_estimator=LedoitWolf(assume_centered=False, block_size=1000, store_precision=False), kind='covariance', vectorize=False, discard_diagonal=False)¶ A class that computes different kinds of functional connectivity matrices.
New in version 0.2.
 Parameters
 cov_estimatorestimator object, optional.
The covariance estimator. By default the LedoitWolf estimator is used. This implies that correlations are slightly shrunk towards zero compared to a maximumlikelihood estimate
 kind{“correlation”, “partial correlation”, “tangent”, “covariance”, “precision”}, optional
The matrix kind.
 vectorizebool, optional
If True, connectivity matrices are reshaped into 1D arrays and only their flattened lower triangular parts are returned.
 discard_diagonalbool, optional
If True, vectorized connectivity coefficients do not include the matrices diagonal elements. Used only when vectorize is set to True.
References
For the use of “tangent”, see the paper: G. Varoquaux et al. “Detection of brain functionalconnectivity difference in poststroke patients using grouplevel covariance modeling, MICCAI 2010.
 Attributes
 `cov_estimator_`estimator object
A new covariance estimator with the same parameters as cov_estimator.
 `mean_`numpy.ndarray
The mean connectivity matrix across subjects. For ‘tangent’ kind, it is the geometric mean of covariances (a group covariance matrix that captures information from both correlation and partial correlation matrices). For other values for “kind”, it is the mean of the corresponding matrices
 `whitening_`numpy.ndarray
The inverted squarerooted geometric mean of the covariance matrices.

__init__
(self, cov_estimator=LedoitWolf(assume_centered=False, block_size=1000, store_precision=False), kind='covariance', vectorize=False, discard_diagonal=False)¶ Initialize self. See help(type(self)) for accurate signature.

fit
(self, X, y=None)¶ Fit the covariance estimator to the given time series for each subject.
 Parameters
 Xlist of numpy.ndarray, shape for each (n_samples, n_features)
The input subjects time series. The number of samples may differ from one subject to another.
 Returns
 selfConnectivityMatrix instance
The object itself. Useful for chaining operations.

fit_transform
(self, X, y=None)¶ 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
 Xnumpy array of shape [n_samples, n_features]
Training set.
 ynumpy array of shape [n_samples]
Target values.
 **fit_paramsdict
Additional fit parameters.
 Returns
 X_newnumpy array of shape [n_samples, n_features_new]
Transformed array.

get_params
(self, 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
 paramsmapping of string to any
Parameter names mapped to their values.

inverse_transform
(self, connectivities, diagonal=None)¶ Returns connectivity matrices from connectivities, vectorized or not.
If kind is ‘tangent’, the covariance matrices are reconstructed.
 Parameters
 connectivitieslist of n_subjects numpy.ndarray with shapes (n_features, n_features) or (n_features * (n_features + 1) / 2,)
or ((n_features  1) * n_features / 2,) Connectivities of each subject, vectorized or not.
 diagonalnumpy.ndarray, shape (n_subjects, n_features), optional
The diagonals of the connectivity matrices.
 Returns
 outputnumpy.ndarray, shape (n_subjects, n_features, n_features)
The corresponding connectivity matrices. If kind is ‘correlation’/ ‘partial correlation’, the correlation/partial correlation matrices are returned. If kind is ‘tangent’, the covariance matrices are reconstructed.

set_params
(self, **params)¶ Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as pipelines). 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
 selfobject
Estimator instance.

transform
(self, X)¶ Apply transform to covariances matrices to get the connectivity matrices for the chosen kind.
 Parameters
 Xlist of n_subjects numpy.ndarray with shapes (n_samples, n_features)
The input subjects time series. The number of samples may differ from one subject to another.
 Returns
 outputnumpy.ndarray, shape (n_subjects, n_features, n_features) or (n_subjects, n_features * (n_features + 1) / 2) if vectorize is set to True.
The transformed individual connectivities, as matrices or vectors.