Permalink
Browse files

Use rbf_kernel.

  • Loading branch information...
1 parent f977346 commit e3ed8e0a0e89d40f7252224e0c799ebae14596cc @mblondel mblondel committed Jan 10, 2012
Showing with 5 additions and 6 deletions.
  1. +5 −6 sklearn/tests/test_kernel_approximation.py
View
11 sklearn/tests/test_kernel_approximation.py
@@ -1,10 +1,10 @@
import numpy as np
from scipy.sparse import csr_matrix
-from scipy.spatial.distance import cdist
-from ..kernel_approximation import RBFSampler
-from ..kernel_approximation import AdditiveChi2Sampler
-from ..kernel_approximation import SkewedChi2Sampler
+from sklearn.kernel_approximation import RBFSampler
+from sklearn.kernel_approximation import AdditiveChi2Sampler
+from sklearn.kernel_approximation import SkewedChi2Sampler
+from sklearn.metrics.pairwise import rbf_kernel
# generate data
X = np.random.uniform(size=(300, 50))
@@ -64,8 +64,7 @@ def test_rbf_sampler():
"""test that RBFSampler approximates kernel on random data"""
# compute exact kernel
gamma = 10.
- dists = cdist(X, Y)
- kernel = np.exp(-gamma * dists ** 2)
+ kernel = rbf_kernel(X, Y, gamma=gamma)
# appoximate kernel mapping
rbf_transform = RBFSampler(gamma=gamma, n_components=1000, random_state=42)

0 comments on commit e3ed8e0

Please sign in to comment.