本文整理汇总了Python中sklearn.covariance.GraphLassoCV方法的典型用法代码示例。如果您正苦于以下问题:Python covariance.GraphLassoCV方法的具体用法?Python covariance.GraphLassoCV怎么用?Python covariance.GraphLassoCV使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.covariance
的用法示例。
在下文中一共展示了covariance.GraphLassoCV方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: subject_connectivity
# 需要导入模块: from sklearn import covariance [as 别名]
# 或者: from sklearn.covariance import GraphLassoCV [as 别名]
def subject_connectivity(timeseries, subject, atlas_name, kind, save=True, save_path=root_folder):
"""
timeseries : timeseries table for subject (timepoints x regions)
subject : the subject short ID
atlas_name : name of the atlas used
kind : the kind of connectivity to be used, e.g. lasso, partial correlation, correlation
save : save the connectivity matrix to a file
save_path : specify path to save the matrix if different from subject folder
returns:
connectivity : connectivity matrix (regions x regions)
"""
print("Estimating %s matrix for subject %s" % (kind, subject))
if kind == 'lasso':
# Graph Lasso estimator
covariance_estimator = GraphLassoCV(verbose=1)
covariance_estimator.fit(timeseries)
connectivity = covariance_estimator.covariance_
print('Covariance matrix has shape {0}.'.format(connectivity.shape))
elif kind in ['tangent', 'partial correlation', 'correlation']:
conn_measure = connectome.ConnectivityMeasure(kind=kind)
connectivity = conn_measure.fit_transform([timeseries])[0]
if save:
subject_file = os.path.join(save_path, subject,
subject + '_' + atlas_name + '_' + kind.replace(' ', '_') + '.mat')
sio.savemat(subject_file, {'connectivity': connectivity})
return connectivity
示例2: group_connectivity
# 需要导入模块: from sklearn import covariance [as 别名]
# 或者: from sklearn.covariance import GraphLassoCV [as 别名]
def group_connectivity(timeseries, subject_list, atlas_name, kind, save=True, save_path=root_folder):
"""
timeseries : list of timeseries tables for subjects (timepoints x regions)
subject_list : the subject short IDs list
atlas_name : name of the atlas used
kind : the kind of connectivity to be used, e.g. lasso, partial correlation, correlation
save : save the connectivity matrix to a file
save_path : specify path to save the matrix if different from subject folder
returns:
connectivity : connectivity matrix (regions x regions)
"""
if kind == 'lasso':
# Graph Lasso estimator
covariance_estimator = GraphLassoCV(verbose=1)
connectivity_matrices = []
for i, ts in enumerate(timeseries):
covariance_estimator.fit(ts)
connectivity = covariance_estimator.covariance_
connectivity_matrices.append(connectivity)
print('Covariance matrix has shape {0}.'.format(connectivity.shape))
elif kind in ['tangent', 'partial correlation', 'correlation']:
conn_measure = connectome.ConnectivityMeasure(kind=kind)
connectivity_matrices = conn_measure.fit_transform(timeseries)
if save:
for i, subject in enumerate(subject_list):
subject_file = os.path.join(save_path, subject_list[i],
subject_list[i] + '_' + atlas_name + '_' + kind.replace(' ', '_') + '.mat')
sio.savemat(subject_file, {'connectivity': connectivity_matrices[i]})
print("Saving connectivity matrix to %s" % subject_file)
return connectivity_matrices
示例3: test_objectmapper
# 需要导入模块: from sklearn import covariance [as 别名]
# 或者: from sklearn.covariance import GraphLassoCV [as 别名]
def test_objectmapper(self):
df = pdml.ModelFrame([])
self.assertIs(df.covariance.EmpiricalCovariance, covariance.EmpiricalCovariance)
self.assertIs(df.covariance.EllipticEnvelope, covariance.EllipticEnvelope)
self.assertIs(df.covariance.GraphLasso, covariance.GraphLasso)
self.assertIs(df.covariance.GraphLassoCV, covariance.GraphLassoCV)
self.assertIs(df.covariance.LedoitWolf, covariance.LedoitWolf)
self.assertIs(df.covariance.MinCovDet, covariance.MinCovDet)
self.assertIs(df.covariance.OAS, covariance.OAS)
self.assertIs(df.covariance.ShrunkCovariance, covariance.ShrunkCovariance)
self.assertIs(df.covariance.shrunk_covariance, covariance.shrunk_covariance)
self.assertIs(df.covariance.graph_lasso, covariance.graph_lasso)