[英]How to re-frame the data-frame with multiple inputs for LSTM in Keras?
I am trying to predict the temperature for the given area (its integer number from 1 to 142) for the given date and time.我正在尝试预测给定日期和时间的给定区域的温度(其 integer 编号从 1 到 142)。
The problem is that I have CSV with the following columns:问题是我有 CSV 与以下列:
DateTime,AreaID,Temperature日期时间、区域 ID、温度
How to reframe the data-frame for LSTM (Apologise as I am a new bee for the LSTM)?如何重新构建 LSTM 的数据框(道歉,因为我是 LSTM 的新蜜蜂)?
For the information, I have data for two months with a measured by the period of every 5 minutes.对于信息,我有两个月的数据,每 5 分钟一次。
I have coded LSTM for Input DateTime.我已经为输入日期时间编码了 LSTM。 But I want to include AreaID too.
但我也想包括 AreaID。 to predict Temperature.
预测温度。
The dataset created for the Training and Testing sets are using the following code block:为训练集和测试集创建的数据集使用以下代码块:
dataset = dataset.temperature.values #numpy.ndarray
dataset = dataset.astype('float32')
dataset = np.reshape(dataset, (-1, 1))
scaler = MinMaxScaler(feature_range=(0, 1))
dataset = scaler.fit_transform(dataset)
train_size = int(len(dataset) * 0.80)
test_size = len(dataset) - train_size
train, test = dataset[0:train_size,:], dataset[train_size:len(dataset),:]
def create_dataset(dataset, look_back=1):
X, Y = [], []
for i in range(len(dataset)-look_back-1):
a = dataset[i:(i+look_back), 0]
X.append(a)
Y.append(dataset[i + look_back, 0])
return np.array(X), np.array(Y)
look_back = 30
X_train, Y_train = create_dataset(train, look_back)
X_test, Y_test = create_dataset(test, look_back)
# reshape input to be [samples, time steps, features]
X_train = np.reshape(X_train, (X_train.shape[0], 1, X_train.shape[1]))
X_test = np.reshape(X_test, (X_test.shape[0], 1, X_test.shape[1]))
Before this, The sample code have sorted the data frame based on DateTime like:在此之前,示例代码已根据 DateTime 对数据帧进行排序,例如:
dataset.sort_values('timestamp', inplace=True, ascending=True)
I want to change LSTM to take two inputs 1. DateTime 2. AreaID我想将 LSTM 更改为采用两个输入 1. DateTime 2. AreaID
& One Output: 1. Temperature & 一个 Output: 1. 温度
How to code LSTM for this requirements?如何针对此要求编写 LSTM 代码? (Please help me I am a new bee in the area of neural network)
(请帮助我,我是神经网络领域的新蜜蜂)
Just for hint.只是为了提示。
You prepare new dataset into x_train and y_train Take an starting 60 days to train the model and predict 61th days thats my logic您将新数据集准备到 x_train 和 y_train 开始 60 天来训练 model 并预测第 61 天,这就是我的逻辑
X_train=[]
y_train=[]
count=0
for i in range(60,train.shape[0]):
count=count+1
X_train.append(df[i-60:i])
y_train.append(train['targetcol'][i])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.