Skip to content

Instantly share code, notes, and snippets.

@armgilles
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save armgilles/beb5da3873f33781cb9e to your computer and use it in GitHub Desktop.
Save armgilles/beb5da3873f33781cb9e to your computer and use it in GitHub Desktop.
searching the number of cluster find by DBSCAN algo by moving eps value
from sklearn.cluster import DBSCAN
import pandas as pd
# You already have your feature in X
dbscan_eps = []
for i in [x / 10.0 for x in range(1, 20, 1)]:
db = DBSCAN(eps=i).fit(X)
n_clusters_ = len(set(db.labels_)) - (1 if -1 in db.labels_ else 0)
print "eps = " +" "+ str(i) +" "+ " cluster = " + str(n_clusters_)
dbscan_eps.append({'eps' : i,
'n_cluster' : n_clusters_})
df_dbscan_eps = pd.DataFrame(dbscan_eps)
df_dbscan_eps.set_index('eps', inplace=True)
df_dbscan_eps.plot()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment