物流 eCommerce モデル:k-means 解析
モデル出力について最初の洞察が得られたので、クラスタ分析を使って、結果間のパターンや関係の理解をさらに深めましょう。
k-means アルゴリズムを使って、モデルの挙動を左右する主要な要因を把握し、性質が似たデータ点をグループに分類します。これにより、モデルが表している実世界の e-commerce/物流オペレーションにおけるボトルネックの特定に役立ちます。
kmeans と whiten は scipy.cluster.vq から、matplotlib.pyplot as plt もインポート済みです。元データセットとホワイトニング後のデータセットは、以下の列を持ちます。ダミー変数 p は、各データセットにおけるこれらのプロセスのインデックスを表します。
- 列 1(
p=0):time_requests - 列 2(
p=1):time_packaging - 列 3(
p=2):time_shipping - 列 4(
p=3):sum/total time
この演習はコースの一部です
Pythonで学ぶ離散事象シミュレーション
演習の手順
- k-means クラスタリングに備えて、
record_processes_np配列をホワイトニングしてください。 - SciPy パッケージを使って
whitened配列に対して k-means メソッドを実行し、3 つのクラスタを見つけるように設定してください。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# 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()