##
## Holdout
Holdout <- function(list, prabability = 0.3, seed = 0){
##
## Load package
require("PyKit")
##
## Set random seed
set.seed(seed)
##
## Check list name
if(is.null(names(list)))
names(list) <- seq(length(list))
##
## Total data
intFirstIndex <- 1
booHaveDimension <- HaveDimension(list[[intFirstIndex]])
if(booHaveDimension){
intTotal <- nrow(list[[1]])
}else{
intTotal <- length(list[[1]])
}
##
## Sample size
intSampleSize <- floor(intTotal * prabability)
eleSampleIndex <- sample(seq(intTotal), intSampleSize)
##
## return
listReturn <- list()
for(i in names(list)){
booHaveDimension <- HaveDimension(list[[i]])
if(booHaveDimension){
listReturn[['Train']][[i]] <- list[[i]][-eleSampleIndex,]
listReturn[['Valid']][[i]] <- list[[i]][ eleSampleIndex,]
}else{
listReturn[['Train']][[i]] <- list[[i]][-eleSampleIndex]
listReturn[['Valid']][[i]] <- list[[i]][ eleSampleIndex]
}
}
return(listReturn)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.