View source: R/machine_learning.R
| AStrain.as_data | R Documentation |
For each algorithm (column) in the data, a model is trained to later predict the output (KPI) for that algorithm (using function ASpredict()).
## S3 method for class 'as_data'
AStrain(data_object, method = NULL, parallel = FALSE, f = NULL, ...)
data_object |
object of class |
method |
name of the model to be used. The user can choose from any of the models provided by |
parallel |
boolean to control whether to parallelise the training or not (paralellization is handled by library snow). |
f |
function we want to use to train the models. If NULL, |
... |
arguments passed to the caret train function. |
A list is returned of class as_train containing the trained models, one for each of the algorithms.
data(branchingsmall)
# Partition and normalize the data
data_object <- partition_and_normalize(branchingsmall$x, branchingsmall$y, test_size = 0.3,
family_column = 1, split_by_family = TRUE)
# Example: training a regression decision tree
# with cross-validation control and basic hyperparameter tuning
train_control <- caret::trainControl(method = "cv", number = 5)
tune_grid <- expand.grid(cp = c(0.01, 0.05, 0.1))
training <- AStrain(
data_object,
method = "rpart",
trControl = train_control,
tuneGrid = tune_grid
)
# Example: training with glm and similar with custom function
training <- AStrain(data_object, method = "glm")
custom_function <- function(x, y) {
glm.fit(x, y)
}
custom_training <- AStrain(data_object, f = "custom_function")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.