• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python testing.assert_allclose_dense_sparse函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sklearn.utils.testing.assert_allclose_dense_sparse函数的典型用法代码示例。如果您正苦于以下问题:Python assert_allclose_dense_sparse函数的具体用法?Python assert_allclose_dense_sparse怎么用?Python assert_allclose_dense_sparse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_function_sampler_func

def test_function_sampler_func(X, y):
    def func(X, y):
        return X[:10], y[:10]

    sampler = FunctionSampler(func=func)
    X_res, y_res = sampler.fit_resample(X, y)
    assert_allclose_dense_sparse(X_res, X[:10])
    assert_array_equal(y_res, y[:10])
开发者ID:bodycat,项目名称:imbalanced-learn,代码行数:8,代码来源:test_base.py


示例2: test_tfidf_transformer_sparse

def test_tfidf_transformer_sparse():
    X = sparse.rand(10, 20000, dtype=np.float64, random_state=42)
    X_csc = sparse.csc_matrix(X)
    X_csr = sparse.csr_matrix(X)

    X_trans_csc = TfidfTransformer().fit_transform(X_csc)
    X_trans_csr = TfidfTransformer().fit_transform(X_csr)
    assert_allclose_dense_sparse(X_trans_csc, X_trans_csr)
    assert X_trans_csc.format == X_trans_csr.format
开发者ID:as133,项目名称:scikit-learn,代码行数:9,代码来源:test_text.py


示例3: test_function_sampler_func_kwargs

def test_function_sampler_func_kwargs(X, y):

    def func(X, y, ratio, random_state):
        rus = RandomUnderSampler(ratio=ratio, random_state=random_state)
        return rus.fit_sample(X, y)

    sampler = FunctionSampler(func=func, kw_args={'ratio': 'auto',
                                                  'random_state': 0})
    X_res, y_res = sampler.fit_sample(X, y)
    X_res_2, y_res_2 = RandomUnderSampler(random_state=0).fit_sample(X, y)
    assert_allclose_dense_sparse(X_res, X_res_2)
    assert_array_equal(y_res, y_res_2)
开发者ID:zzhhoubin,项目名称:imbalanced-learn,代码行数:12,代码来源:test_base.py


示例4: test_column_transformer_sparse_array

def test_column_transformer_sparse_array():
    X_sparse = sparse.eye(3, 2).tocsr()

    # no distinction between 1D and 2D
    X_res_first = X_sparse[:, 0]
    X_res_both = X_sparse

    for col in [0, [0], slice(0, 1)]:
        for remainder, res in [('drop', X_res_first),
                               ('passthrough', X_res_both)]:
            ct = ColumnTransformer([('trans', Trans(), col)],
                                   remainder=remainder,
                                   sparse_threshold=0.8)
            assert sparse.issparse(ct.fit_transform(X_sparse))
            assert_allclose_dense_sparse(ct.fit_transform(X_sparse), res)
            assert_allclose_dense_sparse(ct.fit(X_sparse).transform(X_sparse),
                                         res)

    for col in [[0, 1], slice(0, 2)]:
        ct = ColumnTransformer([('trans', Trans(), col)],
                               sparse_threshold=0.8)
        assert sparse.issparse(ct.fit_transform(X_sparse))
        assert_allclose_dense_sparse(ct.fit_transform(X_sparse), X_res_both)
        assert_allclose_dense_sparse(ct.fit(X_sparse).transform(X_sparse),
                                     X_res_both)
开发者ID:kevin-coder,项目名称:scikit-learn-fork,代码行数:25,代码来源:test_column_transformer.py


示例5: test_incremental_pca_batch_rank

def test_incremental_pca_batch_rank():
    # Test sample size in each batch is always larger or equal to n_components
    rng = np.random.RandomState(1999)
    n_samples = 100
    n_features = 20
    X = rng.randn(n_samples, n_features)
    all_components = []
    batch_sizes = np.arange(20, 90, 3)
    for batch_size in batch_sizes:
        ipca = IncrementalPCA(n_components=20, batch_size=batch_size).fit(X)
        all_components.append(ipca.components_)

    for components_i, components_j in zip(all_components[:-1],
                                          all_components[1:]):
        assert_allclose_dense_sparse(components_i, components_j)
开发者ID:allefpablo,项目名称:scikit-learn,代码行数:15,代码来源:test_incremental_pca.py


示例6: test_assert_allclose_dense_sparse

def test_assert_allclose_dense_sparse():
    x = np.arange(9).reshape(3, 3)
    msg = "Not equal to tolerance "
    y = sparse.csc_matrix(x)
    for X in [x, y]:
        # basic compare
        assert_raise_message(AssertionError, msg, assert_allclose_dense_sparse,
                             X, X * 2)
        assert_allclose_dense_sparse(X, X)

    assert_raise_message(ValueError, "Can only compare two sparse",
                         assert_allclose_dense_sparse, x, y)

    A = sparse.diags(np.ones(5), offsets=0).tocsr()
    B = sparse.csr_matrix(np.ones((1, 5)))

    assert_raise_message(AssertionError, "Arrays are not equal",
                         assert_allclose_dense_sparse, B, A)
开发者ID:MartinThoma,项目名称:scikit-learn,代码行数:18,代码来源:test_testing.py


示例7: test_check_inverse

