Learn R Programming

kerasformula (version 1.0.0)

predict.kms_fit: predict.kms_fit

Description

predict function for kms_fit object. Places test data on same scale that the training data were by kms(). Wrapper for keras::predict_classes(). Creates a sparse model matrix with the same columns as the training data, some of which may be 0.

Usage

# S3 method for kms_fit
predict(object, newdata, batch_size = 32, verbose = 0,
  ...)

Arguments

object

output from kms()

newdata

new data. Performs merge so that X_test has the same columns as the object created by kms_fit using the user-provided input formula. y_test is also generated from that formula.

batch_size

To be passed to keras::predict_classes. Default == 32.

verbose

0 ot 1, to be passed to keras::predict_classes. Default == 0.

...

additional parameters to build the sparse matrix X_test.

Value

list containing predictions, y_test, confusion matrix.

Examples

Run this code
# NOT RUN {
if(is_keras_available()){

 mtcars$make <- unlist(lapply(strsplit(rownames(mtcars), " "), function(tokens) tokens[1]))
 company <- kms(make ~ ., mtcars[3:32, ], Nepochs = 2)
 forecast <- predict(company, mtcars[1:2, ])
 forecast$confusion
 
 # example where y_test is unavailable
 
 trained <- kms(log(mpg) ~ ., mtcars[4:32,])
 X_test <- subset(mtcars[1:3,], select = -mpg)  
 predictions <- predict(trained, X_test)
 
}else{
   cat("Please run install_keras() before using kms(). ?install_keras for options like gpu.")
}
# }

Run the code above in your browser using DataLab