머신러닝 실전: Scikit-Learn 및 TensorFlow 기반 노트

1186 단어 기계 학습
P71 코드 상세 정보
import os
import tarfile
from six.moves import urllib
import pandas as pd

#    
DOWNLOAD_ROOT = "https://raw.githubusercontent.com/ageron/handson-ml/master/"
#      (     )
HOUSING_PATH = "datasets/housing"
HOUSING_URL = DOWNLOAD_ROOT + HOUSING_PATH + "/housing.tgz"
#     housing.tgz,     housing.csv
def fetch_housing_data(housing_url=HOUSING_URL, housing_path=HOUSING_PATH):
	#     datasets/housing   
	if not os.path.isdir(housing_path):
		#    
		os.makedirs(housing_path)
		#housing.tgz       ,join     ,           '/'
		#   tgz_path = datasets/housing/housing.tgz
		tgz_path = os.path.join(housing_path, "housing.tgz")
		# housing_url     tgz_path
		urllib.request.urlretrieve(housing_url, tgz_path)
		#  housing.tgz     housing_tgz
		housing_tgz = tarfile.open(tgz_path)
		#  housing_tgz      
		housing_tgz.extractall(path=housing_path)
		#    
		housing_tgz.close()
		
fetch_housing_data()

#      housing.csv  
def load_housing_data(housing_path=HOUSING_PATH):
	csv_path = os.path.join(housing_path, "housing.csv")
	return pd.read_csv(csv_path)

#     
ans = load_housing_data()
print(ans)

좋은 웹페이지 즐겨찾기