클러스터 품질에 대한 특성 영향
개별 특성이 KMeans 모델의 클러스터링 성능에 어떤 영향을 미치는지 살펴보세요. 데이터셋 X는 소득, 자녀 수, 집에 있는 청소년 수의 세 가지 특성으로 고객 세분화를 수행합니다.
silhouette_score 함수와 column_names 변수는 미리 로드되어 있습니다.
이 연습은 강의의 일부입니다
Python으로 배우는 Explainable AI
연습 안내
- 원래의 실루엣 점수(
original_score)를 구하세요. - for 루프에서 특성을 하나씩 제거하고 결과를
X_reduced에 저장하세요. - 새로운 실루엣 점수(
new_score)를 계산하세요. - 해당 특성의
impact를 계산하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
kmeans = KMeans(n_clusters=5, random_state=10, n_init=10).fit(X)
# Derive the original silhouette score
original_score = ____
for i in range(X.shape[1]):
# Remove feature at index i
X_reduced = ____
kmeans.fit(X_reduced)
# Compute the new silhouette score
new_score = ____
# Compute the feature's impact
impact = ____
print(f'Feature {column_names[i]}: Impact = {impact}')