% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/spectra-train.R
\name{train_pls_from_ossl}
\alias{train_pls_from_ossl}
\title{Train pre-trained PLSR models from an OSSL library}
\usage{
train_pls_from_ossl(
  ossl_library,
  properties = c("clay_pct", "sand_pct", "silt_pct", "cec_cmol", "ph_h2o", "oc_pct"),
  ncomp_max = 20L,
  validation = c("CV", "LOO", "none"),
  segments = 10L,
  preprocess = "snv+sg1",
  min_n = 50L,
  verbose = TRUE
)
}
\arguments{
\item{ossl_library}{A list with two named elements: \code{Xr}
(numeric matrix of training spectra) and \code{Yr}
(data.frame keyed by property name, one row per training
spectrum). See \code{\link{ossl_library_template}}.}

\item{properties}{Character vector of column names in
\code{ossl_library$Yr} to train models for. Defaults to the
six core soil properties exposed by OSSL.}

\item{ncomp_max}{Integer. Upper bound on the number of PLS
components to consider during cross-validation. Defaults
to 20.}

\item{validation}{One of \code{"CV"} (default, k-fold),
\code{"LOO"} (leave-one-out, slow), \code{"none"} (uses
\code{ncomp_max} components without selection).}

\item{segments}{Number of CV segments when
\code{validation = "CV"}. Default 10.}

\item{preprocess}{Pre-processing label passed to
\code{\link{preprocess_spectra}}. Stored on the trained
models so \code{\link{predict_from_spectra}} can reapply it.}

\item{min_n}{Minimum number of valid training samples (after
dropping rows with non-finite y or X). Properties below this
threshold are skipped with a warning. Default 50.}

\item{verbose}{If \code{TRUE} (default), prints a per-property
summary on completion.}
}
\value{
A named list of \code{soilKey_pls_model} objects, one per
        successfully trained property. Carries
        \code{trained_at}, \code{soilKey_version} and
        \code{preprocess} attributes for provenance.
}
\description{
Iterates over \code{properties} and fits one PLSR model per target
against the OSSL spectra in \code{ossl_library$Xr}, with internal
cross-validation to pick the optimal number of components per
property. The returned list is a drop-in replacement for the
\code{ossl_models} argument of \code{\link{predict_ossl_pretrained}}
and \code{\link{fill_from_spectra}}.
}
\details{
Spectra are pre-processed inside the function (default
\code{"snv+sg1"}); the same preprocessing is used downstream by
\code{\link{predict_from_spectra}} so the user does not have to
remember which transform was applied at training time.
}
\examples{
\dontrun{
lib <- download_ossl_subset(region = "south_america")
models <- train_pls_from_ossl(lib,
                               properties = c("clay_pct", "ph_h2o"))
result <- predict_from_spectra(my_pedon, models = models)
}
}
