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


Python SpectralEmbedding.fit_transform方法代码示例

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


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

示例1: test_spectral_embedding_two_components

# 需要导入模块: from sklearn.manifold.spectral_embedding_ import SpectralEmbedding [as 别名]
# 或者: from sklearn.manifold.spectral_embedding_.SpectralEmbedding import fit_transform [as 别名]
def test_spectral_embedding_two_components(seed=36):
    """Test spectral embedding with two components"""
    random_state = np.random.RandomState(seed)
    n_sample = 100
    affinity = np.zeros(shape=[n_sample * 2,
                               n_sample * 2])
    # first component
    affinity[0:n_sample,
             0:n_sample] = np.abs(random_state.randn(n_sample, n_sample)) + 2
    # second component
    affinity[n_sample::,
             n_sample::] = np.abs(random_state.randn(n_sample, n_sample)) + 2
    # connection
    affinity[0, n_sample + 1] = 1
    affinity[n_sample + 1, 0] = 1
    affinity.flat[::2 * n_sample + 1] = 0
    affinity = 0.5 * (affinity + affinity.T)

    true_label = np.zeros(shape=2 * n_sample)
    true_label[0:n_sample] = 1

    se_precomp = SpectralEmbedding(n_components=1, affinity="precomputed",
                                   random_state=np.random.RandomState(seed))
    embedded_coordinate = se_precomp.fit_transform(affinity)
    # Some numpy versions are touchy with types
    embedded_coordinate = \
        se_precomp.fit_transform(affinity.astype(np.float32))
    # thresholding on the first components using 0.
    label_ = np.array(embedded_coordinate.ravel() < 0, dtype="float")
    assert_equal(normalized_mutual_info_score(true_label, label_), 1.0)
开发者ID:amitmse,项目名称:scikit-learn,代码行数:32,代码来源:test_spectral_embedding.py

示例2: test_spectral_embedding_precomputed_affinity

# 需要导入模块: from sklearn.manifold.spectral_embedding_ import SpectralEmbedding [as 别名]
# 或者: from sklearn.manifold.spectral_embedding_.SpectralEmbedding import fit_transform [as 别名]
def test_spectral_embedding_precomputed_affinity(seed=36):
    # Test spectral embedding with precomputed kernel
    gamma = 1.0
    se_precomp = SpectralEmbedding(n_components=2, affinity="precomputed", random_state=np.random.RandomState(seed))
    se_rbf = SpectralEmbedding(n_components=2, affinity="rbf", gamma=gamma, random_state=np.random.RandomState(seed))
    embed_precomp = se_precomp.fit_transform(rbf_kernel(S, gamma=gamma))
    embed_rbf = se_rbf.fit_transform(S)
    assert_array_almost_equal(se_precomp.affinity_matrix_, se_rbf.affinity_matrix_)
    assert_true(_check_with_col_sign_flipping(embed_precomp, embed_rbf, 0.05))
开发者ID:BTY2684,项目名称:scikit-learn,代码行数:11,代码来源:test_spectral_embedding.py

示例3: test_spectral_embedding_amg_solver

# 需要导入模块: from sklearn.manifold.spectral_embedding_ import SpectralEmbedding [as 别名]
# 或者: from sklearn.manifold.spectral_embedding_.SpectralEmbedding import fit_transform [as 别名]
def test_spectral_embedding_amg_solver(seed=36):
    """Test spectral embedding with amg solver"""
    try:
        from pyamg import smoothed_aggregation_solver
    except ImportError:
        raise SkipTest("pyamg not available.")

    se_amg = SpectralEmbedding(n_components=2, affinity="nearest_neighbors",
                               eigen_solver="amg", n_neighbors=5,
                               random_state=np.random.RandomState(seed))
    se_arpack = SpectralEmbedding(n_components=2, affinity="nearest_neighbors",
                                  eigen_solver="arpack", n_neighbors=5,
                                  random_state=np.random.RandomState(seed))
    embed_amg = se_amg.fit_transform(S)
    embed_arpack = se_arpack.fit_transform(S)
    assert_true(_check_with_col_sign_flipping(embed_amg, embed_arpack, 0.05))
