Skip to content

Commit fa8d1fe

Browse files
znd4rth
authored andcommitted
Implement KMedoids in scikit-learn-extra (#12)
1 parent ba1e3b7 commit fa8d1fe

File tree

11 files changed

+1049
-106
lines changed

11 files changed

+1049
-106
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ __pycache__/
88
# C extensions
99
*.so
1010

11+
# Text Editors
12+
.vscode/
13+
1114
# scikit-learn specific
1215
doc/_build/
1316
doc/auto_examples/
@@ -17,6 +20,7 @@ doc/datasets/generated/
1720
# Distribution / packaging
1821

1922
.Python
23+
venv/
2024
env/
2125
build/
2226
develop-eggs/

benchmarks/bench_rbfsampler_fastfood.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
Y /= Y.sum(axis=1)[:, np.newaxis]
1616

1717
# calculate feature maps
18-
gamma = 10.
18+
gamma = 10.0
1919
sigma = np.sqrt(1 / (2 * gamma))
20-
number_of_features_to_generate = 4096*4
20+
number_of_features_to_generate = 4096 * 4
2121

2222
exact_start = datetime.datetime.utcnow()
2323
# original rbf kernel method:
@@ -27,23 +27,24 @@
2727
exact_spent_time = exact_end - exact_start
2828
print("Timimg exact rbf: \t\t", exact_spent_time)
2929

30-
rbf_transform = Fastfood(sigma=sigma,
31-
n_components=number_of_features_to_generate,
32-
tradeoff_mem_accuracy='mem',
33-
random_state=42)
30+
rbf_transform = Fastfood(
31+
sigma=sigma,
32+
n_components=number_of_features_to_generate,
33+
tradeoff_mem_accuracy="mem",
34+
random_state=42,
35+
)
3436
_ = rbf_transform.fit(X)
3537
fastfood_fast_vec_start = datetime.datetime.utcnow()
3638
# Fastfood: approximate kernel mapping
3739
_ = rbf_transform.transform(X)
3840
_ = rbf_transform.transform(Y)
3941
fastfood_fast_vec_end = datetime.datetime.utcnow()
40-
fastfood_fast_vec_spent_time = fastfood_fast_vec_end - \
41-
fastfood_fast_vec_start
42+
fastfood_fast_vec_spent_time = fastfood_fast_vec_end - fastfood_fast_vec_start
4243
print("Timimg fastfood fast vectorized: \t\t", fastfood_fast_vec_spent_time)
4344

44-
rks_rbf_transform = RBFSampler(gamma=gamma,
45-
n_components=number_of_features_to_generate,
46-
random_state=42)
45+
rks_rbf_transform = RBFSampler(
46+
gamma=gamma, n_components=number_of_features_to_generate, random_state=42
47+
)
4748
_ = rks_rbf_transform.fit(X)
4849
rks_start = datetime.datetime.utcnow()
4950
# Random Kitchens Sinks: approximate kernel mapping

doc/api.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,13 @@ Kernel approximation
1212
:template: class.rst
1313

1414
kernel_approximation.Fastfood
15+
16+
Clustering
17+
====================
18+
19+
.. autosummary::
20+
:toctree: generated/
21+
:template: class.rst
22+
23+
cluster.KMedoids
24+

0 commit comments

Comments
 (0)