three_blobs_data: 用于分类的合成团状数据
一个将 three_blobs
数据集加载到 NumPy 数组的函数。
from mlxtend.data import three_blobs_data
概述
一个用于聚类的随机 3 个 2D 团状数据集。
- 样本数: 150
- 建议标签{0, 1, 2}, 分布: [50, 50, 50]
参考资料
示例 1 - 数据集概述
from mlxtend.data import three_blobs_data
X, y = three_blobs_data()
print('Dimensions: %s x %s' % (X.shape[0], X.shape[1]))
print('1st row', X[0])
Dimensions: 150 x 2
1st row [ 2.60509732 1.22529553]
import numpy as np
print('Suggested cluster labels')
print(np.unique(y))
print('Label distribution: %s' % np.bincount(y))
Suggested cluster labels
[0 1 2]
Label distribution: [50 50 50]
import matplotlib.pyplot as plt
plt.scatter(X[:,0], X[:,1],
c='white',
marker='o',
s=50)
plt.grid()
plt.show()
plt.scatter(X[y == 0, 0],
X[y == 0, 1],
s=50,
c='lightgreen',
marker='s',
label='cluster 1')
plt.scatter(X[y == 1,0],
X[y == 1,1],
s=50,
c='orange',
marker='o',
label='cluster 2')
plt.scatter(X[y == 2,0],
X[y == 2,1],
s=50,
c='lightblue',
marker='v',
label='cluster 3')
plt.legend(loc='lower left')
plt.grid()
plt.show()
API
three_blobs_data()
一个用于聚类的随机 3 个 2D 团状数据集。
-
样本数
: 150 -
Suggested labels
: {0, 1, 2}, 分布: [50, 50, 50]
返回
-
X, y
: [样本数, 特征数], [聚类标签数]X 是特征矩阵,包含 159 个样本作为行,2 个特征作为列。y 是一个一维数组,包含 3 个建议的聚类标签 0, 1, 2
示例
用法示例请参阅 https://mlxtend.cn/mlxtend/user_guide/data/three_blobs_data