![]() 5.9 Fitting Models Without Parameter Tuning.5.8 Exploring and Comparing Resampling Distributions.5.7 Extracting Predictions and Class Probabilities.5.1 Model Training and Parameter Tuning.4.4 Simple Splitting with Important Groups.4.1 Simple Splitting Based on the Outcome.3.2 Zero- and Near Zero-Variance Predictors.TL DR I had a quick go at adding a custom model into the caret framework. This is great- saves me a job of having to implement this all myself. I can now access all the benefits of the caret model training framework (such as preprocessing and cross validation) with my nnePtR model. Well, that was short and sweet! Max Kuhn has left the caret framework accessable for custom models, and has documented the process thoroughly. ![]() We see peformance roughly constant until number of hidden layers exceeds 3- then it drops off sharply to a pretty much uninformative model (remember we have three balanced classes, so random guessing should get accuracy of 0.33). We get back an object of class train, so we get the nicely formatted summary printed to screen that comes with it, as well as the plot and predict genericsįor example, lets plot the resamples' accuracy over the different training parameters: want repeated 10-fold CV # fitControl <- trainControl ( method = repeatedcv, number = 10, repeats = 5 ) # define grid of parameter values # nnetGrid <- id ( lambda = c ( 0.1, 0.3 ), nLayers = seq ( 1 : 5 ) ) # train using caret::train() # preprocess by normalising inputs # pass nUnits directly to nnePtR constructor function # set.seed ( 825 ) nnetTune <- train ( x = iris, y = iris, method = nnetP, trControl = fitControl, tuneGrid = nnetGrid, preProcess = c ( center, scale ), nUnits = 20 ) # we have access to plot generic for object of class train # plot ( nnetTune ) # and the predict generic! # predict ( nnetTune, newdata = iris ) predict ( nnetTune, newdata = iris, type = prob ) # load caret and doMC library library ( caret ) library ( doMC ) # register cores for parallel processing # registerDoMC ( 4 ) # train control options. I can pass other arguments to the nnePtR cpnstructor function, so I specify that I want 20 units per hidden layer in my network. I have access to the preprocessing options, so I specify that I want to center and scale the predictive inputs. I define an object of class train called nnetTune. TRAIN CARET CODEThe code snippet below details how I specify the training options (repeated 10-fold CV) and define the training grid of parameters (else the default parameters will be used). ![]() First, load up the caret package, and if you want to speed up the training a bit, load the doMC package for parallel training. ![]() The iris data set seems to be one of my favorites (I seem to always use it for examples!), so lets train the model to this data set. how the tuning parameters # are ordered in case similar performance obtained # nnetPSort <- function ( x ) x # append to list # nnetP $ sort <- nnetPSortĪnd believe it or not (I was a little suprised), that is it! we are ready to go! testing out on the iris data set ![]() some models can do # a random search, but I wont implement that # nnetPGrid <- function ( x, y, len = NULL, search = grid ) # append to list # nnetP $ prob <- nnetPProb # define the sort function, i.e. # start by naming my method to pass to train # nnetP <- list ( type = Classification, library = nnePtR, loop = NULL ) # define the tuning parameters # prm <- ame ( parameter = c ( nLayers, lambda ), class = rep ( numeric, 2 ), label = c ( Hidden Layers, Penalty ) ) # append them to the list # nnetP $ parameters <- prm # define the default training grid. So I here is where I give it a go, and unlock the magic caret-ty goodness for my model! setting up nneptr for use with caretįollowing Max's instructions, we define the following list, so that we can use our custom model with caret::train() I recently wrote my nnePtR package, which I detailed in this post. Max Kuhn has published instructions online as to how you go about integrating custom models with caret. Well, this is going to be a pretty short post. Integrating custom models into the caret framework ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |