当前位置: 首页 > news >正文

导入fetch_california_housing 加州房价数据集报错解决(HTTPError: HTTP Error 403: Forbidden)

报错

HTTPError                                 Traceback (most recent call last)
Cell In[3], line 52 from sklearn.datasets import fetch_california_housing3 from sklearn.model_selection import train_test_split
----> 5 X, Y = fetch_california_housing(return_X_y=True)6 print(X.shape), # (20640, 8)7 print(Y.shape) #  (20640, )File ~\miniconda3\lib\site-packages\sklearn\datasets\_california_housing.py:138, in fetch_california_housing(data_home, download_if_missing, return_X_y, as_frame)132     raise IOError("Data not found and `download_if_missing` is False")134 logger.info(135     "Downloading Cal. housing from {} to {}".format(ARCHIVE.url, data_home)136 )
--> 138 archive_path = _fetch_remote(ARCHIVE, dirname=data_home)140 with tarfile.open(mode="r:gz", name=archive_path) as f:141     cal_housing = np.loadtxt(142         f.extractfile("CaliforniaHousing/cal_housing.data"), delimiter=","143     )File ~\miniconda3\lib\site-packages\sklearn\datasets\_base.py:1324, in _fetch_remote(remote, dirname)1302 """Helper function to download a remote dataset into path1303 1304 Fetch a dataset pointed by remote's url, save into path using remote's(...)1320     Full path of the created file.1321 """1323 file_path = remote.filename if dirname is None else join(dirname, remote.filename)
-> 1324 urlretrieve(remote.url, file_path)1325 checksum = _sha256(file_path)1326 if remote.checksum != checksum:File ~\miniconda3\lib\urllib\request.py:241, in urlretrieve(url, filename, reporthook, data)224 """225 Retrieve a URL into a temporary location on disk.226 (...)237 data file as well as the resulting HTTPMessage object.238 """239 url_type, path = _splittype(url)
--> 241 with contextlib.closing(urlopen(url, data)) as fp:242     headers = fp.info()244     # Just return the local path and the "headers" for file://245     # URLs. No sense in performing a copy unless requested.File ~\miniconda3\lib\urllib\request.py:216, in urlopen(url, data, timeout, cafile, capath, cadefault, context)214 else:215     opener = _opener
--> 216 return opener.open(url, data, timeout)File ~\miniconda3\lib\urllib\request.py:525, in OpenerDirector.open(self, fullurl, data, timeout)523 for processor in self.process_response.get(protocol, []):524     meth = getattr(processor, meth_name)
--> 525     response = meth(req, response)527 return responseFile ~\miniconda3\lib\urllib\request.py:634, in HTTPErrorProcessor.http_response(self, request, response)631 # According to RFC 2616, "2xx" code indicates that the client's632 # request was successfully received, understood, and accepted.633 if not (200 <= code < 300):
--> 634     response = self.parent.error(635         'http', request, response, code, msg, hdrs)637 return responseFile ~\miniconda3\lib\urllib\request.py:563, in OpenerDirector.error(self, proto, *args)561 if http_err:562     args = (dict, 'default', 'http_error_default') + orig_args
--> 563     return self._call_chain(*args)File ~\miniconda3\lib\urllib\request.py:496, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)494 for handler in handlers:495     func = getattr(handler, meth_name)
--> 496     result = func(*args)497     if result is not None:498         return resultFile ~\miniconda3\lib\urllib\request.py:643, in HTTPDefaultErrorHandler.http_error_default(self, req, fp, code, msg, hdrs)642 def http_error_default(self, req, fp, code, msg, hdrs):
--> 643     raise HTTPError(req.full_url, code, msg, hdrs, fp)HTTPError: HTTP Error 403: Forbidden

先手动下载数据(https://www.dcc.fc.up.pt/~ltorgo/Regression/cal_housing.tgz)

在这里插入图片描述
PS

  1. 报错文件 File ~\miniconda3\lib\site-packages\sklearn\datasets\_california_housing.py:138, in fetch_california_housing(data_home, download_if_missing, return_X_y, as_frame)在这里插入图片描述

  2. 找到文件打开,43行有下载地址在这里插入图片描述

  3. 复制下载后的cal_housing.tgz文件到指定文件夹,无需解压。需要复制到的文件夹需要从代码里获取,获取代码如下:
    在这里插入图片描述在这里插入图片描述
    4.更改 _california_housing.py文件,将def fetch_california_housing()这个函数内的archive_path这段代码更改为如下在这里插入图片描述

重启 jupyter notebook即可,Windows系统也相同操作

http://www.lryc.cn/news/318289.html

相关文章:

  • 后勤管理系统|基于SSM 框架+vue+ Mysql+Java+B/S架构技术的后勤管理系统设计与实现(可运行源码+数据库+设计文档+部署说明+视频演示)
  • 【办公类-40-01】20240311 用Python将MP4转MP3提取音频 (家长会系列一)
  • 人类的谋算与量子计算
  • 【数据结构和算法初阶(C语言)】栈的概念和实现(后进先出---后来者居上的神奇线性结构带来的惊喜体验)
  • 搭建mysql主从复制(主主复制)
  • centos 系统 yum 无法安装(换国内镜像地下)
  • 【python绘图】turle 绘图基本案例
  • 损失函数和反向传播
  • Nginx:配置拦截/禁用ip地址
  • css超出部分显示省略号
  • python-0001-安装虚拟环境
  • Python爬虫:原理与实战
  • C# danbooru Stable Diffusion 提示词反推 Onnx Demo
  • Windows系统搭建Cloudreve结合内网穿透打造可公网访问的私有云盘
  • upload-labs 0.1 靶机详解
  • react 综合题-旧版
  • 基于ElasticSearch存储海量AIS数据:AIS数据索引机制篇
  • IDEA中返回上一步和下一步快捷键失效【Ctrl+Alt+左箭头】
  • Hubspot 2023年推荐使用的11个AI视频生成器
  • Python 导入Excel三维坐标数据 生成三维曲面地形图(体) 5-2、线条平滑曲面且可通过面观察柱体变化(二)
  • [2024年]-flink面试真题(四)
  • 基于SpringBoot+Druid实现多数据源:原生注解式
  • AJAX 03 XMLHttpRequest、Promise、封装简易版 axios
  • 如何将办公资料文件生成二维码?扫码可看详情
  • 【Streamlit学习笔记】实现包含多个sheet的excel文件下载
  • [Redis]——主从同步原理(全量同步、增量同步)
  • Buildroot 之二 详解构建架构、流程、external tree、示例
  • 牛客小白月赛61-C-小喵觅食
  • 200 名专家编写报告:AI 发展可能对人类构成「灭绝级威胁」
  • 学习Android的第二十九天