【问题标题】:Is it possible to define the coordinates of centers with make_blobs?是否可以使用 make_blob 定义中心坐标?
【发布时间】:2020-06-22 12:48:41
【问题描述】:

我想用 sklearn.datasets 中的 make_blobs 创建 1 个中心为 (x,y) = (1,5) 的 blob。我目前使用以下脚本生成,但创建的 blob 设置为 x 和 y 中心在 1 到 5 之间随机设置。

from sklearn.datasets import make_blobs
X, y = make_blobs(n_samples=30, center_box=(1,5), cluster_std=0.05,centers=1)

我怎么能强制 blob 的中心为 (1,5)?

【问题讨论】:

    标签: python scikit-learn centering


    【解决方案1】:

    您可以在centers 参数中为您的 blob specify 任意数量的中心:

    centers: int 或形状数组 [n_centers, n_features],可选 (默认=无)要生成的中心数,或固定的中心位置。如果 n_samples 是一个 int 并且中心是 None,则生成 3 个中心。如果 n_samples 是类数组,则中心必须是 None 或长度等于 n_samples 长度的数组

    X, y = make_blobs(n_samples=300, n_features=2, cluster_std=.1
                      ,centers= [(1,5), (2,10)])
    plt.scatter(X[:,0],X[:,1], c=y);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-30
      • 2012-03-23
      • 1970-01-01
      • 1970-01-01
      • 2013-11-10
      • 1970-01-01
      • 1970-01-01
      • 2012-07-05
      相关资源
      最近更新 更多