第5章多層パーセプトロン
5.7.3. Accessing and Reading the Dataset5.7.3 データセットへのアクセスと読み込み
Note that the competition data is separated into training and test sets. Each record includes the property value of the house and attributes such as street type, year of construction, roof type, basement condition, etc. The features consist of various data types. For example, the year of construction is represented by an integer, the roof type by discrete categorical assignments, and other features by floating point numbers. And here is where reality complicates things: for some examples, some data is altogether missing with the missing value marked simply as “na”. The price of each house is included for the training set only (it is a competition after all). We will want to partition the training set to create a validation set, but we only get to evaluate our models on the official test set after uploading predictions to Kaggle. The “Data” tab on the competition tab in Fig. 5.7.2 has links for downloading the data.
英語のヒント
コンペティションのデータは、訓練集合とテスト集合に分かれていることに注意してほしい。各記録には、住宅の資産価値と、道路の種類、建築年、屋根の種類、地下室の状態などの属性が含まれる。特徴量はさまざまなデータ型からなる。たとえば、建築年は整数で、屋根の種類は離散的なカテゴリーの割り当てで、ほかの特徴量は浮動小数点数で表される。そしてここで現実が事態を複雑にする。一部の事例では、一部のデータがすっかり欠けていて、欠損値は単に「na」と記されている。各住宅の価格は訓練集合にだけ含まれている(何しろコンペティションなのだから)。訓練集合を分割して検証集合を作りたくなるが、公式のテスト集合でモデルを評価できるのは、予測をKaggleにアップロードした後だけである。図5.7.2のコンペティションのタブにある「Data」タブには、データをダウンロードするためのリンクがある。
To get started, we will read in and process the data using
pandas, which we introduced in Section 2.2. For convenience, we can download and cache the Kaggle housing dataset. If a file corresponding to this dataset already exists in the cache directory and its SHA-1 matches sha1_hash, our code will use the cached file to avoid clogging up your Internet with redundant downloads.英語のヒント
手始めに、2.2節で紹介した
pandasを使って、データを読み込んで処理する。便利なように、Kaggleの住宅データセットをダウンロードしてキャッシュしておける。このデータセットに対応するファイルがすでにキャッシュのディレクトリにあり、そのSHA-1がsha1_hashと一致すれば、余計なダウンロードで回線を詰まらせないよう、コードはキャッシュしたファイルを使う。class KaggleHouse(d2l.DataModule):
def __init__(self, batch_size, train=None, val=None):
super().__init__()
self.save_hyperparameters()
if self.train is None:
self.raw_train = pd.read_csv(d2l.download(
d2l.DATA_URL + 'kaggle_house_pred_train.csv', self.root,
sha1_hash='585e9cc93e70b39160e7921475f9bcd7d31219ce'))
self.raw_val = pd.read_csv(d2l.download(
d2l.DATA_URL + 'kaggle_house_pred_test.csv', self.root,
sha1_hash='fa19780a7b011d9b009e8bff8e99922a8ee2eb90'))The training dataset includes 1460 examples, 80 features, and one label, while the validation data contains 1459 examples and 80 features.
英語のヒント
訓練データセットには1460個の事例、80個の特徴量、一つのラベルが含まれ、検証データには1459個の事例と80個の特徴量が含まれる。
data = KaggleHouse(batch_size=64)
print(data.raw_train.shape)
print(data.raw_val.shape)Downloading ../data/kaggle_house_pred_train.csv from http://d2l-data.s3-accelerate.amazonaws.com/kaggle_house_pred_train.csv...
Downloading ../data/kaggle_house_pred_test.csv from http://d2l-data.s3-accelerate.amazonaws.com/kaggle_house_pred_test.csv...
(1460, 81)
(1459, 80)