github.com/pachyderm/pachyderm@v1.13.4/examples/ml/iris/rstats/iris-infer-r/infer.R (about) 1 library(caret) 2 library(tools) 3 4 # load model 5 load("/pfs/model/model.rda") 6 7 # loop over input files performing inference 8 files <- list.files(path = "/pfs/attributes", 9 pattern = "*.csv", 10 full.names = T, 11 recursive = FALSE) 12 13 cols <- c("Sepal.Length", 14 "Sepal.Width", 15 "Petal.Length", 16 "Petal.Width") 17 18 species <- c("setosa", 19 "versicolor", 20 "virginica") 21 22 for (file in files){ 23 # load the data 24 dataset <- read.csv(file, header=FALSE) 25 colnames(dataset) <- cols 26 27 # perform the inference 28 predictions <- predict(fit.model, dataset) 29 30 # output the results 31 write(species[predictions], 32 file = paste("/pfs/out/", file_path_sans_ext(basename(file)), sep = "")) 33 } 34