predict.kms_fit: predict.kms_fit

Description Usage Arguments Value Author(s) Examples

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

1
2
3
## S3 method for class '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.

Author(s)

Pete Mohanty

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
if(is_keras_available()){

 mtcars$make <- unlist(lapply(strsplit(rownames(mtcars), " "), function(tokens) tokens[1]))
 company <- kms(make ~ ., mtcars[3:32, ], Nepochs = 2, verbose=0)
 forecast <- predict(company, mtcars[1:2, ])
 forecast$confusion
 
 # example where y_test is unavailable
 
 trained <- kms(log(mpg) ~ ., mtcars[4:32,], Nepochs=1, verbose=0)
 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.")
}

kerasformula documentation built on May 2, 2019, 9:44 a.m.