階層式分群的限制

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 per loop (mean ± std. dev. of 7 runs, 1000 loops each)
Python 中的叢集分析

`.linkage()` 方法的執行時間比較

  • 資料點愈多,執行時間愈長
  • 執行時間呈平方成長
  • 不適用於大型資料集

Python 中的叢集分析

接下來-練習

Python 中的叢集分析

Preparing Video For Download...