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


Python random_projection.SparseRandomProjection方法代码示例

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


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

示例1: reduce_dimensionality

# 需要导入模块: from sklearn import random_projection [as 别名]
# 或者: from sklearn.random_projection import SparseRandomProjection [as 别名]
def reduce_dimensionality(X, method='svd', dimred=DIMRED, raw=False):
    if method == 'svd':
        k = min((dimred, X.shape[0], X.shape[1]))
        U, s, Vt = pca(X, k=k, raw=raw)
        return U[:, range(k)] * s[range(k)]
    elif method == 'jl_sparse':
        jls = JLSparse(n_components=dimred)
        return jls.fit_transform(X).toarray()
    elif method == 'hvg':
        X = X.tocsc()
        disp = dispersion(X)
        highest_disp_idx = np.argsort(disp)[::-1][:dimred]
        return X[:, highest_disp_idx].toarray()
    else:
        sys.stderr.write('ERROR: Unknown method {}.'.format(svd))
        exit(1) 
开发者ID:brianhie,项目名称:geosketch,代码行数:18,代码来源:utils.py

示例2: test_SparseRandomProjection_output_representation

# 需要导入模块: from sklearn import random_projection [as 别名]
# 或者: from sklearn.random_projection import SparseRandomProjection [as 别名]
def test_SparseRandomProjection_output_representation():
    for SparseRandomProjection in all_SparseRandomProjection:
        # when using sparse input, the projected data can be forced to be a
        # dense numpy array
        rp = SparseRandomProjection(n_components=10, dense_output=True,
                                    random_state=0)
        rp.fit(data)
        assert isinstance(rp.transform(data), np.ndarray)

        sparse_data = sp.csr_matrix(data)
        assert isinstance(rp.transform(sparse_data), np.ndarray)

        # the output can be left to a sparse matrix instead
        rp = SparseRandomProjection(n_components=10, dense_output=False,
                                    random_state=0)
        rp = rp.fit(data)
        # output for dense input will stay dense:
        assert isinstance(rp.transform(data), np.ndarray)

        # output for sparse output will be sparse:
        assert sp.issparse(rp.transform(sparse_data)) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:23,代码来源:test_random_projection.py

示例3: test_estimators_samples_deterministic

# 需要导入模块: from sklearn import random_projection [as 别名]
# 或者: from sklearn.random_projection import SparseRandomProjection [as 别名]
def test_estimators_samples_deterministic():
    # This test is a regression test to check that with a random step
    # (e.g. SparseRandomProjection) and a given random state, the results
    # generated at fit time can be identically reproduced at a later time using
    # data saved in object attributes. Check issue #9524 for full discussion.

    iris = load_iris()
    X, y = iris.data, iris.target

    base_pipeline = make_pipeline(SparseRandomProjection(n_components=2),
                                  LogisticRegression())
    clf = BaggingClassifier(base_estimator=base_pipeline,
                            max_samples=0.5,
                            random_state=0)
    clf.fit(X, y)
    pipeline_estimator_coef = clf.estimators_[0].steps[-1][1].coef_.copy()

    estimator = clf.estimators_[0]
    estimator_sample = clf.estimators_samples_[0]
    estimator_feature = clf.estimators_features_[0]

    X_train = (X[estimator_sample])[:, estimator_feature]
    y_train = y[estimator_sample]

    estimator.fit(X_train, y_train)
    assert_array_equal(estimator.steps[-1][1].coef_, pipeline_estimator_coef) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:28,代码来源:test_bagging.py

示例4: __init__

# 需要导入模块: from sklearn import random_projection [as 别名]
# 或者: from sklearn.random_projection import SparseRandomProjection [as 别名]
def __init__(self, **kwargs):
        super().__init__()
        self.estimator = sk_rp.SparseRandomProjection(**kwargs) 
开发者ID:minerva-ml,项目名称:open-solution-value-prediction,代码行数:5,代码来源:feature_extraction.py

示例5: __init__

# 需要导入模块: from sklearn import random_projection [as 别名]
# 或者: from sklearn.random_projection import SparseRandomProjection [as 别名]
def __init__(self, n_components='auto', density='auto', eps=0.1, dense_output=False, random_state=None):
        self._hyperparams = {
            'n_components': n_components,
            'density': density,
            'eps': eps,
            'dense_output': dense_output,
            'random_state': random_state}
        self._wrapped_model = Op(**self._hyperparams) 
开发者ID:IBM,项目名称:lale,代码行数:10,代码来源:sparse_random_projection.py

示例6: test_objectmapper

# 需要导入模块: from sklearn import random_projection [as 别名]
# 或者: from sklearn.random_projection import SparseRandomProjection [as 别名]
def test_objectmapper(self):
        df = pdml.ModelFrame([])
        self.assertIs(df.random_projection.GaussianRandomProjection, rp.GaussianRandomProjection)
        self.assertIs(df.random_projection.SparseRandomProjection, rp.SparseRandomProjection)
        self.assertIs(df.random_projection.johnson_lindenstrauss_min_dim, rp.johnson_lindenstrauss_min_dim) 
开发者ID:pandas-ml,项目名称:pandas-ml,代码行数:7,代码来源:test_random_projection.py


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