MulaiMulai sekarang secara gratis

Feature importance in clustering with ARI

Leverage the Adjusted Rand Index (ARI) to quantitatively measure the impact of each feature's removal on cluster assignments in the customer dataset you've worked with in the previous exercise, pre-loaded in X.

The adjusted_rand_score() function and the column_names variable have been pre-loaded for you.

Latihan ini adalah bagian dari kursus

Explainable AI in Python

Lihat Kursus

Petunjuk latihan

  • Derive the original cluster assignments in original_clusters.
  • In the for loop, remove features one by one and save the result in X_reduced.
  • Derive the reduced_clusters by applying K-means on X_reduced.
  • Compute the feature importance based on ARI between the reduced_clusters and the original_clusters.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

kmeans = KMeans(n_clusters=5, random_state=10, n_init=10).fit(X)
# Derive original clusters
original_clusters = ____

for i in range(X.shape[1]):
  	# Remove feature at index i
    X_reduced = ____
    # Derive reduced clusters
    reduced_clusters = ____
    # Derive feature importance
    importance = ____
    print(f'{column_names[i]}: {importance}')
Edit dan Jalankan Kode