簡體   English   中英

如何下載sklearn的數據集? -蟒蛇

[英]How to download datasets for sklearn? - python

在NLTK中,有一個nltk.download()函數來下載NLP套件隨附的數據集。

在sklearn中,它討論了如何加載數據集( http://scikit-learn.org/stable/datasets/ )和從http://mldata.org/中獲取數據,但是對於其余的數據集,說明是要下載的從源頭上

我應該在哪里保存從源下載的數據? 將數據保存到正確的目錄之后,可以從python代碼調用之前,還有其他步驟嗎?

有示例如何下載例如20newsgroups數據集嗎?

我已經安裝了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文件夾中刪除與二十組相關的文件或文件夾,然后重試。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM