是否可以用 make_blobs 定义中心坐标?
Is it possible to define the coordinates of centers with make_blobs?
我想创建 1 个 blob,其中心为 (x,y) = (1,5),make_blobs 来自 sklearn.datasets。我目前使用以下脚本生成,但创建的 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)?
您可以 specify 在 centers
参数中为您的 blob 设置任意数量的中心:
centers
: int or array of shape [n_centers, n_features], optional
(default=None) The number of centers to generate, or the fixed center locations. If n_samples is an int and centers is None, 3 centers are generated. If n_samples is array-like, centers must be either None or an array of length equal to the length of 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);
我想创建 1 个 blob,其中心为 (x,y) = (1,5),make_blobs 来自 sklearn.datasets。我目前使用以下脚本生成,但创建的 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)?
您可以 specify 在 centers
参数中为您的 blob 设置任意数量的中心:
centers
: int or array of shape [n_centers, n_features], optional (default=None) The number of centers to generate, or the fixed center locations. If n_samples is an int and centers is None, 3 centers are generated. If n_samples is array-like, centers must be either None or an array of length equal to the length of 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);