Search code examples
pythonscikit-learncentering

Is it possible to define the coordinates of centers with make_blobs?


I would like to create 1 blob whose center would be (x,y) = (1,5) with make_blobs from sklearn.datasets. I currently use the following script to generate but the created blob is set with x and y centers randomly between 1 and 5.

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

How please could I force the center of the blob to be (1,5) ?


Solution

  • You may specify any number of centers for you blobs in centers param:

    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);
    

    enter image description here