물류 eCommerce 모델: k-평균 분석
모델 출력에 대한 첫 인사이트를 얻었으니, 이제 클러스터 분석을 통해 결과들 사이의 패턴과 관계를 더 깊이 이해해 보세요.
k-평균 알고리즘을 사용해 모델 동작의 주요 제어 요인을 파악하고, 비슷한 성질을 가진 데이터 포인트를 그룹으로 분류할 거예요. 이는 모델이 표현하는 실제 전자상거래/물류 운영에서의 병목 지점을 식별하는 데 도움이 됩니다.
kmeans와 whiten은 scipy.cluster.vq에서, 그리고 matplotlib.pyplot as plt가 이미 임포트되어 있어요. 원본과 whitened 데이터셋에는 아래와 같은 열 데이터가 포함되어 있습니다. 더미 변수 p는 데이터셋에서 각 프로세스의 인덱스를 나타냅니다.
- 열 1 (
p=0):time_requests - 열 2 (
p=1):time_packaging - 열 3 (
p=2):time_shipping - 열 4 (
p=3):sum/total time
이 연습은 강의의 일부입니다
Python으로 배우는 이산 사건 시뮬레이션
연습 안내
- k-평균 클러스터링을 준비하기 위해
record_processes_np배열을 whiten 하세요. - SciPy 패키지를 사용해
whitened배열에서 k-평균 메서드를 실행하고, 세 개의 클러스터를 찾도록 설정하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Whiten the record_processes_np array
whitened = ____(record_processes_np)
# Run the k-means method on whitened, using three clusters
codebook, distortion = ____(whitened, ____)
fig, axs = plt.subplots(3)
for p in range(3):
axs[p].scatter(whitened[:, 3], whitened[:, p], marker=".", label=f"{process_names[p]}")
axs[p].scatter(codebook[:, 3], codebook[:, p], label='Cluster Centroids')
axs[p].legend(loc='center left', bbox_to_anchor=(1, 0.5))
axs[p].set_ylabel(f'Process duration (days)')
axs[p].set_xlabel('Total duration (days)')
plt.show()