Skip to content

Commit

Permalink
reference/cluster: Change calculation for k-means k
Browse files Browse the repository at this point in the history
  • Loading branch information
etal committed Mar 29, 2019
1 parent 14146aa commit 74b20d1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cnvlib/cluster.py
Expand Up @@ -14,11 +14,11 @@


def kmeans(samples, k=None):
from .pca import pca_sk
from scipy.cluster import vq
if k is None:
# E.g. 8 -> k=2, 27 -> k=3, 64->4, 5->125, 6->216, 7->343
k = max(1, int(len(samples) ** (1/3.)))
from math import log
k = max(1, int(round(log(len(samples), 3))))
# E.g. n=66 -> k=2, 16 -> 3, 47 -> 4, 141 -> 5, 421 -> 6, 1263 -> 7

print("Clustering", len(samples), "samples by k-means, where k =", k)
obs = pca_sk(samples, 3)
Expand Down

0 comments on commit 74b20d1

Please sign in to comment.