开始使用免费开始使用

物流电商模型:k-means 分析

现在,您已经对模型输出有了初步了解,可以通过聚类分析来加深对结果中模式和关系的理解。

您将使用 k-means 算法来帮助理解模型行为的主要控制因素,并将数据点按相似属性分组。这将有助于识别您的模型所代表的现实电商/物流运营中的瓶颈。

kmeanswhiten 已从 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 中的离散事件模拟

查看课程

练习说明

  • record_processes_np 数组进行白化,以便为 k-means 聚类做准备。
  • 使用 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()
编辑并运行代码