R/ranger.model.R

ranger.model <- function(preProcess = "zv",
                         description = NULL, ...)
{
  library(ranger)
  library(e1071)
  library(caret)

  function()
  {
    model.name <- "ranger"
    model_ <- NULL

    train_ <- function(X_train, y)
    {
      model_ <<- train(
        x = X_train,
        y = y,
        method = "ranger",
        preProcess = preProcess, ...,
        trControl = trainControl(method = "none",
                                 classProbs = TRUE,
                                 returnResamp = "none",
                                 returnData = FALSE))
      invisible()
    }

    predict_ <- function(X_test)
    {
      predictions <- predict(model_, X_test, type = "prob")
      predictions <- rename.prediction.columns(predictions, model.name)
      predictions
    }

    list(
      train_ = train_,
      predict_ = predict_,
      name = model.name,
      description = description
    )
  }
}
rladeira/stacking documentation built on May 27, 2019, 9:28 a.m.