def test_check_inverse():
    X_dense = np.array([1, 4, 9, 16], dtype=np.float64).reshape((2, 2))

    X_list = [X_dense,
              sparse.csr_matrix(X_dense),
              sparse.csc_matrix(X_dense)]

    for X in X_list:
        if sparse.issparse(X):
            accept_sparse = True
        else:
            accept_sparse = False
        trans = FunctionTransformer(func=np.sqrt,
                                    inverse_func=np.around,
                                    accept_sparse=accept_sparse,
                                    check_inverse=True,
                                    validate=True)
        assert_warns_message(UserWarning,
                             "The provided functions are not strictly"
                             " inverse of each other. If you are sure you"
                             " want to proceed regardless, set"
                             " 'check_inverse=False'.",
                             trans.fit, X)

        trans = FunctionTransformer(func=np.expm1,
                                    inverse_func=np.log1p,
                                    accept_sparse=accept_sparse,
                                    check_inverse=True,
                                    validate=True)
        Xt = assert_no_warnings(trans.fit_transform, X)
        assert_allclose_dense_sparse(X, trans.inverse_transform(Xt))

    # check that we don't check inverse when one of the func or inverse is not
    # provided.
    trans = FunctionTransformer(func=np.expm1, inverse_func=None,
                                check_inverse=True, validate=True)
    assert_no_warnings(trans.fit, X_dense)
    trans = FunctionTransformer(func=None, inverse_func=np.expm1,
                                check_inverse=True, validate=True)
    assert_no_warnings(trans.fit, X_dense)
开发者ID:SuryodayBasak,项目名称:scikit-learn,代码行数:40,代码来源:test_function_transformer.py


示例8: test_imputation_constant_float

def test_imputation_constant_float(array_constructor):
    # Test imputation using the constant strategy on floats
    X = np.array([
        [np.nan, 1.1, 0, np.nan],
        [1.2, np.nan, 1.3, np.nan],
        [0, 0, np.nan, np.nan],
        [1.4, 1.5, 0, np.nan]
    ])

    X_true = np.array([
        [-1, 1.1, 0, -1],
        [1.2, -1, 1.3, -1],
        [0, 0, -1, -1],
        [1.4, 1.5, 0, -1]
    ])

    X = array_constructor(X)

    X_true = array_constructor(X_true)

    imputer = SimpleImputer(strategy="constant", fill_value=-1)
    X_trans = imputer.fit_transform(X)

    assert_allclose_dense_sparse(X_trans, X_true)
开发者ID:psorianom,项目名称:scikit-learn,代码行数:24,代码来源:test_impute.py


示例9: test_pipeline_consistency

def test_pipeline_consistency(estimator, build_dataset,
                              with_preprocessor):
  # Adapted from scikit learn
  # check that make_pipeline(est) gives same score as est
  # we do this test on all except quadruplets (since they don't have a y
  # in fit):
  if estimator.__class__.__name__ not in [e.__class__.__name__
                                          for (e, _) in
                                          quadruplets_learners]:
    input_data, y, preprocessor, _ = build_dataset(with_preprocessor)

    def make_random_state(estimator, in_pipeline):
      rs = {}
      name_estimator = estimator.__class__.__name__
      if name_estimator[-11:] == '_Supervised':
        name_param = 'random_state'
        if in_pipeline:
            name_param = name_estimator.lower() + '__' + name_param
        rs[name_param] = check_random_state(0)
      return rs

    estimator = clone(estimator)
    estimator.set_params(preprocessor=preprocessor)
    pipeline = make_pipeline(estimator)
    estimator.fit(*remove_y_quadruplets(estimator, input_data, y),
                  **make_random_state(estimator, False))
    pipeline.fit(*remove_y_quadruplets(estimator, input_data, y),
                 **make_random_state(estimator, True))

    if hasattr(estimator, 'score'):
      result = estimator.score(*remove_y_quadruplets(estimator,
                                                     input_data,
                                                     y))
      result_pipe = pipeline.score(*remove_y_quadruplets(estimator,
                                                         input_data,
                                                         y))
      assert_allclose_dense_sparse(result, result_pipe)

    if hasattr(estimator, 'predict'):
      result = estimator.predict(input_data)
      result_pipe = pipeline.predict(input_data)
      assert_allclose_dense_sparse(result, result_pipe)

    if issubclass(estimator.__class__, TransformerMixin):
      if hasattr(estimator, 'transform'):
        result = estimator.transform(input_data)
        result_pipe = pipeline.transform(input_data)
        assert_allclose_dense_sparse(result, result_pipe)
开发者ID:all-umass,项目名称:metric-learn,代码行数:48,代码来源:test_sklearn_compat.py


示例10: test_check_array_force_all_finite_valid

def test_check_array_force_all_finite_valid(value, force_all_finite, retype):
    X = retype(np.arange(4).reshape(2, 2).astype(np.float))
    X[0, 0] = value
    X_checked = check_array(X, force_all_finite=force_all_finite,
                            accept_sparse=True)
    assert_allclose_dense_sparse(X, X_checked)
开发者ID:daniel-perry,项目名称:scikit-learn,代码行数:6,代码来源:test_validation.py


示例11: test_as_float_array_nan

def test_as_float_array_nan(X):
    X[5, 0] = np.nan
    X[6, 1] = np.nan
    X_converted = as_float_array(X, force_all_finite='allow-nan')
    assert_allclose_dense_sparse(X_converted, X)
开发者ID:daniel-perry,项目名称:scikit-learn,代码行数:5,代码来源:test_validation.py


示例12: test_function_sampler_identity

def test_function_sampler_identity(X, y):
    sampler = FunctionSampler()
    X_res, y_res = sampler.fit_sample(X, y)
    assert_allclose_dense_sparse(X_res, X)
    assert_array_equal(y_res, y)
开发者ID:zzhhoubin,项目名称:imbalanced-learn,代码行数:5,代码来源:test_base.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python testing.assert_almost_equal函数代码示例发布时间:2022-05-27
下一篇:
Python testing.assert_allclose函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap