【发布时间】:2020-10-20 09:49:34
【问题描述】:
我是机器学习的初学者。虽然,这个问题类似于1、2、3,但在为我的数据选择输入形状时我真的很困惑。 我在时间序列数据上使用一维 CNN。数据的维度是(6400, 4)。有 4 个特征(列),其中一个是目标变量。 拆分后:
dim(xtrain) -> 5000, 3
dim(ytrain) -> 5000, 1
dim(xtest) -> 1400, 3
dim(ytest) -> 1400, 1
我在为 CNN 选择输入形状时感到困惑。这是我尝试过的(我一直保持输入 shape = c(3, 1)):
model = keras_model_sequential() %>%
layer_conv_1d(filters = 64, kernel_size = 2,
input_shape = c(3, 1), activation = "relu") %>%
layer_max_pooling_1d(pool_size = 2) %>%
layer_flatten() %>%
layer_dense(units = 32, activation = "relu") %>%
layer_dropout(rate = 0.2) %>%
layer_dense(units = 1, activation = "linear")
xtrain <- as.matrix(train[, c(1, 2, 3)])
ytrain <- as.matrix(train[, c(4)])
xtest = as.matrix(test[, c(1, 2, 3)])
ytest = as.matrix(test[, c(4)])
# Transforming 2-D matrix into 3-D matrix
xtrain = array(xtrain, dim = c(nrow(xtrain), 3, 1))
xtest = array(xtest, dim = c(nrow(xtest), 3, 1))
# fitting model
model %>% fit(xtrain, ytrain, epochs = 50, batch_size = 128, verbose = 1, validation_split = 0.20)
这执行得很好,但我不确定它是否正确。请告知设置输入形状的正确方法。
【问题讨论】:
标签: r machine-learning keras deep-learning conv-neural-network