如何下载 sklearn 的数据集?- Python [英] How to download datasets for sklearn? - python

查看:184
本文介绍了如何下载 sklearn 的数据集?- Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 NLTK 中有一个 nltk.download() 函数来下载 NLP 套件附带的数据集.

在 sklearn 中,它谈到加载数据集(http://scikit-learn.org/stable/datasets/) 并从 http://mldata.org/ 获取数据,但对于其余的数据集,说明是从源下载.

我应该在哪里保存从源代码下载的数据? 将数据保存到正确目录后,我可以从我的 python 代码调用之前还有其他步骤吗?>

是否有下载示例,例如20newsgroups 数据集?

我已经 pip 安装了 sklearn 并尝试了这个,但是我遇到了 IOError.很可能是因为我还没有从源代码下载数据集.

<预><代码>>>>从 sklearn.datasets 导入 fetch_20newsgroups>>>fetch_20newsgroups(subset='train')回溯(最近一次调用最后一次):文件<stdin>",第 1 行,在 <module> 中文件/usr/local/lib/python2.7/dist-packages/sklearn/datasets/twenty_newsgroups.py",第 207 行,在 fetch_20newsgroups缓存路径=缓存路径)文件/usr/local/lib/python2.7/dist-packages/sklearn/datasets/twenty_newsgroups.py",第89行,在download_20newsgroupstarfile.open(archive_path, "r:gz").extractall(path=target_dir)文件/usr/lib/python2.7/tarfile.py",第 1678 行,打开返回函数(名称,文件模式,文件对象,**kwargs)文件/usr/lib/python2.7/tarfile.py",第 1727 行,在 gzopen 中**夸格)taropen 中的文件/usr/lib/python2.7/tarfile.py",第 1705 行返回 cls(name, mode, fileobj, **kwargs)文件/usr/lib/python2.7/tarfile.py",第 1574 行,在 __init__ 中self.firstmember = self.next()文件/usr/lib/python2.7/tarfile.py",第 2334 行,在下一个引发读取错误(空文件")tarfile.ReadError: 空文件

解决方案

网络连接问题可能已损坏驱动器上的源存档.从您的用户主目录中的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