This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Many Models, One Question

Kuhn and Johnson’s practice of fitting a panel of models built on different mathematics (PLS, penalized regression, MARS, SVM, KNN, random forest, boosting and a neural network) on the same resamples, comparing them honestly, stacking them into an ensemble and choosing what a regulated setting can defend.

    The one idea

    No single algorithm is right in advance. Fit several that explain the outcome in different mathematical ways, compare them on identical resamples, and let the evidence, then the intended use, choose.

    Kuhn and Johnson make this the backbone of Applied Predictive Modeling1. Their worked case studies do not pick an algorithm and tune it to death. They fit a panel: linear, nonlinear, tree-based, kernel-based. They compare the resampled performance distributions and only then decide. Judging a model by how well it predicts held-out data, rather than by how plausible its assumptions look, is what Leo Breiman called the algorithmic modelling culture2. The reason is not fashion. Each model makes different assumptions about how predictors relate to the outcome, so a panel is a set of competing hypotheses about the data.

    Graphic titled 'Many Models, One Question', subtitled 'No single algorithm is right in advance. Fit several that explain the outcome in different mathematical ways, compare them, and let the evidence choose.' Left, 'Product T: manufacturing inputs (same dataset for all models)': API particle size (D50), granule moisture, lubricant blend time, compression force, tablet hardness, supplier and manufacturing equipment, above a photograph of tablets. An arrow leads to 'Same dataset', which branches into four model families, each with two models, a small sketch and a one-line description. Regression and latent variables: PLS, a weighted sum of a few latent variables related to the outcome; lasso, a linear model with coefficients shrunk toward zero (variable selection). Nonlinear functions: MARS, joined straight-line segments with automatic interactions; neural network, weighted sums through nonlinear functions (learns flexible relationships). Similarity and kernel methods: SVM, a smooth nonlinear model with a tolerance band; KNN, the average of the k most similar training batches. Tree-based methods: random forest, the average of many decision trees (more stable and robust); boosted trees, many shallow trees, each fitted to the errors of the previous trees. All four families point to 'Outcome (same question): percent dissolved at 30 minutes', with a photograph of dissolution vessels. Footer: 'The takeaway: one question, one dataset, multiple mathematical hypotheses.'
    The eight-model panel for Product T, grouped into four families. Every model sees the same batches and answers the same question; they differ only in how they assume the inputs relate to % dissolved. Constructed teaching case; photographs are illustrative.

    Eight models, eight explanations

    Product T, from reading 1: predict % dissolved at 30 minutes from material and process data.

    ModelHow it explains the outcomeWhat it assumesPreprocessing it needs
    Partial least squares (PLS)A weighted sum of a few latent variables chosen to covary with yRoughly linear; collinearity is fineCentring, usually scaling
    Penalized regression (lasso, elastic net)A weighted sum of predictors with coefficients shrunk toward zero; lasso sets some exactly to zeroLinear, additiveScaling (the penalty is scale-dependent)
    MARSJoined straight-line segments (“hinges”), with interactions added automaticallyPiecewise linearLittle
    Support vector machine (radial kernel)A smooth surface in a transformed space, ignoring errors inside a tolerance bandSmooth, possibly curvedScaling, essential
    k-nearest neighboursThe average of the k most similar training batchesSimilar inputs give similar outputsScaling, essential (it is all distances)
    Random forestThe average of hundreds of decision trees, each grown on a bootstrap sample with random subsets of predictorsStep-like relationships; interactions are naturalAlmost none
    Boosted treesMany shallow trees, each fitted to the errors of the trees before itSame as forest, built sequentiallyAlmost none
    Neural network (single hidden layer)Weighted sums passed through nonlinear functions, layeredVery flexible; needs dataScaling, essential

    Three practical consequences follow from the table.

    • Different preprocessing for different models. Trees need almost nothing; KNN, SVM and neural networks are useless without scaling. tidymodels handles this by pairing recipes with models.
    • Different extrapolation behaviour. A tree ensemble cannot predict outside the range of outcomes it was trained on; it plateaus. A linear model extrapolates confidently, and can be confidently wrong. Neither is safe outside the applicability domain, which is why T² and Q monitoring matter regardless of model.
    • Different explanations. If PLS, the lasso and a random forest all rank API particle size first, that is evidence about the data. If only the neural network finds a signal, ask what it is fitting.

    Run the panel on the same resamples

    A workflow joins one recipe to one model. A workflow set crosses several recipes with several models:

    library(tidymodels)
    
    basic  <- recipe(diss_30 ~ ., data = batches) |>
      update_role(batch_id, api_lot, new_role = "id") |>
      step_impute_median(hardness) |>
      step_dummy(all_nominal_predictors()) |>
      step_nzv(all_predictors())
    
    scaled <- basic |> step_normalize(all_numeric_predictors())
    
    panel <- workflow_set(
      preproc = list(basic = basic, scaled = scaled),
      models  = list(
        pls    = parsnip::pls(num_comp = tune()) |> set_mode("regression"),
        lasso  = linear_reg(penalty = tune(), mixture = 1) |> set_engine("glmnet"),
        mars   = mars(prod_degree = tune()) |> set_mode("regression"),
        svm    = svm_rbf(cost = tune(), rbf_sigma = tune()) |> set_mode("regression"),
        knn    = nearest_neighbor(neighbors = tune()) |> set_mode("regression"),
        forest = rand_forest(mtry = tune(), trees = 1000) |> set_mode("regression"),
        boost  = boost_tree(trees = tune(), learn_rate = tune()) |> set_mode("regression"),
        nnet   = mlp(hidden_units = tune(), penalty = tune()) |> set_mode("regression")
      )
    )
    
    results <- panel |>
      workflow_map("tune_grid", resamples = folds, grid = 15,
                   metrics = metric_set(rmse, rsq), seed = 2026)
    
    autoplot(results, rank_metric = "rmse")
    

    In practice you would pair the tree models with basic and the rest with scaled instead of fitting every combination. The point to see is the structure: one folds object (the batch-grouped folds from reading 1), used by every workflow. Each model is scored on exactly the same held-out batches, so the comparison is paired. Differences come from the models, not from luck in the split.

    Read the result as a distribution, not a leaderboard

    The constructed Product T panel gives these cross-validated RMSE values, in % dissolved:

    ModelMean RMSESpread across folds
    Random forest3.12.4–3.9
    Boosted trees3.22.3–4.2
    MARS3.32.6–4.0
    PLS3.42.8–4.1
    Lasso3.52.9–4.1
    SVM3.62.7–4.6
    Neural network4.02.9–5.6
    KNN4.43.3–5.8

    The forest “wins” by 0.3 percentage points. The spread across folds is about 1.5 points. The top five are not meaningfully different on this evidence. Kuhn and Silge recommend formal paired comparisons of resampled metrics for exactly this reason3. Two things are clear: KNN and the neural network are worse, and the relationships appear to be mostly linear, since PLS and the lasso keep up with the flexible models.

    The one-standard-error rule

    When several settings perform within noise of each other, choose the simplest one within one standard error of the best. tune provides select_by_one_std_err(). In a regulated setting this rule has more force, because the simpler model is easier to explain, validate, monitor and transfer. Here PLS or the lasso is the defensible choice. The forest’s 0.3 points do not pay for what it costs to justify.

    Ensembles: let models vote

    Sometimes the models are wrong in different places. Then a combination beats any member. Stacking fits a second, simple model whose inputs are the out-of-fold predictions of the candidates, and learns how much weight each deserves3:

    library(stacks)
    
    ens <- stacks() |>
      add_candidates(results) |>     # out-of-fold predictions from the panel
      blend_predictions() |>         # penalized weights; most get zero
      fit_members()                  # refit the survivors on all training data
    

    add_candidates needs the tuning run to keep its predictions (control_grid(save_pred = TRUE, save_workflow = TRUE)). The blending step uses a lasso-type penalty, so most candidates get zero weight; a typical result keeps two to four members. Random forests and boosted trees are themselves ensembles of trees. Stacking is the same idea one level up.

    For Product T the stack (PLS 0.55, random forest 0.30, MARS 0.15) reaches RMSE 2.9. Is that worth it? An ensemble is several locked models plus a blending model, each with its own preprocessing. Every one has to be validated, monitored for drift and change-controlled. Ensembles are common in research and in high-volume, low-consequence prediction. For a model that supports a release decision, the extra 0.5 points must be weighed against that lifecycle burden.

    What the panel tells you that one model cannot

    • Is the problem linear? If PLS keeps up with the forest, yes, mostly.
    • Is there more signal to find? If every model plateaus near the same error, the limit is the data, not the algorithm. Compare the plateau with the reference method’s own noise. In Product T, vessel-to-vessel SD is about 3%, so a six-vessel batch mean carries roughly 1.2 points of noise, and run-to-run variation adds a little more. Every model stalls near 3, well above that floor. Something that drives dissolution is either not in the table or not varying enough in it to be learned.
    • Do the explanations agree? Variable importance from different model families that agrees is stronger evidence than one model’s ranking.

    None of this establishes cause. Every model here learns associations in historical batches. Reading 3 is about that limit.

    Where the analyst sits

    The analyst sets the comparison up honestly (same folds, grouped the way the model will be used) and reads the result as a distribution. They also know the error floor set by the reference method, and choose the simplest model the evidence supports. The final choice is a judgment about intended use, consequence and lifecycle cost, not a sort by RMSE.

    Graphic titled 'From Predictive Performance to Pharmaceutical Confidence', subtitled 'Linking model performance, intended use and lifecycle controls with ICH Q14 and ICH Q2(R2).' Panel 1, 'Extrapolation and applicability domain': two plots of % dissolved at 30 minutes against a process or material variable, each with a shaded region marked 'outside the applicability domain'. The linear model's line keeps rising into that region; the random forest's curve flattens into a plateau. Below, 'T² and Q monitoring'. Panel 2, 'Performance versus complexity': a balance scale. One pan holds predictive accuracy, robustness, sensitivity and improved decision-making; the other holds interpretability, validation effort, model maintenance, technology transfer, change control and drift monitoring. Panel 3, 'Intended use determines the burden of evidence': a table comparing a process advisory model with a model supporting product release. Intended use: identify potential slow batches, versus support a consequential quality decision. Model complexity: may justify a more flexible ensemble, versus must justify complexity against risk. Human oversight: scientist evaluates the prediction, versus a defined and controlled decision procedure. Lifecycle controls: proportionate to risk, versus more rigorous evidence and controls. A strip below, 'The analytical lifecycle': intended purpose, development, validation, deployment, monitoring, change control. Footer: 'The takeaway: choose the simplest model that adequately and reliably fulfills its intended purpose.'
    Why the best RMSE is not the whole decision. Models extrapolate differently, every added model carries lifecycle cost, and the evidence needed depends on whether the prediction advises the process or supports release.

    The reading on one page

    Six-panel summary figure, each panel ending in a takeaway. Panel 1, 'Many Models, One Question': Product T's inputs (API particle size D50, granule moisture, lubricant blend time, compression force, tablet hardness, supplier and equipment) feed a panel of eight models in four families (PLS and lasso; MARS and neural network; KNN and SVM; random forest and boosted trees), all answering one question, predict % dissolved at 30 minutes. Takeaway: one question, one dataset, multiple mathematical hypotheses. Panel 2, 'Eight Models, Eight Mathematical Explanations': a sketch and one-line description of how each model learns the relationship. Takeaway: different models make different assumptions about the data. Panel 3, 'A Fair Competition': model-specific recipes (a basic recipe for trees and MARS: impute missing values, encode categorical variables, remove zero and near-zero variance; a scaled recipe for PLS, lasso, SVM, KNN and the neural network that adds centring and scaling), a workflow from Product T's 60 batches through grouped cross-validation by API lot, model workflows and hyperparameter tuning to held-out predictions, and three levels of model development (preprocessing, model parameters, hyperparameters). Takeaway: compare the algorithms, not the luck of the data split. Panel 4, 'Read the Distribution, Not the Leaderboard': mean RMSE with ranges for the eight models, from random forest 3.1 (2.4 to 3.9) to KNN 4.4 (3.3 to 5.8); the one-standard-error rule, choose the simplest model within one standard error of the minimum; and the analytical noise floor, a vessel SD of 3% giving a batch-mean SE of 3 over root 6, about 1.22%, below the model RMSE of about 3 to 4. Takeaway: a lower error does not automatically mean a better analytical procedure. Panel 5, 'Ensembles, When Models Work Together': bagging (random forest), boosting (gradient boosting) and stacking, with the example stack 0.55 PLS plus 0.30 random forest plus 0.15 MARS reaching RMSE 2.9, against PLS 3.4 and random forest 3.1. Takeaway: the value of an ensemble comes from diversity in prediction errors. Panel 6, 'From Predictive Performance to Pharmaceutical Confidence': extrapolation outside the applicability domain (linear model extrapolates, random forest plateaus) with T² and Q monitoring; performance versus operational burden; intended use (process advisory versus product release) determines the evidence; and the analytical lifecycle under ICH Q14 and Q2(R2). Takeaway: choose the simplest model that adequately and reliably fulfills its intended purpose.
    The reading in one figure: the model panel, how each model explains the outcome, a fair comparison on identical grouped resamples, reading results as distributions against the measurement noise floor, ensembles, and choosing a model for its intended use. The fifth panel is misnumbered '3' in the figure.

    For discussion

    1. Why must every model in the panel use the same resampling object?
    2. The neural network has the widest spread across folds. Give two reasons a flexible model might be unstable with 60 batches.
    3. A random forest is trained on batches with 70–90% dissolved. What does it predict for a batch whose true value is 60%? What does PLS predict?
    4. Make the case for and against deploying the three-member stack for in-process prediction. Then do the same for release.

    Bridge back to the week

    Next: Correlation Is Not Causation. Return to Week 12.

    Sources

    Product T and the panel results are constructed for teaching.


    1. M. Kuhn and K. Johnson, Applied Predictive Modeling (Springer, 2013). Chapters 6–9 for the regression models; Chapter 10 compares a full model panel on one case study. DOI. ↩︎

    2. L. Breiman, “Statistical Modeling: The Two Cultures,” Statistical Science 16(3) (2001) 199–231. The classic argument for judging models by predictive accuracy, with replies from statisticians who disagree. DOI. ↩︎

    3. M. Kuhn and J. Silge, Tidy Modeling with R (O’Reilly, 2022). Chapter 11 on comparing models with resampling, Chapter 15 on workflow sets, Chapter 20 on ensembles and the stacks package. Free online at tmwr.org. ↩︎ ↩︎