gpt4 book ai didi

python-3.x - 当我尝试重新创建来自 Hands On Machine Learning with Sci-Kit Learn & Tensorflow 的住房数据集时,该数据集不显示

转载 作者:行者123 更新时间:2023-11-30 09:07:26 25 4
gpt4 key购买 nike

我正在尝试使用下面的代码重新创建书中的住房数据集/代码。由于某种原因,我得到了最后一直显示的错误

In [32]:

import os
import tarfile
from six.moves import urllib
In [37]:

DOWNLOAD_ROOT = "https://raw.githubusercontent.com/ageron/handson-ml/master/"
HOUSING_PATH = "/home/isaac/Fundamentals of Data Science Certificate/3253 - Machine Learning/Code from book"
HOUSING_URL = DOWNLOAD_ROOT + HOUSING_PATH + "/housing.tgz"
In [41]:

def fetch_housing_data(housing_url=HOUSING_URL, housing_path=HOUSING_PATH):
if not os.path.isdir(housing_path):
os.makedirs(housing_path)
tgz_path = os.path.join(housing_path, "housing.tgz")
urllib.request.urlretrieve(housing_url, tgz_path)
housing_tgz = tarfile.open(tgz_path)
housing_tgz.extractall(path=housing_path)
housing_tgz.close()
In [42]:

import pandas as pd
def load_housing_data(housing_path=HOUSING_PATH):
csv_path = os.path.join(housing_path, "housing.csv")
return pd.read_csv(csv_path)
In [43]:

housing = load_housing_data()
housing.head
<小时/>
FileNotFoundError: File b'/home/isaac/Fundamentals of Data Science Certificate/3253 - Machine Learning/Code from book/housing.csv' does not exist

我该如何解决这个问题?

最佳答案

将 pandas 导入为 pdfetch_housing_data()

导入 pandas 后。只需调用函数 fetch_housing_data() 即可。这应该可以解决问题。

这本书也有类似的错误,作者忘记添加一两行。

关于python-3.x - 当我尝试重新创建来自 Hands On Machine Learning with Sci-Kit Learn & Tensorflow 的住房数据集时,该数据集不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48472277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com