예제
from sklearn.cluster import DBSCAN
from sklearn.datasets import make_blobs
import matplotlib.pyplot as plt
X, y = make_blobs(n_samples=50, n_features=2, centers=3, random_state=1)
X.shape # (50, 2)
y.shape # (50,)
dbscan = DBSCAN(eps=2, min_samples=5, metric="euclidean") # eps : 반경, min_samples : 최소
dbscan.fit(X)
dbscan.labels_
clusters = dbscan.fit_predict(X)
# 한글 깨짐 없이 나오게 설정
from matplotlib import rcParams # 인코딩 폰트 설정
rcParams['font.family'] = 'New Gulim'
rcParams['font.size'] = 10
plt.figure(figsize=(10,4))
plt.subplot(1,2,1)
plt.title("정답")
plt.scatter(X[:,0],X[:,1],c=y)
plt.subplot(1,2,2)
plt.title("추정")
plt.scatter(X[:,0],X[:,1],c=clusters)
plt.show()