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