当前位置: 首页>>代码示例>>Python>>正文


Python WardAgglomeration.inverse_transform方法代码示例

本文整理汇总了Python中sklearn.cluster.WardAgglomeration.inverse_transform方法的典型用法代码示例。如果您正苦于以下问题:Python WardAgglomeration.inverse_transform方法的具体用法?Python WardAgglomeration.inverse_transform怎么用?Python WardAgglomeration.inverse_transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.cluster.WardAgglomeration的用法示例。


在下文中一共展示了WardAgglomeration.inverse_transform方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_ward_agglomeration

# 需要导入模块: from sklearn.cluster import WardAgglomeration [as 别名]
# 或者: from sklearn.cluster.WardAgglomeration import inverse_transform [as 别名]
def test_ward_agglomeration():
    """
    Check that we obtain the correct solution in a simplistic case
    """
    rnd = np.random.RandomState(0)
    mask = np.ones([10, 10], dtype=np.bool)
    X = rnd.randn(50, 100)
    connectivity = grid_to_graph(*mask.shape)
    ward = WardAgglomeration(n_clusters=5, connectivity=connectivity)
    ward.fit(X)
    assert_true(np.size(np.unique(ward.labels_)) == 5)

    Xred = ward.transform(X)
    assert_true(Xred.shape[1] == 5)
    Xfull = ward.inverse_transform(Xred)
    assert_true(np.unique(Xfull[0]).size == 5)
开发者ID:AlexLerman,项目名称:scikit-learn,代码行数:18,代码来源:test_hierarchical.py

示例2: representation

# 需要导入模块: from sklearn.cluster import WardAgglomeration [as 别名]
# 或者: from sklearn.cluster.WardAgglomeration import inverse_transform [as 别名]
first_epi = nifti_masker.inverse_transform(fmri_masked[0]).get_data()
first_epi = np.ma.masked_array(first_epi, first_epi == 0)
# Outside the mask: a uniform value, smaller than inside the mask
first_epi[np.logical_not(mask)] = 0.9 * first_epi[mask].min()
vmax = first_epi[..., 20].max()
vmin = first_epi[..., 20].min()
pl.imshow(np.rot90(first_epi[..., 20]),
          interpolation='nearest', cmap=pl.cm.spectral, vmin=vmin, vmax=vmax)
pl.axis('off')
pl.title('Original (%i voxels)' % fmri_masked.shape[1])

# A reduced data can be create by taking the parcel-level average:
# Note that, as many objects in the scikit-learn, the ward object exposes
# a transform method that modifies input features. Here it reduces their
# dimension
fmri_reduced = ward.transform(fmri_masked)

# Display the corresponding data compressed using the parcellation
fmri_compressed = ward.inverse_transform(fmri_reduced)
compressed = nifti_masker.inverse_transform(
    fmri_compressed[0]).get_data()
compressed = np.ma.masked_equal(compressed, 0)


pl.figure()
pl.imshow(np.rot90(compressed[:, :, 20]),
          interpolation='nearest', cmap=pl.cm.spectral, vmin=vmin, vmax=vmax)
pl.title('Compressed representation (2000 parcels)')
pl.axis('off')
pl.show()
开发者ID:jcketz,项目名称:nilearn,代码行数:32,代码来源:plot_rest_clustering.py

示例3:

# 需要导入模块: from sklearn.cluster import WardAgglomeration [as 别名]
# 或者: from sklearn.cluster.WardAgglomeration import inverse_transform [as 别名]
labels[mask] = ward.labels_

cut = labels[:, :, 20].astype(np.int)
colors = np.random.random(size=(ward.n_clusters + 1, 3))
colors[-1] = 0
pl.axis('off')
pl.imshow(colors[cut], interpolation='nearest')
pl.title('Ward parcellation')

# Display the original data
pl.figure()
first_epi_img = epi_img[..., 0].copy()
first_epi_img[np.logical_not(mask)] = 0
pl.imshow(first_epi_img[..., 20], interpolation='nearest',
           cmap=pl.cm.spectral)
pl.axis('off')
pl.title('Original')

# Display the corresponding data compressed using the parcellation
X_r = ward.transform(epi_masked.T)
X_c = ward.inverse_transform(X_r)
compressed_img = np.zeros(mask.shape)
compressed_img[mask] = X_c[0]

pl.figure()
pl.imshow(compressed_img[:, :, 20], interpolation='nearest',
           cmap=pl.cm.spectral)
pl.title('Compressed representation')
pl.axis('off')
pl.show()
开发者ID:dengemann,项目名称:nisl.github.com,代码行数:32,代码来源:plot_nyu_rest_clustering.py


注:本文中的sklearn.cluster.WardAgglomeration.inverse_transform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。