R-如何缩放(标准化)模型的1行输入数据

时间:2019-07-18 17:05:03

标签: r tensorflow keras

我一直在寻找一种方法来在“ df”仅为1行的预测端缩放数据。predict(Model,as.matrix(df))。如果我使用scale函数,它只会为输入中的每一列返回0。我的模型代码如下。

我知道在python中有一种方法可以用所谓的管道来完成。我基本上需要将缩放比例内置到已保存的模型中,因此不需要使用输入变量来执行它。

Model <- keras_model_sequential() 
Model %>% 
  layer_dense(units=200, kernel_initializer = "uniform", activation = "relu", input_shape = ncol(x)) %>%
  layer_dense(units=50, kernel_initializer = "uniform", activation = "linear") %>%
  layer_dense(units=1, kernel_initializer = "uniform", activation = "linear") 

compile(Model,optimizer = "adam",loss = "mse", metrics=c("mae", "accuracy"))

fit<-fit(Model, as.matrix(x), as.matrix(y), epochs = 100, batch_size = 25, shuffle = T, verbose = T, validation_split = .3)

accuracy <-mean(fit[["metrics"]][["acc"]])

save_model_hdf5(Model, "M1")

0 个答案:

没有答案