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


Python kernel_approximation.AdditiveChi2Sampler方法代码示例

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


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

示例1: test_input_validation

# 需要导入模块: from sklearn import kernel_approximation [as 别名]
# 或者: from sklearn.kernel_approximation import AdditiveChi2Sampler [as 别名]
def test_input_validation():
    # Regression test: kernel approx. transformers should work on lists
    # No assertions; the old versions would simply crash
    X = [[1, 2], [3, 4], [5, 6]]
    AdditiveChi2Sampler().fit(X).transform(X)
    SkewedChi2Sampler().fit(X).transform(X)
    RBFSampler().fit(X).transform(X)

    X = csr_matrix(X)
    RBFSampler().fit(X).transform(X) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:12,代码来源:test_kernel_approximation.py

示例2: __init__

# 需要导入模块: from sklearn import kernel_approximation [as 别名]
# 或者: from sklearn.kernel_approximation import AdditiveChi2Sampler [as 别名]
def __init__(self, sample_steps=2, sample_interval=None):
        self._hyperparams = {
            'sample_steps': sample_steps,
            'sample_interval': sample_interval}
        self._wrapped_model = Op(**self._hyperparams) 
开发者ID:IBM,项目名称:lale,代码行数:7,代码来源:additive_chi2_sampler.py

示例3: chi_squared_projection

# 需要导入模块: from sklearn import kernel_approximation [as 别名]
# 或者: from sklearn.kernel_approximation import AdditiveChi2Sampler [as 别名]
def chi_squared_projection(features):
    chi2_feature = AdditiveChi2Sampler()
    X_transformed = chi2_feature.fit_transform(features)
    X_transformed = X_transformed.tocsr()

    return X_transformed 
开发者ID:MKLab-ITI,项目名称:reveal-graph-embedding,代码行数:8,代码来源:common.py

示例4: test_objectmapper

# 需要导入模块: from sklearn import kernel_approximation [as 别名]
# 或者: from sklearn.kernel_approximation import AdditiveChi2Sampler [as 别名]
def test_objectmapper(self):
        df = pdml.ModelFrame([])
        self.assertIs(df.kernel_approximation.AdditiveChi2Sampler,
                      ka.AdditiveChi2Sampler)
        self.assertIs(df.kernel_approximation.Nystroem, ka.Nystroem)
        self.assertIs(df.kernel_approximation.RBFSampler, ka.RBFSampler)
        self.assertIs(df.kernel_approximation.SkewedChi2Sampler,
                      ka.SkewedChi2Sampler) 
开发者ID:pandas-ml,项目名称:pandas-ml,代码行数:10,代码来源:test_kernel_approximation.py

示例5: test_additive_chi2_sampler

# 需要导入模块: from sklearn import kernel_approximation [as 别名]
# 或者: from sklearn.kernel_approximation import AdditiveChi2Sampler [as 别名]
def test_additive_chi2_sampler():
    # test that AdditiveChi2Sampler approximates kernel on random data

    # compute exact kernel
    # abbreviations for easier formula
    X_ = X[:, np.newaxis, :]
    Y_ = Y[np.newaxis, :, :]

    large_kernel = 2 * X_ * Y_ / (X_ + Y_)

    # reduce to n_samples_x x n_samples_y by summing over features
    kernel = (large_kernel.sum(axis=2))

    # approximate kernel mapping
    transform = AdditiveChi2Sampler(sample_steps=3)
    X_trans = transform.fit_transform(X)
    Y_trans = transform.transform(Y)

    kernel_approx = np.dot(X_trans, Y_trans.T)

    assert_array_almost_equal(kernel, kernel_approx, 1)

    X_sp_trans = transform.fit_transform(csr_matrix(X))
    Y_sp_trans = transform.transform(csr_matrix(Y))

    assert_array_equal(X_trans, X_sp_trans.A)
    assert_array_equal(Y_trans, Y_sp_trans.A)

    # test error is raised on negative input
    Y_neg = Y.copy()
    Y_neg[0, 0] = -1
    assert_raises(ValueError, transform.transform, Y_neg)

    # test error on invalid sample_steps
    transform = AdditiveChi2Sampler(sample_steps=4)
    assert_raises(ValueError, transform.fit, X)

    # test that the sample interval is set correctly
    sample_steps_available = [1, 2, 3]
    for sample_steps in sample_steps_available:

        # test that the sample_interval is initialized correctly
        transform = AdditiveChi2Sampler(sample_steps=sample_steps)
        assert_equal(transform.sample_interval, None)

        # test that the sample_interval is changed in the fit method
        transform.fit(X)
        assert_not_equal(transform.sample_interval_, None)

    # test that the sample_interval is set correctly
    sample_interval = 0.3
    transform = AdditiveChi2Sampler(sample_steps=4,
                                    sample_interval=sample_interval)
    assert_equal(transform.sample_interval, sample_interval)
    transform.fit(X)
    assert_equal(transform.sample_interval_, sample_interval) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:58,代码来源:test_kernel_approximation.py


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