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


Python SparsePCA.transform方法代码示例

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


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

示例1: test_fit_transform

# 需要导入模块: from sklearn.decomposition import SparsePCA [as 别名]
# 或者: from sklearn.decomposition.SparsePCA import transform [as 别名]
def test_fit_transform():
    alpha = 1
    rng = np.random.RandomState(0)
    Y, _, _ = generate_toy_data(3, 10, (8, 8), random_state=rng)  # wide array
    spca_lars = SparsePCA(n_components=3, method='lars', alpha=alpha,
                          random_state=0)
    spca_lars.fit(Y)
    U1 = spca_lars.transform(Y)
    # Test multiple CPUs
    if sys.platform == 'win32':  # fake parallelism for win32
        import sklearn.externals.joblib.parallel as joblib_par
        _mp = joblib_par.multiprocessing
        joblib_par.multiprocessing = None
        try:
            spca = SparsePCA(n_components=3, n_jobs=2, random_state=0,
                             alpha=alpha).fit(Y)
            U2 = spca.transform(Y)
        finally:
            joblib_par.multiprocessing = _mp
    else:  # we can efficiently use parallelism
        spca = SparsePCA(n_components=3, n_jobs=2, method='lars', alpha=alpha,
                         random_state=0).fit(Y)
        U2 = spca.transform(Y)
    assert_true(not np.all(spca_lars.components_ == 0))
    assert_array_almost_equal(U1, U2)
    # Test that CD gives similar results
    spca_lasso = SparsePCA(n_components=3, method='cd', random_state=0,
                           alpha=alpha)
    spca_lasso.fit(Y)
    assert_array_almost_equal(spca_lasso.components_, spca_lars.components_)
开发者ID:boersmamarcel,项目名称:scikit-learn,代码行数:32,代码来源:test_sparse_pca.py

示例2: test_fit_transform_parallel

# 需要导入模块: from sklearn.decomposition import SparsePCA [as 别名]
# 或者: from sklearn.decomposition.SparsePCA import transform [as 别名]
def test_fit_transform_parallel():
    alpha = 1
    rng = np.random.RandomState(0)
    Y, _, _ = generate_toy_data(3, 10, (8, 8), random_state=rng)  # wide array
    spca_lars = SparsePCA(n_components=3, method='lars', alpha=alpha,
                          random_state=0)
    spca_lars.fit(Y)
    U1 = spca_lars.transform(Y)
    # Test multiple CPUs
    spca = SparsePCA(n_components=3, n_jobs=2, method='lars', alpha=alpha,
                     random_state=0).fit(Y)
    U2 = spca.transform(Y)
    assert_true(not np.all(spca_lars.components_ == 0))
    assert_array_almost_equal(U1, U2)
开发者ID:lebigot,项目名称:scikit-learn,代码行数:16,代码来源:test_sparse_pca.py

示例3: sparse_pca

# 需要导入模块: from sklearn.decomposition import SparsePCA [as 别名]
# 或者: from sklearn.decomposition.SparsePCA import transform [as 别名]
 def sparse_pca(self):
     """
     Runs PCA on view and returns projected view, the principle components,
     and explained variance.
     """
     model = SparsePCA(n_components=param['components'], alpha=param['sparse_pca_alpha'])
     model.fit(self.view)
     return model.transform(self.view), model.components_
开发者ID:bshapiro,项目名称:disease-time-series,代码行数:10,代码来源:representation.py

示例4: test_scaling_fit_transform

# 需要导入模块: from sklearn.decomposition import SparsePCA [as 别名]
# 或者: from sklearn.decomposition.SparsePCA import transform [as 别名]
def test_scaling_fit_transform():
    alpha = 1
    rng = np.random.RandomState(0)
    Y, _, _ = generate_toy_data(3, 1000, (8, 8), random_state=rng)
    spca_lars = SparsePCA(n_components=3, method='lars', alpha=alpha,
                          random_state=rng, normalize_components=True)
    results_train = spca_lars.fit_transform(Y)
    results_test = spca_lars.transform(Y[:10])
    assert_allclose(results_train[0], results_test[0])
开发者ID:MartinThoma,项目名称:scikit-learn,代码行数:11,代码来源:test_sparse_pca.py

示例5: test_pca_vs_spca

# 需要导入模块: from sklearn.decomposition import SparsePCA [as 别名]
# 或者: from sklearn.decomposition.SparsePCA import transform [as 别名]
def test_pca_vs_spca():
    rng = np.random.RandomState(0)
    Y, _, _ = generate_toy_data(3, 1000, (8, 8), random_state=rng)
    Z, _, _ = generate_toy_data(3, 10, (8, 8), random_state=rng)
    spca = SparsePCA(alpha=0, ridge_alpha=0, n_components=2,
                     normalize_components=True)
    pca = PCA(n_components=2)
    pca.fit(Y)
    spca.fit(Y)
    results_test_pca = pca.transform(Z)
    results_test_spca = spca.transform(Z)
    assert_allclose(np.abs(spca.components_.dot(pca.components_.T)),
                    np.eye(2), atol=1e-5)
    results_test_pca *= np.sign(results_test_pca[0, :])
    results_test_spca *= np.sign(results_test_spca[0, :])
    assert_allclose(results_test_pca, results_test_spca)
开发者ID:MartinThoma,项目名称:scikit-learn,代码行数:18,代码来源:test_sparse_pca.py

示例6: transform

# 需要导入模块: from sklearn.decomposition import SparsePCA [as 别名]
# 或者: from sklearn.decomposition.SparsePCA import transform [as 别名]
def transform(xTrain,yTrain,xTest):
    pca = SparsePCA(n_components=2);
    newXTrain =  pca.fit_transform(xTrain,yTrain)
    newXTest = pca.transform(xTest)
    return newXTrain,newXTest   
开发者ID:sreeram26,项目名称:DataMiningClassifier,代码行数:7,代码来源:DataModeller.py


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