Learn R Programming

waves (version 0.1.0)

PredictFromSavedModel: Use provided model object to predict trait values with input dataset

Description

Loads an existing model and cross-validation performance statistics (created with SaveModel) and makes predictions based on new spectra.

Usage

PredictFromSavedModel(input.data, model.stats.location, model.location,
  wavelengths = 740:1070, model.method = "pls")

Arguments

input.data

data.frame object of spectral data for input into a spectral prediction model. First column contains unique identifiers followed by spectral columns. Include no other columns to right of spectra! Column names of spectra must start with "X".

model.stats.location

String containing file path (including file name) to save location of "(model.name)_stats.csv" as output from the SaveModel function.

model.location

String containing file path (including file name) to location where the trained model ("(model.name).Rds") was saved as output by the SaveModel function.

wavelengths

List of wavelengths represented by each column in input.data

model.method

Model type to use for training. Valid options include:

  • "pls": Partial least squares regression (Default)

  • "rf": Random forest

  • "svmLinear": Support vector machine with linear kernel

  • "svmRadial": Support vector machine with radial kernel

Value

data.frame object of predictions for each sample (row). First column is unique identifier supplied by input.data and second is predicted values

Examples

Run this code
# NOT RUN {
ikeogu.2017 %>%
  dplyr::select(sample.id, dplyr::starts_with("X")) %>%
  PredictFromSavedModel(input.data = .,
                        model.stats.location = paste0(getwd(),
                                                      "/my_model_stats.csv"),
                        model.location = paste0(getwd(), "/my_model.Rds"),
                        wavelengths = 350:2500)
# }

Run the code above in your browser using DataLab