在NLTK中,有一个nltk.download()
函数用于下载随NLP套件提供的数据集。
在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
回答:
网络连接问题可能已经损坏了您驱动器上的源存档。请从您用户主目录中的scikit_learn_data
文件夹中删除与twenty groups相关的文件或文件夹,然后再试一次。
$ cd ~/scikit_learn_data'$ rm -rf 20news_home$ rm 20news-bydate.pkz