【问题标题】:How to download datasets for sklearn? - python如何下载 sklearn 的数据集? - Python
【发布时间】:2023-03-08 07:24:02
【问题描述】:

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

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

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

是否有如何下载的示例,例如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 对我来说效果很好
  • 你之前下载过数据吗?
  • from sklearn.datasets import fetch_20newsgroups 将下载数据,如果它不存在,我现在第一次尝试这个

标签: python machine-learning dataset nlp scikit-learn


【解决方案1】:

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

$ cd ~/scikit_learn_data'
$ rm -rf 20news_home
$ rm 20news-bydate.pkz

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-12
    • 2022-12-21
    • 2016-06-25
    • 1970-01-01
    • 2017-05-11
    • 2022-11-16
    • 2019-10-24
    相关资源
    最近更新 更多