當前位置: 首頁>>代碼示例>>Python>>正文


Python random_projection.GaussianRandomProjection方法代碼示例

本文整理匯總了Python中sklearn.random_projection.GaussianRandomProjection方法的典型用法代碼示例。如果您正苦於以下問題:Python random_projection.GaussianRandomProjection方法的具體用法?Python random_projection.GaussianRandomProjection怎麽用?Python random_projection.GaussianRandomProjection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sklearn.random_projection的用法示例。


在下文中一共展示了random_projection.GaussianRandomProjection方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: random_projection

# 需要導入模塊: from sklearn import random_projection [as 別名]
# 或者: from sklearn.random_projection import GaussianRandomProjection [as 別名]
def random_projection(mat, dim=3):
  """
   Projects a matrix of dimensions m x oldim to m x dim using a random
   projection
  """
  # include has to be here for multiprocessing problems
  from sklearn import random_projection as rp

  if mat.is_cuda:
    device = torch.device("cuda")
  else:
    device = torch.device("cpu")

  # project
  m, oldim = mat.shape
  t = rp.GaussianRandomProjection()
  proj_mat = torch.tensor(t._make_random_matrix(dim, oldim))
  proj_mat = proj_mat.to(device)
  output = torch.matmul(mat.double(), proj_mat.t())

  # check new dim
  assert(output.shape[0] == m)
  assert(output.shape[1] == dim)

  return output 
開發者ID:PRBonn,項目名稱:bonnetal,代碼行數:27,代碼來源:projections.py

示例2: transform_bag_of_words

# 需要導入模塊: from sklearn import random_projection [as 別名]
# 或者: from sklearn.random_projection import GaussianRandomProjection [as 別名]
def transform_bag_of_words(filename, n_dimensions, out_fn):
    import gzip
    from scipy.sparse import lil_matrix
    from sklearn.feature_extraction.text import TfidfTransformer
    from sklearn import random_projection
    with gzip.open(filename, 'rb') as f:
        file_content = f.readlines()
        entries = int(file_content[0])
        words = int(file_content[1])
        file_content = file_content[3:]  # strip first three entries
        print("building matrix...")
        A = lil_matrix((entries, words))
        for e in file_content:
            doc, word, cnt = [int(v) for v in e.strip().split()]
            A[doc - 1, word - 1] = cnt
        print("normalizing matrix entries with tfidf...")
        B = TfidfTransformer().fit_transform(A)
        print("reducing dimensionality...")
        C = random_projection.GaussianRandomProjection(
            n_components=n_dimensions).fit_transform(B)
        X_train, X_test = train_test_split(C)
        write_output(numpy.array(X_train), numpy.array(
            X_test), out_fn, 'angular') 
開發者ID:erikbern,項目名稱:ann-benchmarks,代碼行數:25,代碼來源:datasets.py

示例3: __init__

# 需要導入模塊: from sklearn import random_projection [as 別名]
# 或者: from sklearn.random_projection import GaussianRandomProjection [as 別名]
def __init__(self, **kwargs):
        super().__init__()
        self.estimator = sk_rp.GaussianRandomProjection(**kwargs) 
開發者ID:minerva-ml,項目名稱:open-solution-value-prediction,代碼行數:5,代碼來源:feature_extraction.py

示例4: __init__

# 需要導入模塊: from sklearn import random_projection [as 別名]
# 或者: from sklearn.random_projection import GaussianRandomProjection [as 別名]
def __init__(self, n_components='auto', eps=0.1, random_state=None):
        self._hyperparams = {
            'n_components': n_components,
            'eps': eps,
            'random_state': random_state}
        self._wrapped_model = Op(**self._hyperparams) 
開發者ID:IBM,項目名稱:lale,代碼行數:8,代碼來源:gaussian_random_projection.py

示例5: test_gaussian_random_projection_float32

# 需要導入模塊: from sklearn import random_projection [as 別名]
# 或者: from sklearn.random_projection import GaussianRandomProjection [as 別名]
def test_gaussian_random_projection_float32(self):
        rng = np.random.RandomState(42)
        pt = GaussianRandomProjection(n_components=4)
        X = rng.rand(10, 5)
        model = pt.fit(X)
        assert model.transform(X).shape[1] == 4
        model_onnx = convert_sklearn(
            model, "scikit-learn GaussianRandomProjection",
            [("inputs", FloatTensorType([None, X.shape[1]]))],
            target_opset=TARGET_OPSET)
        self.assertIsNotNone(model_onnx)
        dump_data_and_model(X.astype(np.float32), model,
                            model_onnx, basename="GaussianRandomProjection") 
開發者ID:onnx,項目名稱:sklearn-onnx,代碼行數:15,代碼來源:test_sklearn_random_projection.py

示例6: test_gaussian_random_projection_float64

# 需要導入模塊: from sklearn import random_projection [as 別名]
# 或者: from sklearn.random_projection import GaussianRandomProjection [as 別名]
def test_gaussian_random_projection_float64(self):
        rng = np.random.RandomState(42)
        pt = GaussianRandomProjection(n_components=4)
        X = rng.rand(10, 5).astype(np.float64)
        model = pt.fit(X)
        model_onnx = to_onnx(model, X[:1], dtype=np.float64,
                             target_opset=TARGET_OPSET)
        self.assertIsNotNone(model_onnx)
        dump_data_and_model(X, model,
                            model_onnx, basename="GaussianRandomProjection64") 
開發者ID:onnx,項目名稱:sklearn-onnx,代碼行數:12,代碼來源:test_sklearn_random_projection.py

示例7: test_objectmapper

# 需要導入模塊: from sklearn import random_projection [as 別名]
# 或者: from sklearn.random_projection import GaussianRandomProjection [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.GaussianRandomProjection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。