Пример #1
0
def test_rbf_kernel(setup):
    rs = np.random.RandomState(0)
    raw_X = rs.rand(10, 4)
    raw_Y = rs.rand(11, 4)

    r = rbf_kernel(raw_X, raw_Y)
    result = r.to_numpy()
    expected = sklearn_rbf_kernel(raw_X, raw_Y)

    np.testing.assert_almost_equal(result, expected)
Пример #2
0
    def testRbfKernel(self):
        rs = np.random.RandomState(0)
        raw_X = rs.rand(10, 4)
        raw_Y = rs.rand(11, 4)

        r = rbf_kernel(raw_X, raw_Y)
        result = r.execute()
        expected = sklearn_rbf_kernel(raw_X, raw_Y)

        np.testing.assert_almost_equal(result, expected)
Пример #3
0
 def setUp(self) -> None:
     self.estimators = [(LabelPropagation, {
         'kernel': 'rbf'
     }), (LabelPropagation, {
         'kernel': 'knn',
         'n_neighbors': 2
     }),
                        (LabelPropagation, {
                            'kernel':
                            lambda x, y: rbf_kernel(x, y, gamma=20)
                        })]
Пример #4
0
    def setUp(self) -> None:
        self.session = new_session().as_default()
        self._old_executor = self.session._sess._executor
        self.executor = self.session._sess._executor = \
            ExecutorForTest('numpy', storage=self.session._sess._context)

        self.estimators = [(LabelPropagation, {
            'kernel': 'rbf'
        }), (LabelPropagation, {
            'kernel': 'knn',
            'n_neighbors': 2
        }),
                           (LabelPropagation, {
                               'kernel':
                               lambda x, y: rbf_kernel(x, y, gamma=20)
                           })]
Пример #5
0
from sklearn.model_selection import train_test_split
from sklearn.exceptions import ConvergenceWarning
from sklearn.utils._testing import assert_no_warnings, assert_warns

from mars import tensor as mt
from mars.learn.metrics.pairwise import rbf_kernel
from mars.learn.neighbors import NearestNeighbors
from mars.learn.semi_supervised import LabelPropagation

estimators = [(LabelPropagation, {
    'kernel': 'rbf'
}), (LabelPropagation, {
    'kernel': 'knn',
    'n_neighbors': 2
}), (LabelPropagation, {
    'kernel': lambda x, y: rbf_kernel(x, y, gamma=20)
})]


@pytest.mark.parametrize('estimator, parameters', estimators)
def test_fit_transduction(setup, estimator, parameters):
    samples = [[1., 0.], [0., 2.], [1., 3.]]
    labels = [0, 1, -1]
    clf = estimator(**parameters).fit(samples, labels)
    assert clf.transduction_[2].fetch() == 1


@pytest.mark.parametrize('estimator, parameters', estimators)
def test_distribution(setup, estimator, parameters):
    samples = [[1., 0.], [0., 1.], [1., 1.]]
    labels = [0, 1, -1]