如何下载 sklearn 的数据集?- Python [英] How to download datasets for sklearn? - python
问题描述
在 NLTK 中有一个 nltk.download()
函数来下载 NLP 套件附带的数据集.
在 sklearn 中,它谈到加载数据集(http://scikit-learn.org/stable/datasets/) 并从 http://mldata.org/ 获取数据,但对于其余的数据集,说明是从源下载.
我应该在哪里保存从源代码下载的数据? 将数据保存到正确目录后,我可以从我的 python 代码调用之前还有其他步骤吗?>
是否有下载示例,例如20newsgroups
数据集?
我已经 pip 安装了 sklearn 并尝试了这个,但是我遇到了 IOError
.很可能是因为我还没有从源代码下载数据集.
网络连接问题可能已损坏驱动器上的源存档.从您的用户主目录中的 scikit_learn_data
文件夹中删除二十个组相关文件或文件夹,然后重试.
$ cd ~/scikit_learn_data'$ rm -rf 20news_home$ rm 20news-bydate.pkz
In NLTK there is a nltk.download()
function to download the datasets that are comes with the NLP suite.
In sklearn, it talks about loading data sets (http://scikit-learn.org/stable/datasets/) and fetching datas from http://mldata.org/ but for the rest of the datasets, the instructions were to download from the source.
Where should I save the data that I've downloaded from the source? Are there any other steps after I save the data into the correct directory before I can call from my python code?
Is there an example of how to download e.g. the 20newsgroups
dataset?
I've pip installed sklearn and tried this but I got an IOError
. Most probably because I haven't downloaded the dataset from the source.
>>> 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
A network connection problem has probably corrupted the source archive on your drive. Delete the twenty groups related files or folders from you scikit_learn_data
folder in your user's home directory and try again.
$ cd ~/scikit_learn_data'
$ rm -rf 20news_home
$ rm 20news-bydate.pkz
这篇关于如何下载 sklearn 的数据集?- Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!