Skip to content

Instantly share code, notes, and snippets.

@tomaskrehlik
Created November 19, 2013 17:23
Show Gist options
  • Save tomaskrehlik/7549003 to your computer and use it in GitHub Desktop.
Save tomaskrehlik/7549003 to your computer and use it in GitHub Desktop.
A cusom function to use jordan recurrent neural network from RSNNS package with caret.
grid <- expand.grid(.size=5:10)
modelFunc <- function(data, parameter, levels, last, ...)
{
library(RSNNS)
list(fit = jordan(data[,setdiff(names(data),".outcome")], data$.outcome, size = parameter$.size, initFuncParams = c(1,-1, 0.3, 1, 0.5)))
}
predFunc <- function(object, newdata)
{
library(RSNNS)
predict(object$fit, newdata)
}
sortFunc <- function(x) {return(x)}
ctrl <- trainControl(custom = list(
parameters = grid,
model = modelFunc,
prediction = predFunc,
probability = NULL,
sort = sortFunc),
method = "timeslice",
horizon = 1,
initialWindow = tsl,
fixedWindow=TRUE,
savePredictions = TRUE)
customRpart <- train(outcome ~ ., data = b, method = "custom", trControl = ctrl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment