机器学习训练营——机器学习爱好者的自由交流空间(入群联系qq:2279055353)
这个例子演示不同的聚类算法用于6个标准数据集(toy datasets)聚类上的特性。这6个数据集分别是:
-
noisy_circles
: 数据点围成大小两个同心圈状。 -
noisy_moons
: 数据点构成两个交错的半圆。 -
blobs
: 数据点形如团状高斯块。 -
varied
: 可变方差的数据块。 -
aniso
: 各向异性分布的数据块。 -
no_structure
: 均匀分布的数据。
使用的聚类算法是:
-
MiniBatchKMeans
-
AP聚类
-
MeanShift
-
谱聚类
-
Ward
聚类 -
层次聚类
-
DBSCAN
聚类 -
Birch
聚类 -
高斯混合模型聚类
除了最后一个数据集no_structure
, 每一对数据集-算法的参数都被优化到产生最佳的聚类结果。我们发现,一些算法对参数是敏感的。no_structure数据集是一个null
情形的例子。数据是同分布的,所以没有好的聚类结果。
实例代码
import time
import warnings
import numpy as np
import matplotlib.pyplot as plt
from sklearn import cluster, datasets, mixture
from sklearn.neighbors import kneighbors_graph
from sklearn.preprocessing import StandardScaler
from itertools import cycle, islice
np.random.seed(0)
# ============
# Generate datasets. We choose the size big enough to see the scalability
# of the algorithms, but not too big to avoid too long running times
# =