教師なしモデルの説明

Pythonで学ぶExplainable AI

Fouad Trad

Machine Learning Engineer

クラスタリング

事前ラベルなしで類似データ点をグループ化

2特徴のデータが3クラスタに分かれ、各クラスタに重心がある図。

Pythonで学ぶExplainable AI

シルエットスコア

  • クラスタリングの品質を測る
  • -1 から 1 の範囲
    • 1 → よく分離したクラスタ

よく分離したクラスタを示す画像。

Pythonで学ぶExplainable AI

シルエットスコア

  • クラスタリングの品質を測る
  • -1 から 1 の範囲
    • 1 → よく分離したクラスタ
    • -1 → 誤った割当

明確な分離がないクラスタを示す画像。

Pythonで学ぶExplainable AI

クラスタ品質への特徴量の影響

2特徴のデータをクラスタリングした結果を示す画像。

Pythonで学ぶExplainable AI

クラスタ品質への特徴量の影響

特徴量を1つ除去して再学習した後のクラスタリング結果を示す画像。

Pythonで学ぶExplainable AI

クラスタ品質への特徴量の影響

除去した特徴量の影響を、全特徴ありのシルエットと除去時のシルエットの差で表す式を示す画像。

  • $\text{Impact(}f) > 0$ → $f$ は正の寄与
  • $\text{Impact(}f) < 0$ → $f$ はノイズを導入
Pythonで学ぶExplainable AI

Student Performance データセット

age health status absences G1 G2 G3
18 3 4 0 11 11
17 3 2 9 11 11
15 3 6 12 13 12
15 5 0 14 14 14
16 5 0 11 13 13

 

X: 特徴量を含む配列

Pythonで学ぶExplainable AI

クラスタ品質への特徴量影響の算出

from sklearn.cluster import KMeans
from sklearn.metrics import silhouette_score


kmeans = KMeans(n_clusters=2).fit(X)
original_score = silhouette_score(X, kmeans.labels_)
for i in range(X.shape[1]):
X_reduced = np.delete(X, i, axis=1)
kmeans.fit(X_reduced)
new_score = silhouette_score(X_reduced, kmeans.labels_)
impact = original_score - new_score print(f'Feature {column_names[i]}: Impact = {impact}')
Pythonで学ぶExplainable AI

クラスタ品質への特徴量影響の算出

Feature age: Impact = 0.05199181662741281
Feature health status: Impact = 0.06046737420227638
Feature absences: Impact = 0.031290940582026694
Feature G1: Impact = -0.025746421940652353
Feature G2: Impact = -0.02578292339364119
Feature G3: Impact = -0.03163419458330158
Pythonで学ぶExplainable AI

Adjusted Rand Index (ARI)

  • クラスタ割当の一致度を測る

同一データに対する類似したクラスタ割当を示す画像。

  • 最大 ARI = 1 → 完全一致
Pythonで学ぶExplainable AI

Adjusted Rand Index (ARI)

  • クラスタ割当の一致度を測る

同一データに対する異なるクラスタ割当を示す画像。

  • 最大 ARI = 1 → 完全一致
  • ARI が低いほど → 差が大きい
Pythonで学ぶExplainable AI

クラスタ割当に対する特徴量の重要度

   

  • 特徴量を1つずつ除去
  • $\text{Importance}(f) = 1 - \text{ARI (original clusters, modifed clusters)}$
  • 低い $\text(ARI)$ → 高い $\text(1 - ARI)$ → 重要な特徴量
Pythonで学ぶExplainable AI

クラスタ割当に対する特徴量の重要度

from sklearn.metrics import adjusted_rand_score

kmeans = KMeans(n_clusters=2).fit(X) original_clusters = kmeans.predict(X)
for i in range(X.shape[1]):
X_reduced = np.delete(X, i, axis=1)
reduced_clusters = kmeans.fit_predict(X_reduced)
importance = 1 - adjusted_rand_score(original_clusters, reduced_clusters) print(f'{df.columns[i]}: {importance}')
age: 0.0
health status: 0.9995376368119572
absences: 0.0
G1: 0.0
G2: 0.6204069909514572
G3: 0.6204069909514572
Pythonで学ぶExplainable AI

演習に進みましょう!

Pythonで学ぶExplainable AI

Preparing Video For Download...