0
$\begingroup$

This is not so much a problem, as it is me making sure I understand what's happening with my Random Forest algorithm.

Below, I've set a few parameters. Am I right in thinking that this is the stages:

  1. Model is being run 10 times due to 10 Fold Cross Validation, whereby data is being split into 10 folds (9 used for training, 1 for validation - repeated k times, each time with a different group used for validation).

  2. For each model, 500 individual decision trees (ntree) are being generated to create the Random Forest.

  3. Because tuneLength is 5, steps 1 and 2 are repeated 5 times - each time with mtry being set to a different number.

Also, I ran this on my training data.

Is it normal practice to next pass the separate test data into the model to check how well it's able to predict the target variable. Then if satisfied with the outcome, re-create the model with all of the data?

I could really use some clarification here, as I think I may be getting this all wrong. The results of the below model tell me what the optimal mtry is (i.e. 2). So I'm unsure if I should then be creating an entirely new model, removing the trControl parameter, and manually adding in mtry as 2 if possible.

set.seed(1)
rf_test <- train(mortality ~., 
                 data = rf_train, 
                 method = "rf", 
                 ntree = 500,
                 trControl = trainControl(method = "CV", number = 10),
                 tuneLength = 5)
print(rf_test)
$\endgroup$
3
  • $\begingroup$ Your understanding is correct (including the next steps). $\endgroup$
    – desertnaut
    Apr 24 at 22:24
  • $\begingroup$ @desertnaut Thanks. So because steps 1 and 2 are repeated 5 times, is it correct to say that 25,000 decision trees are generated in total for this one algorithm? (500 * 10 * 5). Also, looking at documentation, I don't think there is a way to actually set mtry manually $\endgroup$ Apr 24 at 22:40
  • 1
    $\begingroup$ Yes, 25K trees; and there are of course various ways to set mtry manually $\endgroup$
    – desertnaut
    Apr 24 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.