当前位置: 首页>>代码示例>>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;未经允许,请勿转载。