當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。