Sklearn产生无负值的斑点

时间:2018-08-24 08:58:31

标签: python scikit-learn

我正在尝试使用make_blobs函数生成五个群集。 我的问题是生成的点包含负值,但我希望不包含负值。

这是我当前的代码:

X, y = make_blobs(n_samples=2647, n_features=2, centers=6, 
       cluster_std=1.5, shuffle=True, random_state=20000)

这是我绘制的数据:

plotted data

我试图将每个观察值乘以某个值,但是问题是,在0附近会有一个点的“直线”,并且观察值不会自然减少。

我该如何实现?或更妙的是,如何将我的所有观测值上移至例如1000?

1 个答案:

答案 0 :(得分:1)

幸运的是,您可以使用make_blobs来执行此操作,而无需手动移动它,可以使用center_box参数。

center_box = (100, 200) # defines the box that cluster centres are allowed to be in
standard_dev = 15 # defines the standard deviation of clusters
X, y = make_blobs(n_samples=200, n_features=2, center_box=center_box, cluster_std=standard_dev)

fig, ax = plt.subplots()
ax.scatter(X[:, 0], X[:, 1], c=y)

enter image description here

但是,如果您希望将所有功能都从零开始,则只需使用X -= X.min(axis=0)即可。