---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
Cell In[27], line 13
11 from sklearn.metrics import mean_squared_error, r2_score
12 # 1. 加载加州房价数据集
---> 13 housing = fetch_california_housing(as_frame=True)
14 df = housing.frame
15 features = housing.feature_names
File ~\anaconda3\envs\myenv\Lib\site-packages\sklearn\utils\_param_validation.py:218, in validate_params.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
212 try:
213 with config_context(
214 skip_parameter_validation=(
215 prefer_skip_nested_validation or global_skip_validation
216 )
217 ):
--> 218 return func(*args, **kwargs)
219 except InvalidParameterError as e:
220 # When the function is just a wrapper around an estimator, we allow
221 # the function to delegate validation to the estimator, but we replace
222 # the name of the estimator by the name of the function in the error
223 # message to avoid confusion.
224 msg = re.sub(
225 r"parameter of \w+ must be",
226 f"parameter of {func.__qualname__} must be",
227 str(e),
228 )
File ~\anaconda3\envs\myenv\Lib\site-packages\sklearn\datasets\_california_housing.py:177, in fetch_california_housing(data_home, download_if_missing, return_X_y, as_frame, n_retries, delay)
171 raise OSError("Data not found and `download_if_missing` is False")
173 logger.info(
174 "Downloading Cal. housing from {} to {}".format(ARCHIVE.url, data_home)
175 )
--> 177 archive_path = _fetch_remote(
178 ARCHIVE,
179 dirname=data_home,
180 n_retries=n_retries,
181 delay=delay,
182 )
184 with tarfile.open(mode="r:gz", name=archive_path) as f:
185 cal_housing = np.loadtxt(
186 f.extractfile("CaliforniaHousing/cal_housing.data"), delimiter=","
187 )
File ~\anaconda3\envs\myenv\Lib\site-packages\sklearn\datasets\_base.py:1512, in _fetch_remote(remote, dirname, n_retries, delay)
1510 while True:
1511 try:
-> 1512 urlretrieve(remote.url, temp_file_path)
1513 break
1514 except (URLError, TimeoutError):
File ~\anaconda3\envs\myenv\Lib\urllib\request.py:240, in urlretrieve(url, filename, reporthook, data)
223 """
224 Retrieve a URL into a temporary location on disk.
225
(...)
236 data file as well as the resulting HTTPMessage object.
237 """
238 url_type, path = _splittype(url)
--> 240 with contextlib.closing(urlopen(url, data)) as fp:
241 headers = fp.info()
243 # Just return the local path and the "headers" for file://
244 # URLs. No sense in performing a copy unless requested.
File ~\anaconda3\envs\myenv\Lib\urllib\request.py:215, in urlopen(url, data, timeout, cafile, capath, cadefault, context)
213 else:
214 opener = _opener
--> 215 return opener.open(url, data, timeout)
File ~\anaconda3\envs\myenv\Lib\urllib\request.py:521, in OpenerDirector.open(self, fullurl, data, timeout)
519 for processor in self.process_response.get(protocol, []):
520 meth = getattr(processor, meth_name)
--> 521 response = meth(req, response)
523 return response
File ~\anaconda3\envs\myenv\Lib\urllib\request.py:630, in HTTPErrorProcessor.http_response(self, request, response)
627 # According to RFC 2616, "2xx" code indicates that the client's
628 # request was successfully received, understood, and accepted.
629 if not (200 <= code < 300):
--> 630 response = self.parent.error(
631 'http', request, response, code, msg, hdrs)
633 return response
File ~\anaconda3\envs\myenv\Lib\urllib\request.py:559, in OpenerDirector.error(self, proto, *args)
557 if http_err:
558 args = (dict, 'default', 'http_error_default') + orig_args
--> 559 return self._call_chain(*args)
File ~\anaconda3\envs\myenv\Lib\urllib\request.py:492, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)
490 for handler in handlers:
491 func = getattr(handler, meth_name)
--> 492 result = func(*args)
493 if result is not None:
494 return result
File ~\anaconda3\envs\myenv\Lib\urllib\request.py:639, in HTTPDefaultErrorHandler.http_error_default(self, req, fp, code, msg, hdrs)
638 def http_error_default(self, req, fp, code, msg, hdrs):
--> 639 raise HTTPError(req.full_url, code, msg, hdrs, fp)
HTTPError: HTTP Error 403: Forbidden
最新发布