시작하기무료로 시작하기

도매 데이터 다시 보기: 탐색

이전 분석에서 k = 2일 때 평균 실루엣 너비가 가장 높다는 것을 확인했어요. 이번 연습 문제에서는 2개의 클러스터로 kmeans 모델을 만들고 탐색하면서 도매 고객 데이터를 계속 분석해 보겠습니다.

이 연습은 강의의 일부입니다

R로 배우는 군집 분석

강의 보기

연습 안내

  • centers = 2kmeans() 함수를 사용해 customers_spend 데이터에 대한 k-평균 모델 model_customers를 만드세요.
  • 모델에서 클러스터 할당 벡터 model_customers$cluster를 추출해 변수 clust_customers에 저장하세요.
  • 클러스터 할당을 열 clustercustomers_spend 데이터 프레임에 추가하고, 결과를 새 데이터 프레임 segment_customers에 저장하세요.
  • count()를 사용해 각 클러스터의 크기를 계산하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

set.seed(42)

# Build a k-means model for the customers_spend with a k of 2
model_customers <- ___

# Extract the vector of cluster assignments from the model
clust_customers <- ___

# Build the segment_customers data frame
segment_customers <- mutate(___, cluster = ___)

# Calculate the size of each cluster
count(___, ___)

# Calculate the mean for each category
segment_customers %>% 
  group_by(cluster) %>% 
  summarise_all(list(mean))
코드 편집 및 실행