我正在尝试使用keras进行文本分类,我已经对文本进行了预处理,正确地删除了停用词,阻止了它们,删除了标点符号,创建了文档术语矩阵,令我感到困惑的部分是我可以使用DTM直接训练我的模型吗? 我遇到一个很奇怪的错误,我无法解决
model <- keras_model_sequential()
model %>%
layer_dense(units = 256, activation = 'relu', input_shape = c(784)) %>%
layer_dropout(rate = 0.4) %>%
layer_dense(units = 128, activation = 'relu') %>%
layer_dropout(rate = 0.3) %>%
layer_dense(units = 10, activation = 'softmax')
model %>% compile(
loss = 'categorical_crossentropy',
optimizer = optimizer_rmsprop(),
metrics = c('accuracy')
)
history <- model %>% fit(
dtm_train_most_frequent, train_labels,
epochs = 30, batch_size = 128,
validation_split = 0.2
)
我遇到的错误是
Error in UseMethod("fit") :
no applicable method for 'fit' applied to an object of class "c('keras.engine.sequential.Sequential', 'keras.engine.training.Model', 'keras.engine.network.Network', 'keras.engine.base_layer.Layer', 'python.builtin.object')"
我正在使用R
答案 0 :(得分:1)
请以以下形式编写fit
函数:
keras::fit()