开始使用免费开始使用

为聚类生成数据集

合成数据完全合法,并符合全球各地隐私法律法规的要求。它是原始数据的合规且注重隐私的替代方案。make_blobs() 函数可用于生成符合高斯(或正态)分布的数据点。

在本练习中,您将生成一个包含 15000 个样本的数据集。

numpy 已以 np 导入,且已再次为本练习提供自定义函数 plot_data_points()

本练习是课程的一部分

Python 中的数据隐私与匿名化

查看课程

练习说明

  • datasets 模块中导入用于生成聚类数据集的相应函数。
  • 生成一个包含 15000 个样本、2 个特征、2 个中心、簇标准差为 3 的数据集。
  • 打印生成数据的形状。
  • 在二维散点图中查看生成的数据点。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Import the function from the datasets module for generating clustering datasets
from sklearn.datasets import ____

# Generate a dataset with 15000 rows, 2 features, 2 centers, and a cluster std of 3
x, labels = ____

# Print the shape of the resulting generated data
print(____)

# See the resulting data points in a 2 dimensional scatter plot
plot_data_points(x, labels)
编辑并运行代码