fit_and_evaluate_rf: Fit and Evaluate Random Forest Model

View source: R/modelTrainingTuningFittingTesting.R

fit_and_evaluate_rfR Documentation

Fit and Evaluate Random Forest Model

Description

This function fits a Random Forest model using the provided hyperparameters and training data, then evaluates its performance on a validation set.

Usage

fit_and_evaluate_rf(
  best_params,
  X_train,
  y_train,
  X_val = NULL,
  y_val = NULL,
  save_path = NULL,
  seed = 4
)

Arguments

best_params

A list of best hyperparameters obtained from hyperparameter tuning.

X_train

Training feature matrix.

y_train

Training target vector.

X_val

Validation feature matrix (optional).

y_val

Validation target vector (optional).

save_path

Optional path to save the trained model.

seed

Optional random seed.

Value

A list containing the trained model and, if testing or validation data is provided, the accuracy, f1, precision, recall and roc_auc scores on the testing or validation set.

Examples

fitting_results<-fit_and_evaluate_rf(tuning_results$best_params,processed_training_data$X_training_mat,processed_training_data$y_training_vector,processed_validation_data$X_validation_mat,processed_validation_data$y_validation_vector)

Print the fitting results, provides accuracy, f1 score, precision, recall and roc_auc scores on the model as fitted to the validation set
print(fitting_results)

tkolisnik/Rf2pval documentation built on Feb. 20, 2024, 5:39 a.m.