When I execute this sample code below, everything works with out an error. When I try to use predict function with test data, it results in predicting everything instead of just test data set
# load libraries
library(tfestimators)
library(tensorflow)
library(caret)
# load data
data("mtcars")
row.names(mtcars) = NULL
# create data partition
samples = createDataPartition(mtcars$mpg, p= 0.8)
mpg_train = mtcars[samples$Resample1,]
mpg_test = mtcars[-samples$Resample1, ]
# return an input_fn for a given subset of data
CA_input_fn = function(data, num_epochs = 1) {
input_fn(mtcars,
features = names(mtcars[,2:11]),
response = "mpg",
batch_size = 32,
num_epochs = num_epochs)
}
# create feature columns
cols <- feature_columns(
tf$feature_column$numeric_column("disp"),
tf$feature_column$numeric_column("cyl")
)
# dnn model
model = dnn_regressor(hidden_units = c(30,20,10)
,feature_columns = cols
)
# train the model
model %>% train(CA_input_fn(mpg_train, num_epochs = 10))
# do evaluation
model %>% evaluate(CA_input_fn(mpg_test))
# A tibble: 1 x 5
# average_loss `label/mean` loss `prediction/mean` global_step
# <dbl> <dbl> <dbl> <dbl> <dbl>
# 1 166. 20.1 5302. 13.4 10
# dimension of test data
dim(mpg_test)
## [1] 4 11
# do predictions
predictions = model %>% predict(CA_input_fn(mpg_test), simplify = TRUE, predict_keys = "predictions")
# dimension of predictions data
dim(predictions)
## [1] 32 1
When I execute this sample code below, everything works with out an error. When I try to use predict function with test data, it results in predicting everything instead of just test data set
Session Information
Any ideas on why this bug is happending?