开发者ID:amitmse,项目名称:scikit-learn,代码行数:18,代码来源:test_spectral_embedding.py

示例4: test_spectral_embedding_callable_affinity

# 需要导入模块: from sklearn.manifold.spectral_embedding_ import SpectralEmbedding [as 别名]
# 或者: from sklearn.manifold.spectral_embedding_.SpectralEmbedding import fit_transform [as 别名]
def test_spectral_embedding_callable_affinity(seed=36):
    # Test spectral embedding with callable affinity
    gamma = 0.9
    kern = rbf_kernel(S, gamma=gamma)
    se_callable = SpectralEmbedding(
        n_components=2,
        affinity=(lambda x: rbf_kernel(x, gamma=gamma)),
        gamma=gamma,
        random_state=np.random.RandomState(seed),
    )
    se_rbf = SpectralEmbedding(n_components=2, affinity="rbf", gamma=gamma, random_state=np.random.RandomState(seed))
    embed_rbf = se_rbf.fit_transform(S)
    embed_callable = se_callable.fit_transform(S)
    assert_array_almost_equal(se_callable.affinity_matrix_, se_rbf.affinity_matrix_)
    assert_array_almost_equal(kern, se_rbf.affinity_matrix_)
    assert_true(_check_with_col_sign_flipping(embed_rbf, embed_callable, 0.05))
开发者ID:BTY2684,项目名称:scikit-learn,代码行数:18,代码来源:test_spectral_embedding.py

示例5: test_spectral_embedding_two_components

# 需要导入模块: from sklearn.manifold.spectral_embedding_ import SpectralEmbedding [as 别名]
# 或者: from sklearn.manifold.spectral_embedding_.SpectralEmbedding import fit_transform [as 别名]
def test_spectral_embedding_two_components(seed=36):
    """Test spectral embedding with two components"""
    random_state = np.random.RandomState(seed)
    n_sample = 100
    affinity = np.zeros(shape=[n_sample * 2,
                               n_sample * 2])
    # first component
    affinity[0:n_sample,
             0:n_sample] = np.abs(random_state.randn(n_sample, n_sample)) + 2
    # second component
    affinity[n_sample::,
             n_sample::] = np.abs(random_state.randn(n_sample, n_sample)) + 2
    # connection
    affinity[0, n_sample + 1] = 1
    affinity[n_sample + 1, 0] = 1
    affinity.flat[::2 * n_sample + 1] = 0
    affinity = 0.5 * (affinity + affinity.T)

    true_label = np.zeros(shape=2 * n_sample)
    true_label[0:n_sample] = 1

    se_precomp = SpectralEmbedding(n_components=1, affinity="precomputed",
                                   random_state=np.random.RandomState(seed))
    embedded_coordinate = se_precomp.fit_transform(affinity)
    # Some numpy versions are touchy with types
    embedded_coordinate = \
        se_precomp.fit_transform(affinity.astype(np.float32))
    # thresholding on the first components using 0.
    label_ = np.array(embedded_coordinate.ravel() < 0, dtype="float")
    assert_equal(normalized_mutual_info_score(true_label, label_), 1.0)

    # test that we can still import spectral embedding
    from sklearn.cluster import spectral_embedding as se_deprecated
    warnings.simplefilter("always", DeprecationWarning)
    with warnings.catch_warnings(record=True) as warning_list:
        embedded_depr = se_deprecated(affinity, n_components=1,
                                      random_state=np.random.RandomState(seed))
    assert_equal(len(warning_list), 1)
    warnings.filters.pop(0)
    assert_true(_check_with_col_sign_flipping(embedded_coordinate,
                                              embedded_depr, 0.05))
开发者ID:Comy,项目名称:scikit-learn,代码行数:43,代码来源:test_spectral_embedding.py


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