View source: R/machinelearning.R
| train_and_predict | R Documentation |
Train a classification model from a dataset and use the fitted model to predict the class labels of new samples.
train_and_predict(
dataset,
new.samples,
column.class,
model,
validation,
num.folds = 10,
num.repeats = 10,
tunelength = 10,
tunegrid = NULL,
metric = NULL,
summary.function = caret::defaultSummary
)
dataset |
A dataset object containing data and metadata. |
new.samples |
A data frame or matrix with new samples to classify. |
column.class |
The metadata column containing the class labels. |
model |
A model name accepted by |
validation |
Validation method, such as |
num.folds |
Number of folds used in resampling. |
num.repeats |
Number of repeats used in repeated resampling. |
tunelength |
Number of tuning levels evaluated by |
tunegrid |
Optional data frame of tuning parameter combinations. |
metric |
Optional performance metric used for model selection. |
summary.function |
Summary function passed to
|
A list with two elements: train.result, the fitted training
object, and predictions.result, a data frame with predicted classes
for new.samples.
## Not run:
datamat <- matrix(
rnorm(24),
nrow = 4,
dimnames = list(paste0("v", 1:4), paste0("s", 1:6))
)
metadata <- data.frame(class = factor(c("A", "A", "A", "B", "B", "B")))
dataset <- list(data = datamat, metadata = metadata)
new.samples <- datamat[, 1:2, drop = FALSE]
train_and_predict(dataset, new.samples, "class", model = "rpart", validation = "cv")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.