IniziaInizia 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.

Questo esercizio fa parte del corso

Explainable AI in Python

Visualizza il corso

Istruzioni dell'esercizio

  • 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.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

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}')
Modifica ed esegui il codice