Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e3ed8e0

Browse files
committed
Use rbf_kernel.
1 parent f977346 commit e3ed8e0

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

sklearn/tests/test_kernel_approximation.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import numpy as np
22
from scipy.sparse import csr_matrix
3-
from scipy.spatial.distance import cdist
43

5-
from ..kernel_approximation import RBFSampler
6-
from ..kernel_approximation import AdditiveChi2Sampler
7-
from ..kernel_approximation import SkewedChi2Sampler
4+
from sklearn.kernel_approximation import RBFSampler
5+
from sklearn.kernel_approximation import AdditiveChi2Sampler
6+
from sklearn.kernel_approximation import SkewedChi2Sampler
7+
from sklearn.metrics.pairwise import rbf_kernel
88

99
# generate data
1010
X = np.random.uniform(size=(300, 50))
@@ -64,8 +64,7 @@ def test_rbf_sampler():
6464
"""test that RBFSampler approximates kernel on random data"""
6565
# compute exact kernel
6666
gamma = 10.
67-
dists = cdist(X, Y)
68-
kernel = np.exp(-gamma * dists ** 2)
67+
kernel = rbf_kernel(X, Y, gamma=gamma)
6968

7069
# appoximate kernel mapping
7170
rbf_transform = RBFSampler(gamma=gamma, n_components=1000, random_state=42)

0 commit comments

Comments
 (0)