sklearnのDBSCANクラスタリング

機械学習




DBSCAN

from sklearn.cluster import DBSCAN
from sklearn.datasets import load_iris, make_moons

import matplotlib.pyplot as plt

noisy_moons = make_moons(n_samples=100, noise=.05)[0]

dbscan_pred = DBSCAN(0.3, 6).fit_predict(noisy_moons)

plt.figure(figsize=(10, 6))
print(set(dbscan_pred))
for i in set(dbscan_pred):
    sub_x = noisy_moons[dbscan_pred==i]
    plt.scatter(sub_x[:,0], sub_x[:,1])
#plt.savefig('noisy_moons_DBSCAN.png')
plt.show()

元のデータ

DBSCAN

参考

  1. sklearn.cluster.DBSCAN|scikit-learn
  2. Demo of OPTICS clustering algorithm
  3. sklearn.cluster.cluster_optics_dbscan
  4. Comparing different clustering algorithms on toy datasets
タイトルとURLをコピーしました