Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #!/usr/bin/Rscript
  2. library(caret)
  3.  
  4. args = commandArgs(trailingOnly=TRUE)
  5.  
  6. if (!length(args)==5) {
  7. stop("Five arguments must be supplied (input file name, splitting ratio related to test data set, seed, train output file name, test output file name).n", call.=FALSE)
  8. }
  9.  
  10.  
  11. set.seed(as.numeric(args[3]))
  12.  
  13. df <- read.csv(args[1],stringsAsFactors = FALSE)
  14.  
  15. test.index <- createDataPartition(df$label, p = as.numeric(args[2]), list = FALSE)
  16.  
  17.  
  18. train <- df[-test.index,]
  19. test <- df[test.index,]
  20.  
  21.  
  22. write.csv(train, file=args[4],row.names=FALSE)
  23. write.csv(test, file=args[5],row.names=FALSE)
  24. print("train/test files created....")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement