Deep Learning nâng cao với PyTorch
Michal Oleszak
Machine Learning Engineer



Nhiệm vụ: dự đoán mức tiêu thụ điện tương lai từ mẫu trong quá khứ
Bộ dữ liệu tiêu thụ điện:
timestamp consumption
0 2011-01-01 00:15:00 -0.704319
1 2011-01-01 00:30:00 -0.704319
... ... ...
140254 2014-12-31 23:45:00 -0.095751
140255 2015-01-01 00:00:00 -0.095751


import numpy as np def create_sequences(df, seq_length):xs, ys = [], []for i in range(len(df) - seq_length):x = df.iloc[i:(i+seq_length), 1] y = df.iloc[i+seq_length, 1]xs.append(x) ys.append(y)return np.array(xs), np.array(ys)
Tạo mẫu huấn luyện
X_train, y_train = create_sequences(train_data, seq_length)
print(X_train.shape, y_train.shape)
(34944, 96) (34944,)
Chuyển thành Torch Dataset
from torch.utils.data import TensorDataset
dataset_train = TensorDataset(
torch.from_numpy(X_train).float(),
torch.from_numpy(y_train).float(),
)
Kỹ thuật tương tự áp dụng cho chuỗi khác:
Deep Learning nâng cao với PyTorch