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

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

问题描述

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

In NLTK there is a nltk.download() function to download the datasets that are comes with the NLP suite.

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

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.

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

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?

有没有例如下载例如$ code> 20newsgroups 数据集?

Is there an example of how to download e.g. the 20newsgroups dataset?

我已经安装了sklearn并尝试过这个,但是我得到了一个 IOError 。很可能是因为我没有从源头下载数据集。

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


推荐答案

连接问题可能已损坏驱动器上的源文件。从用户主目录中的 scikit_learn_data 文件夹中删除二十组相关文件或文件夹,然后重试。

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的数据集? - 蟒蛇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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