训练数据调整为数组
x_train, y_train = np.array(x_train), np.array(y_train) # x_train形状为:(1240, 60, 1)
x_test, y_test = np.array(x_test), np.array(y_test)
# print(x_train.shape)
x_train = np.reshape(x_train, (x_train.shape[0], 60, 1))
x_test = np.reshape(x_test, (x_test.shape[0], 60, 1))
列表是不存在维度问题,数组是有维度的,np.array()把列表转化为数组
可以用x_train.shape来查看自己的数据形状,现在数据处理好了。
构建模型
model = tf.keras.Sequential([
SimpleRNN(100, return_sequences=True), #布尔值。是返回输出序列中的最后一个输出,还是全部序列。
Dropout(0.1), #防止过拟合
SimpleRNN(100),
Dropout(0.1),
Dense(1)
])
tf.keras.Sequential()序贯模型(Sequential):单输入单输出,一条路通到底,层与层之间只有相邻关系,没有跨层连接。这种模型编译速度快,操作也比较简单。
这里用了两次simpleRNN