问题描述
尝试创建 4 个随机数据簇时,我收到以下错误消息:
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)
错误:
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'
我尝试过:pip install sckit-learn
和 pip install sckit-datasets
我在 Windows 上的 Git Bash 上有 Anaconda 3、python 3.6 和 PythonAdv 环境.
I have Anaconda 3, python 3.6 and PythonAdv environments on Git Bash on Windows.
推荐答案
在最新版本的 scikit-learn 中,没有模块 sklearn.datasets.samples_generator
- 它已被替换为 sklearn.datasets
(请参阅文档);因此,根据 make_blobs
文档,你的导入应该是:
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.
这篇关于没有名为“sklearn.datasets.samples_generator"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!