save_model | R Documentation |
Given a set of pretreatment methods, saves the best spectral
prediction model and model statistics to model.save.folder
as
model.name.Rds
and model.name_stats.csv
respectively. If only
one pretreatment method is supplied, results from that method are stored.
save_model(
df,
write.model = TRUE,
pretreatment = 1,
model.save.folder = NULL,
model.name = "PredictionModel",
best.model.metric = "RMSE",
k.folds = 5,
proportion.train = 0.7,
tune.length = 50,
model.method = "pls",
num.iterations = 10,
stratified.sampling = TRUE,
cv.scheme = NULL,
trial1 = NULL,
trial2 = NULL,
trial3 = NULL,
seed = 1,
verbose = TRUE,
save.model = deprecated(),
wavelengths = deprecated(),
autoselect.preprocessing = deprecated(),
preprocessing.method = deprecated()
)
df |
|
write.model |
If |
pretreatment |
Number or list of numbers 1:13 corresponding to desired pretreatment method(s):
|
model.save.folder |
Path to folder where model will be saved. If not provided, will save to working directory. |
model.name |
Name that model will be saved as in
|
best.model.metric |
Metric used to decide which model is best. Must be either "RMSE" or "Rsquared" |
k.folds |
Number indicating the number of folds for k-fold cross-validation during model training. Default is 5. |
proportion.train |
Fraction of samples to include in the training set. Default is 0.7. |
tune.length |
Number delineating search space for tuning of the PLSR
hyperparameter |
model.method |
Model type to use for training. Valid options include:
|
num.iterations |
Number of training iterations to perform |
stratified.sampling |
If |
cv.scheme |
A cross validation (CV) scheme from Jarquín et al., 2017.
Options for
|
trial1 |
|
trial2 |
|
trial3 |
|
seed |
Integer to be used internally as input for |
verbose |
If |
save.model |
DEPRECATED |
wavelengths |
DEPRECATED |
autoselect.preprocessing |
DEPRECATED
|
preprocessing.method |
DEPRECATED |
Wrapper that uses pretreat_spectra
,
format_cv
, and train_spectra
functions.
List of model stats (in data.frame
) and trained model object.
If the parameter write.model
is TRUE, both objects are saved to
model.save.folder
. To use the optimally trained model for
predictions, use tuned parameters from $bestTune
.
Jenna Hershberger jmh579@cornell.edu
library(magrittr)
test.model <- ikeogu.2017 %>%
dplyr::filter(study.name == "C16Mcal") %>%
dplyr::rename(reference = DMC.oven,
unique.id = sample.id) %>%
dplyr::select(unique.id, reference, dplyr::starts_with("X")) %>%
na.omit() %>%
save_model(
df = .,
write.model = FALSE,
pretreatment = 1:13,
model.name = "my_prediction_model",
tune.length = 3,
num.iterations = 3
)
summary(test.model$best.model)
test.model$best.model.stats
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.