Import make_blobs from scikit-learn

Viewed 7792

I am getting next Warning:

D:\Programming\Python\ML\venv\lib\site-packages\sklearn\utils\deprecation.py:77: DeprecationWarning: Function make_blobs is deprecated; Please import make_blobs directly from scikit-learn
warnings.warn(msg, category=DeprecationWarning)

even with this

from sklearn.datasets.samples_generator import make_blobs

And my simple code

# generate dataset
X, y = mglearn.datasets.make_forge()
# plot dataset
mglearn.discrete_scatter(X[:, 0], X[:, 1], y)
plt.legend(["Class 0", "Class 1"], loc=4)
plt.xlabel("First feature")
plt.ylabel("Second feature")
print("X.shape: {}".format(X.shape))
plt.show()

Function make_forge()

def make_forge():
# a carefully hand-designed dataset lol
X, y = make_blobs(centers=2, random_state=4, n_samples=30)
y[np.array([7, 27])] = 0
mask = np.ones(len(X), dtype=np.bool)
mask[np.array([0, 1, 5, 26])] = 0
X, y = X[mask], y[mask]
return X, y

Well, in make_blobs.py I found next thing

@deprecated("Please import make_blobs directly from scikit-learn")
def make_blobs(n_samples=100, n_features=2, centers=2, cluster_std=1.0,
           center_box=(-10.0, 10.0), shuffle=True, random_state=None):

Yes, I know that my code will successfully compile even with this warning but I want to know why I'm getting this and why this is deprecated.

2 Answers

Use the following to import make_blobs that will not give you any warning.

from sklearn.datasets import make_blobs
  1. import make_blobs: from sklearn.datasets import make_blobs
  2. Replace this line: X, y = mglearn.datasets.make_forge() with this line: X,y = make_blobs()
  3. Run your program
Related