层次聚类的局限性

Python 中的聚类分析

Shaumik Daityari

Business Analyst

测量层次聚类的速度

  • timeit 模块
  • 测量 .linkage() 方法的速度
  • 使用随机生成的点
  • 运行多次以外推
Python 中的聚类分析

使用 timeit 模块

from scipy.cluster.hierarchy import linkage
import pandas as pd
import random, timeit

points = 100 df = pd.DataFrame({'x': random.sample(range(0, points), points), 'y': random.sample(range(0, points), points)})
%timeit linkage(df[['x', 'y']], method = 'ward', metric = 'euclidean')
1.02 ms ± 133 µs 每循环(7 次运行的均值 ± 标准差,每次 1000 循环)
Python 中的聚类分析

`.linkage()` 方法运行时间对比

  • 数据点越多,运行时间越长
  • 运行时间呈二次增长
  • 不适用于大型数据集

Python 中的聚类分析

接下来——练习

Python 中的聚类分析

Preparing Video For Download...