ageron / handson-ml2

A series of Jupyter notebooks that walk you through the fundamentals of Machine Learning and Deep Learning in Python using Scikit-Learn, Keras and TensorFlow 2.
Apache License 2.0
27.25k stars 12.59k forks source link

[BUG] Hello, teacher. I am unable to download the data of "housing". I clicked the “download”, but it failed. #596

Open zhupipia opened 1 year ago

zhupipia commented 1 year ago
import os
import tarfile
import urllib

DOWNLOAD_ROOT = "https://raw.githubusercontent.com/ageron/handson-ml2/master/"
HOUSING_PATH = os.path.join("datasets","housing")
HOUSING_URL = DOWNLOAD_ROOT + "datasets/housing/housing.tgz"

def fetch_housing_data(housing_url = HOUSING_URL, housing_path = HOUSING_PATH):
     os.makedirs(housing_path, exist_ok = True)
     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()

fetch_housing_data()    
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)

housing = load_housing_data()
housing.head()
zhupipia commented 1 year ago

After I run, nothing happened.

ageron commented 1 year ago

Hi @zhupipia,

I just tried running your code in Colab, and it worked just fine. What environment are you running this code in? What do you mean by "nothing happened"? Was anything displayed? Did you get an error message? Are you sure you ran the code? Could you please provide more details (e.g., a screenshot).

zhupipia commented 1 year ago

Thanks, teacher! I have downloaded the data from my iPad. I think it could be the cause of the system. Thanks for you again!

ageron commented 1 year ago

Thanks for the update, @zhupipia . I recommend you go through the code examples using Colab, as it does not require any installation on your own system, you get access to a free virtual machine online which can be equipped with a GPU or even a TPU, and it runs in your web browser. Just go to https://homl.info/colab2 , then login to your Google account (if needed), and select the notebook you want to open (for example 02_end_to_end_machine_learning_project.ipynb). Next, run the cells one by one. Feel free to play with the code. If anything fails, you can always reopen the original notebook in Colab and run it to see if the error was due to any changes you made to the code. The code will run on the virtual machine on the cloud, so any data that the code downloads will be downloaded to that virtual machine. If you train a model and you want to keep it, you can always download it to your own machine. Hope this helps.