使用python从sklearn中获取20news的数据为什么会出错呀?请各位帮我看一下,谢谢!(注:已安装sklearn)
代码如下:
from sklearn.datasets import fetch_20newsgroups
news = fetch_20newsgroups(data_home="D:\dev\python\python3.11.3\project\python-learn\machine_learning\data_13",subset="all")
运行的结果是在我的data_13文件夹下创建了一个名为20news_home的文件夹,但是里面什么东西都没有,上面程序的错误提示如下:
Traceback (most recent call last):
File "D:\dev\python\python3.11.3\project\python-learn\machine_learning\13.py", line 6, in <module>
news = fetch_20newsgroups(subset="all")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\dev\python\python3.11.3\Lib\site-packages\sklearn\utils\_param_validation.py", line 211, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "D:\dev\python\python3.11.3\Lib\site-packages\sklearn\datasets\_twenty_newsgroups.py", line 284, in fetch_20newsgroups
cache = _download_20newsgroups(
^^^^^^^^^^^^^^^^^^^^^^^
File "D:\dev\python\python3.11.3\Lib\site-packages\sklearn\datasets\_twenty_newsgroups.py", line 76, in _download_20newsgroups
archive_path = _fetch_remote(ARCHIVE, dirname=target_dir)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\dev\python\python3.11.3\Lib\site-packages\sklearn\datasets\_base.py", line 1388, in _fetch_remote
urlretrieve(remote.url, file_path)
File "D:\dev\python\python3.11.3\Lib\urllib\request.py", line 241, in urlretrieve
with contextlib.closing(urlopen(url, data)) as fp:
^^^^^^^^^^^^^^^^^^
File "D:\dev\python\python3.11.3\Lib\urllib\request.py", line 216, in urlopen
return opener.open(url, data, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\dev\python\python3.11.3\Lib\urllib\request.py", line 525, in open
response = meth(req, response)
^^^^^^^^^^^^^^^^^^^
File "D:\dev\python\python3.11.3\Lib\urllib\request.py", line 634, in http_response
response = self.parent.error(
^^^^^^^^^^^^^^^^^^
File "D:\dev\python\python3.11.3\Lib\urllib\request.py", line 563, in error
return self._call_chain(*args)
^^^^^^^^^^^^^^^^^^^^^^^
File "D:\dev\python\python3.11.3\Lib\urllib\request.py", line 496, in _call_chain
result = func(*args)
^^^^^^^^^^^
File "D:\dev\python\python3.11.3\Lib\urllib\request.py", line 643, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
请问各位这是什么问题导致的呀?我刚学机器学习没几天,不太懂这些提示什么意思
运行时遇到了HTTP 403 Forbidden错误,应该是由于无权访问所请求的资源而引起的。
在代码中,使用 fetch_20newsgroups()
函数从网络上下载新闻数据集,并将其保存在本地目录中。然而,由于某种原因,您的代码被服务器拒绝,并返回了HTTP 403错误。
请确保您的计算机可以正常连接到互联网,并且您具有下载和访问该数据集的权限。另外,还要注意检查您的防火墙或代理设置,确保它们不会阻止您的代码访问所需的资源。
都检查一下然后试试