尝试构建神经网络时出错

时间:2019-02-15 10:21:55

标签: r keras reticulate

当我尝试在模型上拟合训练集时,出现以下错误:

Error in py_call_impl(callable, dots$args, dots$keywords) : Evaluation error: Required version of NumPy not available: installation of Numpy
>= 1.6 not found.

我尝试导入numpy模块,但仍然出现错误:

library(reticulate)
np <- import('numpy')

这是代码:

nn_model = keras_model_sequential()
enter cnn_model %>% layer_dense(units = 20, activation = 'relu', kernel_initializer = 
                       initializer_random_uniform(minval = -0.05, maxval = 0.05, seed = 1), input_shape = ncol(xTrain)
                     ) %>%
         layer_dense(units = 5, activation = 'softmax', kernel_initializer = initializer_random_uniform(minval = -0.05,
                                                                                                        maxval = 0.05,
                                                                                                        seed = 1))
nn_model %>% compile(loss = 'categorical_crossentropy', optimizer = optimizer_sgd(lr = 0.1),
                 metrics = c('categorical_accuracy'))
nn_model %>% fit(xTrain, yTrain, epochs = 100, batch_size = 256, validation_split = 0.5)
nn_model %>% evaluate(xTest, yTest)

1 个答案:

答案 0 :(得分:0)

不幸的是,如果您的系统中没有Numpy,np <- import('numpy')命令似乎不会产生任何错误。尝试以下操作从R安装它:

library(reticulate)
py_install("numpy")
np <- import('numpy')