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

news/2024/7/9 8:36:25 标签: sklearn, 机器学习

报错

HTTPError                                 Traceback (most recent call last)
Cell In[3], line 5
      2 from sklearn.datasets import fetch_california_housing
      3 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 path
   1303 
   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 response

File ~\miniconda3\lib\urllib\request.py:634, in HTTPErrorProcessor.http_response(self, request, response)
    631 # According to RFC 2616, "2xx" code indicates that the client's
    632 # 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 response

File ~\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 result

File ~\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.niftyadmin.cn/n/5436250.html

相关文章

【Linux】从零开始认识进程 — 中篇

今天我们继续学习进程&#xff0c;首先送给大家一句话&#xff1a; 如果痛恨所处的黑暗&#xff0c;请你成为你想要的光。 —— 顾城 从零开始学习进程 1 认识进程收尾2 进程状态2.1 谈谈Linux进程状态R 、T、 D状态 2.2 僵尸进程和孤儿进程Z(zombie)-僵尸进程孤儿进程 2.3 浅…

详细分析Python中的@wraps(func)基本知识(附Demo)

目录 前言1. 基本知识2. Demo 前言 对于装饰器的基本知识推荐阅读&#xff1a;详细分析Python装饰器&#xff08;附Demo&#xff09;对于*args, **kwargs的理解&#xff1a;Python关于 *args 和 **kwargs 参数的详解&#xff08;全&#xff09; 没有使用wraps(func)的Demo&am…

微信小程序调用百度智能云API(菜品识别)

一、注册后生成应用列表创建应用 二、找到当前所需使用的api菜品识别文档 三、点链接看实例代码 这里需要使用到如下几个参数&#xff08;如下&#xff09;&#xff0c;其他的参数可以不管 client_id &#xff1a; 就是创建应用后的API Keyclient_secret&#xff1a; 就是创建…

excel导入功能(适用于vue和react都可)

如图所示&#xff08;需求&#xff09;&#xff1a;点击导入excel后&#xff0c;数据自动新增到列表数据内 这里以vue3 andt 为例 template 标签内代码 &#xff1a; <a-uploadname"file":multiple"true":show-upload-list"false":customR…

开放地址法如何找下一个空地址?

典型回答 通常情况下&#xff0c;开放地址法寻找找下一个空的哈希地址&#xff0c;可以采用线性探测或二次探测的方法。 线性探测和二次探测 线性探测是 发生哈希冲突时&#xff0c;线性探测会在哈希表中寻找下一个可用的位置&#xff0c;具体来说&#xff0c;它会检查哈希…

【数据挖掘】实验3:常用的数据管理

实验3&#xff1a;常用的数据管理 一&#xff1a;实验目的与要求 1&#xff1a;熟悉和掌握常用的数据管理方法&#xff0c;包括变量重命名、缺失值分析、数据排序、随机抽样、字符串处理、文本分词。 二&#xff1a;实验内容 【创建新变量】 方法1&#xff1a; mydata <…

Warning logs 2024-03-18

之后操作数据库一点要谨慎&#xff01;&#xff01;&#xff01; 今天上午11点左右&#xff0c;不小心删除了数据库&#xff0c;操作步骤如下&#xff1a; 在idea的数据库插件中&#xff0c;点击数据库&#xff0c;右键&#xff0c;点击 Drop , 点击 OK。 数据库误删之后&am…

多点通信 、域套接字

广播发送端流程 #include<myhead.h> int main(int argc, const char *argv[]) { int sfdsocket(AF_INET,SOCK_DGRAM,0); if(sfd-1) { perror("socket error\n"); return -1; } printf("%d\n",sfd); int b…