#! /usr/bin/env python3 # import os import tarfile from six.moves import urllib DOWNLOAD_ROOT = "https://raw.githubusercontent.com/ageron/handson-ml/master/" HOUSING_PATH = os.path.join ( "datasets", "housing" ) HOUSING_URL = DOWNLOAD_ROOT + "datasets/housing/housing.tgz" def housing_data_fetch ( housing_url = HOUSING_URL, housing_path = HOUSING_PATH ): #*****************************************************************************80 # ## housing_data_fetch() retrieves a specific data file. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 01 October 2021 # # Author: # # Aurelien Geron # Modifications by John Burkardt # # Reference: # # Aurelien Geron, # Hands-on Machine Learning with Scikit-Learn and TensorFlow, # OReilly, 2017, # ISBN13: 978-1-491-96229-9 # # Input: # # string housing_url, the URL for the data file. # # string housing_path, the local directory where the data file should # be stored. # import platform import sklearn print ( "" ) print ( "housing_data_fetch():" ) print ( ' python version: %s' % ( platform.python_version ( ) ) ) print ( ' scikit-learn version is %s' % ( sklearn.__version__ ) ) print ( " Retrieve housing datafile from github." ) # # Create the local directory for the data, if it doesn't already exist. # if ( not os.path.isdir ( housing_path ) ): print ( "" ) print ( "Creating dataset subdirectory", housing_path ) os.makedirs ( housing_path ) else: print ( "" ) print ( "Dataset subdirectory", housing_path, "already exists." ) # # Construct the full name of the dataset to be downloaded. # tgz_path = os.path.join ( housing_path, "housing.tgz" ) # # Send the request for the dataset. # urllib.request.urlretrieve ( housing_url, tgz_path ) # # Create a TAR file to hold the dataset. # housing_tgz = tarfile.open ( tgz_path ) # # Once the dataset has been copied, extract it from the TAR file. # housing_tgz.extractall ( path = housing_path ) # # Close the TAR file. # housing_tgz.close ( ) # # Terminate. # print ( "" ) print ( "housing_data_fetch():" ) print ( " Normal end of execution." ) return def timestamp ( ): #*****************************************************************************80 # ## timestamp() prints the date as a timestamp. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 21 August 2019 # # Author: # # John Burkardt # import time t = time.time ( ) print ( time.ctime ( t ) ) return if ( __name__ == '__main__' ): timestamp ( ) housing_data_fetch ( ) timestamp ( )