官术网_书友最值得收藏!

Loading data

We can load the data used in this chapter with the following function.  It's very similar to the function we used in chapter 2, however it's adapted for this dataset.

from sklearn.preprocessing import StandardScaler

def
load_data():
"""Loads train, val, and test datasets from disk"""
train = pd.read_csv(TRAIN_DATA)
val = pd.read_csv(VAL_DATA)
test = pd.read_csv(TEST_DATA)

# we will use a dict to keep all this data tidy.
data = dict()
data["train_y"] = train.pop('y')
data["val_y"] = val.pop('y')
data["test_y"] = test.pop('y')

# we will use sklearn's StandardScaler to scale our data to 0 mean, unit variance.
scaler = StandardScaler()
train = scaler.fit_transform(train)
val = scaler.transform(val)
test = scaler.transform(test)

data["train_X"] = train
data["val_X"] = val
data["test_X"] = test
# it's a good idea to keep the scaler (or at least the mean/variance) so we can unscale predictions
data["scaler"] = scaler
return data
主站蜘蛛池模板: 永福县| 大姚县| 呼玛县| 德庆县| 新乐市| 贺州市| 贺兰县| 泉州市| 武宣县| 昔阳县| 淮阳县| 高唐县| 南部县| 镇原县| 偏关县| 全南县| 乐昌市| 阳江市| 彭泽县| 平阴县| 邓州市| 新乡市| 通州市| 遂川县| 望都县| 阜新| 墨脱县| 内乡县| 五台县| 永安市| 静海县| 什邡市| 永丰县| 延庆县| 增城市| 交城县| 钦州市| 历史| 潜江市| 吐鲁番市| 鄂托克前旗|