Learn R Programming

MLSP (version 0.1.0)

ml_f: Machine Learning Function for Soil Spectral Data

Description

This function applies several machine learning models (PCR, PLSR, Random Forest, LASSO, Cubist) to soil spectral data and compares their performance. Optionally, it can return the best-performing model.

Usage

ml_f(
  x,
  y,
  smoother_selection,
  type_of_soil,
  model_selection = TRUE
)

Value

A data frame:

If model_selection = FALSE

Returns results for all models.

If model_selection = TRUE

Returns only the best-performing model result.

Arguments

x

A data frame or matrix containing spectral data.

y

A vector containing corresponding soil laboratory measurements.

smoother_selection

A parameter specifying the smoothing method to be applied during preprocessing.

type_of_soil

A character string indicating the soil type for model calibration.

model_selection

Logical; if `TRUE` (default), the function returns only the best-performing model. If `FALSE`, it returns the results from all models.

Details

The function merges spectral and laboratory data, preprocesses the data, and evaluates the following models:

  • PCR (Principal Component Regression)

  • PLSR (Partial Least Squares Regression)

  • RF (Random Forest)

  • LASSO regression

  • Cubist regression

Each model's performance results are combined into a single results object. If model_selection = TRUE, the function returns the model with the highest performance metric (based on the 11th column of the results table).

Examples

Run this code
# \donttest{
# Example usage:
results <- ml_f(
  x,
  y,
  smoother_selection = "savitzky",
  type_of_soil = "loam",
  model_selection = TRUE
)
# }

Run the code above in your browser using DataLab