tuneandtrainExtRF {RobustPrediction}R Documentation

Tune and Train External Random Forest

Description

This function tunes and trains a Random Forest classifier using the ranger package. It provides two strategies for tuning the min.node.size parameter based on the estperf argument:

Usage

tuneandtrainExtRF(data, dataext, estperf = FALSE, num.trees = 500)

Arguments

data

A data frame containing the training data. The first column should be the response variable (factor), and the remaining columns should be the predictor variables.

dataext

A data frame containing the external validation data. The first column should be the response variable (factor), and the remaining columns should be the predictor variables.

estperf

A logical value indicating whether to use internal tuning with external validation (TRUE) or external tuning (FALSE). Default is FALSE.

num.trees

An integer specifying the number of trees in the Random Forest. Default is 500.

Value

A list containing the following components:

Examples


# Load sample data
data(sample_data_train)
data(sample_data_extern)

# Example usage with external tuning (default)
result <- tuneandtrainExtRF(sample_data_train, sample_data_extern, num.trees = 500)
print(result$best_min_node_size)  # Optimal min.node.size
print(result$best_model)          # Trained Random Forest model
# Note: est_auc is not returned when estperf = FALSE

# Example usage with internal tuning and external validation
result_internal <- tuneandtrainExtRF(sample_data_train, sample_data_extern, 
  estperf = TRUE, num.trees = 500)
print(result_internal$best_min_node_size)  # Optimal min.node.size
print(result_internal$best_model)          # Trained Random Forest model
print(result_internal$est_auc)             # AUC on external validation dataset


[Package RobustPrediction version 0.1.7 Index]