4
在NLTK中有一个nltk.download()
函数来下载NLP套件随附的数据集。如何下载sklearn的数据集? - python
在sklearn中,它讨论了加载数据集(http://scikit-learn.org/stable/datasets/)和从http://mldata.org/获取数据,但是对于其余数据集,指令要从源下载。
我应该在哪里保存从源代码下载的数据?在我可以从我的python代码调用之前,将数据保存到正确的目录后是否还有其他步骤?
是否有如何下载例如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 –
你有没有下载过数据? – alvas
from sklearn.datasets import fetch_20newsgroups将下载数据,如果它不在那里,我第一次尝试这个数据 –