Learn R Programming

MLmorph (version 0.1.1)

create_rf_model: Create a random forest classification model

Description

Create a random forest classification model

Usage

create_rf_model(
  data,
  dependent = colnames(data)[ncol(data)],
  independent = setdiff(colnames(data), dependent),
  train_validate_split = 0.8,
  shiny = FALSE,
  ...
)

Value

A named list with components:

Arguments

data

A data.frame containing predictors and the outcome.

dependent

Character scalar; the name of the outcome (must be a factor for classification). Defaults to the last column of data.

independent

Character vector; names of predictor variables. Defaults to all columns except dependent.

train_validate_split

Numeric in (0, 1); proportion of rows used for training. Default is 0.8.

shiny

Logical; if TRUE, trains incrementally and reports progress via MLmorph app. Default FALSE.

...

Additional arguments passed to randomForest (e.g., ntree).

Examples

Run this code
n <- 60
y  <- factor(sample(letters[1:3], n, TRUE))
x1 <- factorize_numeric_vector(runif(n, 10, 20), breaks_no = 3)
x2 <- factorize_numeric_vector(runif(n,  1,  2), breaks_no = 5)
df <- data.frame(y, x1, x2)
fit <- create_rf_model(df, dependent = "y", ntree = 50)
names(fit)

Run the code above in your browser using DataLab