[英]How to define input_shape for keras for regression problem?
I have a CSV file containing 200000 rows of 5 features samples (200-time steps in 1000 points).我有一个 CSV 文件,其中包含 5 个特征样本的 200000 行(1000 个点中的 200 个时间步长)。 For a regression prediction, I was trying to design an LSTM(keras.Sequential()) because it is a time series problem.
对于回归预测,我试图设计一个 LSTM(keras.Sequential()),因为它是一个时间序列问题。 When I want to design a model in Keras using
"tf.keras.Sequential()"
, in the first layer, I have an issue of defining the input_shape.当我想在
"tf.keras.Sequential()"
中使用"tf.keras.Sequential()"
设计模型时,在第一层中,我遇到了定义 input_shape 的问题。 I used input_shape=(train_dataset.shape[0],1,train_dataset.shape[1])
but I got an error.我使用了
input_shape=(train_dataset.shape[0],1,train_dataset.shape[1])
但出现错误。 The designed model is below:设计的模型如下:
def build_model():
model = tf.keras.Sequential([
layers.Dense(128,activation=tf.nn.relu,input_shape=(train_dataset.shape[0],1,train_dataset.shape[1])),
layers.Dense(128,activation=tf.nn.relu),
layers.Dense(1)
])
opt = tf.keras.optimizers.Adam(learning_rate=0.001)
model.compile(loss='mean_squared_error', optimizer=opt, metrics= ['mean_squared_error'])
return model
Any suggestion would be appreciated任何建议将不胜感激
The input_shape
should not include the batch dimension. input_shape
不应包含批次维度。 Use input_shape=train_dataset.shape[1:]
使用
input_shape=train_dataset.shape[1:]
def build_model():
model = tf.keras.Sequential([
layers.Dense(128,activation=tf.nn.relu,input_shape=train_dataset.shape[1:]),
layers.Dense(128,activation=tf.nn.relu),
layers.Dense(1)
])
opt = tf.keras.optimizers.Adam(learning_rate=0.001)
model.compile(loss='mean_squared_error', optimizer=opt, metrics= ['mean_squared_error'])
return model
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.