【发布时间】:2023-03-08 07:24:02
【问题描述】:
在 NLTK 中有一个 nltk.download() 函数可以下载 NLP 套件附带的数据集。
在 sklearn 中,它谈到了加载数据集 (http://scikit-learn.org/stable/datasets/) 和从 http://mldata.org/ 获取数据,但对于其余数据集,说明是从源下载。
我应该将我从源下载的数据保存在哪里?在我将数据保存到正确的目录之后,我可以从我的 python 代码调用之前是否还有其他步骤? p>
是否有如何下载的示例,例如20newsgroups 数据集?
我已经 pip 安装了 sklearn 并尝试了这个,但我得到了一个 IOError。很可能是因为我还没有从源头下载数据集。
>>> from sklearn.datasets import fetch_20newsgroups
>>> fetch_20newsgroups(subset='train')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/sklearn/datasets/twenty_newsgroups.py", line 207, in fetch_20newsgroups
cache_path=cache_path)
File "/usr/local/lib/python2.7/dist-packages/sklearn/datasets/twenty_newsgroups.py", line 89, in download_20newsgroups
tarfile.open(archive_path, "r:gz").extractall(path=target_dir)
File "/usr/lib/python2.7/tarfile.py", line 1678, in open
return func(name, filemode, fileobj, **kwargs)
File "/usr/lib/python2.7/tarfile.py", line 1727, in gzopen
**kwargs)
File "/usr/lib/python2.7/tarfile.py", line 1705, in taropen
return cls(name, mode, fileobj, **kwargs)
File "/usr/lib/python2.7/tarfile.py", line 1574, in __init__
self.firstmember = self.next()
File "/usr/lib/python2.7/tarfile.py", line 2334, in next
raise ReadError("empty file")
tarfile.ReadError: empty file
【问题讨论】:
-
使用 sklearn 0.14 对我来说效果很好
-
你之前下载过数据吗?
-
from sklearn.datasets import fetch_20newsgroups 将下载数据,如果它不存在,我现在第一次尝试这个
标签: python machine-learning dataset nlp scikit-learn