Contents

1
2
3 谿瑚


1 #

DBSCAN(min_sample, eps) 蟲一 螻襴讀願, 襷り覲螳 2螳.
  • min_sample
  • eps

れ螻 螳.
  1. れ朱 一危 誤碁ゼ 觸螻, 一危 誤語 eps(epsilon) 蟇磯Μ(蠍磯蓋螳 企Μ 蟇磯Μ) 一危 誤碁ゼ 谿城.
  2. 襷 谿場 誤瑚 min_sample覲企 朱 noise襦 豌襴螻, min_sample覲企 襷朱 襦 企ろ 企
  3. 襦 企ろ一 豪 誤碁れ eps 蟇磯Μ 覈 伎 谿場 企ろ 企 豪讌 る 企ろ一 .
  4. 伎 一危 瑚 朱 企ろ 企 豪讌 一危 誤碁れ 1~3 覦覲


  • k-means 襷 k襯 蟆一讌 .
  • 襷り覲(min_sample, eps)襯 譟一覃 るジ 企ろ磯 覦覯覲企 一 蟆郁骸襯 詞 .


  • 譬 襴.
  • 企ろ郁 襷 蠍 . --> eps, min_sample 譟一伎 .

2 #

#two_moon 一危 
from sklearn.datasets import make_moons
import pandas as pd
X, y = make_moons(n_samples=200, noise=0.05, random_state=0)

df = pd.DataFrame(X, columns=["x", "y"])
df["group"] = y
df[:5]

#import matplotlib.pyplot as plt
#plt.scatter(x=df.x, y=df.y, c=df.group)

#<scatter plot>: 蠍磯
import matplotlib.pyplot as plt
plt.scatter(x=df.x, y=df.y, c=df.group)

fig, ax = plt.subplots()
colors = {1:'red', 0:'blue'}

grouped = df.groupby('group')
for key, group in grouped:
    group.plot(ax=ax, kind='scatter', x='x', y='y', label=key, color=colors[key])
plt.show()
#</scatter plot>: 蠍郁讌 覯 ろ


#譴(蠏=0, 覿=1)
from sklearn.preprocessing import StandardScaler
scale = StandardScaler()
scale.fit(df[["x", "y"]])
scaled_X = scale.transform(df[["x", "y"]])

df["scaled_x"] = scaled_X[:,0]
df["scaled_y"] = scaled_X[:,1]

#DBSCAN
from sklearn.cluster import DBSCAN
dbscan = DBSCAN(eps=0.5, min_samples=5) #蠍磯蓋螳企.
cluster = dbscan.fit_predict(scaled_X)
df["cluster"] = cluster

#clustering 蟆郁骸 
plt.scatter(x=df.scaled_x, y=df.scaled_y, c=df.cluster)
plt.xlabel("x")
plt.ylabel("y")

蟆郁骸
dbscan.png

3 谿瑚 #