我正在玩R中的玩具神经网络,试图学习keras
语法。我对此很陌生,所以觉得我可能会错过一些简单的东西。
这是我的X矩阵的前几行:
train_x <- structure(c(619, 502, 699, 850, 645, 822, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 42, 42, 39, 43, 44, 50, 2, 8,
1, 2, 8, 7, 0, 159660.8, 0, 125510.82, 113755.78, 0, 1, 3, 2,
1, 2, 2, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 101348.88, 113931.57,
93826.63, 79084.1, 149756.71, 10062.8), .Dim = c(6L, 11L), .Dimnames =
list(
c("1", "3", "4", "5", "6", "7"), c("CreditScore", "GeographyGermany",
"GeographySpain", "GenderMale", "Age", "Tenure", "Balance",
"NumOfProducts", "HasCrCard", "IsActiveMember", "EstimatedSalary"
)))
这是y的前几个:
train_y <- c(1L, 1L, 0L, 0L, 1L, 0L)
这是我正在努力训练的模型
class <- keras_model_sequential()
class %>%
layer_dense(units = 6, input_shape = 11,
activation = 'relu',
kernel_initializer = "uniform") %>%
layer_dropout(0.2) %>%
layer_dense(units = 6,
activation = 'relu',
kernel_initializer = 'uniform') %>%
layer_dropout(0.2) %>%
layer_dense(units = 1, activation = 'sigmoid',
kernel_initializer = 'uniform')
class %>%
compile(optimizer = 'adam',
loss = 'binary_crossentropy',
metrics = 'accuracy')
class %>%
fit(train_x, train_y, batch_size = 10,
epochs = 10)
y_hat <- predict_classes(class, test_x)
table(y_hat)
我已经尝试过搞乱一堆这些东西,但似乎无法让模型预测除了所有零或全零之外的任何东西。我想我错过了一些简单的......有什么建议吗?