Train word embeddings to a categorical variable using random forrest.

textTrainRandomForest(
x,
y,
cv_method = "validation_split",
outside_folds = 10,
outside_strata_y = "y",
outside_breaks = 4,
inside_folds = 3/4,
inside_strata_y = "y",
inside_breaks = 4,
mode_rf = "classification",
preprocess_step_center = FALSE,
preprocess_scale_center = FALSE,
preprocess_PCA = NA,
extremely_randomised_splitrule = "extratrees",
mtry = c(1, 10, 20, 40),
min_n = c(1, 10, 20, 40),
trees = c(1000),
eval_measure = "bal_accuracy",
model_description = "Consider writing a description of your model here",
multi_cores = "multi_cores_sys_default",
save_output = "all",
seed = 2020,
...
)

## Arguments

x Word embeddings from textEmbed. Categorical variable to predict. Cross-validation method to use within a pipeline of nested outer and inner loops of folds (see nested_cv in rsample). Default is using cv_folds in the outside folds and "validation_split" using rsample::validation_split in the inner loop to achieve a development and assessment set (note that for validation_split the inside_folds should be a proportion, e.g., inside_folds = 3/4); whereas "cv_folds" uses rsample::vfold_cv to achieve n-folds in both the outer and inner loops. Number of folds for the outer folds (default = 10). Variable to stratify according (default "y"; can also set to NULL). The number of bins wanted to stratify a numeric stratification variable in the outer cross-validation loop. Number of folds for the inner folds (default = 3/4). Variable to stratify according (default "y"; can also set to NULL). The number of bins wanted to stratify a numeric stratification variable in the inner cross-validation loop. Default is "classification" ("regression" is not supported yet). normalizes dimensions to have a mean of zero; default is set to TRUE. For more info see (step_center in recipes). normalize dimensions to have a standard deviation of one. For more info see (step_scale in recipes). Pre-processing threshold for PCA. Can select amount of variance to retain (e.g., .90 or as a grid c(0.80, 0.90)); or number of components to select (e.g., 10). Default is "min_halving", which is a function that selects the number of PCA components based on number of participants and feature (word embedding dimensions) in the data. The formula is: preprocess_PCA = round(max(min(number_features/2), number_participants/2), min(50, number_features))). default: "extratrees", which thus implement a random forest; can also select: NULL, "gini" or "hellinger"; if these are selected your mtry settings will be overridden (see Geurts et al. (2006) Extremely randomized trees for details; and see the ranger r-package for details on implementations). hyper parameter that may be tuned; default:c(1, 20, 40), hyper parameter that may be tuned; default: c(1, 20, 40) Number of trees to use (default 1000). Measure to evaluate the models in order to select the best hyperparameters default "roc_auc"; see also "accuracy", "bal_accuracy", "sens", "spec", "precision", "kappa", "f_measure". Text to describe your model (optional; good when sharing the model with others). If TRUE it enables the use of multiple cores if the computer system allows for it (i.e., only on unix, not windows). Hence it makes the analyses considerably faster to run. Default is "multi_cores_sys_default", where it automatically uses TRUE for Mac and Linux and FALSE for Windows. Option not to save all output; default "all". see also "only_results" and "only_results_predictions". Set different seed. For example settings in yardstick::accuracy to set event_level (e.g., event_level = "second").

## Value

A list with roc_curve_data, roc_curve_plot, truth and predictions, preprocessing_recipe, final_model, model_description chisq and fishers test as well as evaluation measures, e.g., including accuracy, f_meas and roc_auc (for details on these measures see the yardstick r-package documentation).

see textTrainLists textSimilarityTest

## Examples

# \donttest{
results <- textTrainRandomForest(
wordembeddings4$harmonywords, as.factor(Language_based_assessment_data_8$gender),
trees = c(1000, 1500),
mtry  = c(1), # this is short because of testing
min_n = c(1), # this is short because of testing
multi_cores = FALSE # This is FALSE due to CRAN testing and Windows machines.
)
# }