その他のクラスタリングによる不正検知手法

Pythonで学ぶ不正検知

Charlotte Werger

Data Scientist

クラスタリング手法はいくつもある

Pythonで学ぶ不正検知

不正の検知方法も多様:最小クラスタを使う

Pythonで学ぶ不正検知

実際はこのようになることが多い

Pythonで学ぶ不正検知

DBSCAN と K-means の比較

  • クラスタ数を事前指定不要
  • クラスタ内の最大距離を調整
  • クラスタ内の最小サンプル数を設定
  • いびつな形状のデータに強い
  • ただし計算コストは高い
Pythonで学ぶ不正検知

DBSCAN の実装

from sklearn.cluster import DBSCAN
db = DBSCAN(eps=0.5, min_samples=10, n_jobs=-1).fit(X_scaled)

# Get the cluster labels (aka numbers) pred_labels = db.labels_
# Count the total number of clusters n_clusters_ = len(set(pred_labels)) - (1 if -1 in pred_labels else 0) # Print model results print('Estimated number of clusters: %d' % n_clusters_)
Estimated number of clusters: 31
Pythonで学ぶ不正検知

クラスタのサイズを確認する

# Print model results
print("Silhouette Coefficient: %0.3f" % metrics.silhouette_score(X_scaled, pred_labels))
Silhouette Coefficient: 0.359
# Get sample counts in each cluster 
counts = np.bincount(pred_labels[pred_labels>=0])
print (counts)
[ 763  496  840  355 1086  676   63  306  560  134   28   18  262  128  332  22  
   22   13   31   38   36   28   14   12   30   10   11   10   21   10    5]
Pythonで学ぶ不正検知

練習してみましょう!

Pythonで学ぶ不正検知

Preparing Video For Download...