Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
348 views
in Technique[技术] by (71.8m points)

python - Which pip install package is required for Module sklearn.datasets.samples_generator import make_blobs?

When trying to create 4 clusters of random data, I am getting the following error message:

# Generate 4 clusters of random data.
from sklearn.datasets.samples_generator import make_blobs

data, _ = make_blobs(n_samples=300, centers=4,
                     cluster_std=0.60, random_state=0)

Error:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-f93335003f84> in <module>
      1 # Generate 4 clusters of random data.
----> 2 from sklearn.datasets.samples_generator import make_blobs
      3 
      4 data, _ = make_blobs(n_samples=300, centers=4,
      5                      cluster_std=0.60, random_state=0)

ModuleNotFoundError: No module named 'sklearn.datasets.samples_generator'

I have tried: pip install sckit-learn and pip install sckit-datasets

I have Anaconda 3, python 3.6 and PythonAdv environments on Git Bash on Windows.

question from:https://stackoverflow.com/questions/65898399/which-pip-install-package-is-required-for-module-sklearn-datasets-samples-genera

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In the latest versions of scikit-learn, there is no module sklearn.datasets.samples_generator - it has been replaced with sklearn.datasets (see the docs); so, according to the make_blobs documentation, your import should simply be:

from sklearn.datasets import make_blobs

As a general rule, the official documentation is your best friend, and you should definitely consult it first before anything else.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...