
The one idea
Model development begins with a decision and ends with evidence about performance on new material. Choosing an algorithm is one step in that process.
This reading adapts the framework in Max Kuhn and Kjell Johnson’s Applied Predictive Modeling (Springer, 2013), particularly Chapters 2–4. The pharmaceutical case and lifecycle discussion are teaching additions, not a reproduction of the authors’ exact sequence [1, 2].
In reading 1, near-infrared (NIR) spectroscopy posed a material-identity question. Here the task changes: can an NIR measurement estimate water content in granules during drying? Identity is a classification or class-membership problem. Water content is a numerical prediction problem, also called regression.
One synthetic dataset runs through the steps. Thirty drying batches, eight samples per batch taken across the drying curve, three replicate NIR scans per sample, and one Karl Fischer result per sample: 720 spectra in all. The simulation builds in what makes the steps matter. Particle size scatters whole spectra; each batch’s excipient lot leaves a small spectral signature; the probe zone and the sampling point differ by a batch-specific offset; and the water response flattens as the bed gets wetter. The figures at steps 3, 5, 7 and 9 are computed from it, and the spectra and references are there to download. Week 12’s R readings apply the same preprocessing logic in code.
1. Define the decision
Imagine a wet-granulation process followed by drying (the solids-manufacturing train from Week 2). The team wants frequent estimates of granule water content to support assessment of the drying endpoint.
Before collecting spectra, write down the intended use. Which formulation, equipment, moisture range and operating conditions are covered? How quickly is a result needed? What prediction error is acceptable near the endpoint? What happens if the result is wrong?
A useful monitoring model is not automatically adequate for automatic process control or release. Those decisions may need different evidence and controls. State the proposed role before deciding whether the results are good enough.
For the synthetic case, the team writes the requirement down now, before any data exist: the endpoint is judged at 2.0% w/w water, and predictions on new batches must have a root mean square error of prediction (RMSEP) of no more than 0.30% w/w for samples below 3% w/w. Both numbers are illustrative teaching choices, not recommended criteria. The point is that step 9 is checked against them, not against whatever the model happens to achieve.
Output of this step: a prediction objective and performance requirements tied to the intended decision.
2. Define Y: what are we trying to predict?
The outcome, Y, is water content measured by an appropriate reference procedure, such as Karl Fischer titration. Specify the units and reporting basis. Water content and loss on drying are not interchangeable labels: loss on drying counts every volatile, not only water.
Match each NIR measurement to a reference sample representing the same material and the same time. A spectrum from the dryer bed paired with an unrelated sample from another location creates a mismatch that no algorithm can fix.
Assess the reference procedure’s suitability and uncertainty. The model learns against those results, including their limitations.
Output: a defined outcome and a defensible way to establish its reference value.
3. Define X and what one observation means
The predictors, X, are the inputs available when making a future prediction. They might include the NIR spectrum and, if justified, process temperature.
| Data element | Role |
|---|---|
| NIR response at each retained wavelength | Candidate predictors |
| Matched Karl Fischer water result | Reference outcome |
| Batch and sample identifiers | Traceability and grouping |
| Timestamp, location, instrument, temperature | Measurement context; some may also be justified predictors |
| Supplier, particle size, formulation | Context for coverage, confounding and applicability |
One row might represent one matched spectrum/reference sample pair. Repeated scans of that sample are related observations. They help characterize repeatability but do not create independent material examples.
Avoid predictors that will not be available at the moment of use. Including the final laboratory water result as an input would make development look excellent while defeating the purpose of the prediction.

Output: a data dictionary, a sampling unit, and a clear separation of predictors, outcome and contextual metadata.
4. Check integrity and scientific coverage
Resolve mismatched identifiers, inconsistent units, duplicated records, missing reference results and documented acquisition failures. Retain original records and document corrections and exclusions.
Then ask whether the data represent the intended application. Include relevant variation in batches, moisture, temperature, raw materials and physical properties. Temperature and particle size can change the NIR response even when water content is unchanged.
An unusual observation is a reason to investigate. Removing it only because it worsens the fit can hide exactly the situation the model will face later.
Basic record checks can come before splitting. Choices learned from distributions or performance, such as outlier thresholds, transformations and variable selection, belong within development, with the test data protected from them.
Output: traceable data and an assessment of what the available examples do and do not cover.
5. Protect a final test set
Divide the available examples into development data and held-out test data. Within development, use resampling to select preprocessing, algorithms and tuning settings [1, 2].
| Partition | What it is used for | What it must not become |
|---|---|---|
| Training/development set | Fit and compare candidate pipelines using resampling | Evidence based only on fitting its own examples |
| Assessment folds within development | Evaluate candidates during tuning | A claim of untouched final testing |
| Held-out test set | Assess the selected, frozen pipeline | A repeated guide to model revision |
Splitting should reflect the future prediction task. If the goal is performance on new batches, keep all observations from a batch together. Otherwise neighboring measurements from the same drying run land in both training and assessment, and the task becomes artificially easy. Week 12, reading 1 shows what that leakage looks like in production.
A concrete splitting example
Suppose a teaching dataset contains 30 independent drying batches. An illustrative plan reserves 6 complete batches for final testing and uses the remaining 24 for development. Inside development, grouped cross-validation holds out subsets of whole batches in turn.

These counts illustrate the structure; they are not a recommended sample size or a universal 80/20 rule. The actual allocation depends on the number of independent units, coverage, and the uncertainty in the performance estimates. A future-time or supplier challenge may be appropriate when that matches the intended use.
6. Fit preprocessing inside resampling
Preprocessing can include centering, scaling, scatter correction, spectral derivatives, missing-value handling or wavelength selection. Its suitability depends on the measurement and the model.
For each cross-validation split:
- Use only that split’s training portion to estimate data-dependent preprocessing.
- Fit the candidate model to the transformed training portion.
- Apply the fitted preprocessing and model to the assessment portion.
- Record prediction performance.
Centering illustrates the rule. Calculate the training means, then subtract those same means from the assessment samples. Do not calculate the means from the combined training and assessment data.
Principal component analysis (PCA) also learns from data. If it is part of a predictive pipeline, fit it inside the resampling. Computing principal components from the full dataset before evaluation leaks information about the assessment samples into development.
The object being evaluated is the entire pipeline: preprocessing plus prediction.
7. Compare models and tune their complexity
Start with a simple benchmark, such as predicting the training mean water content for every sample. Then consider scientifically appropriate alternatives, including partial least squares (PLS) regression for the spectral example.
PLS relates spectral variation to the reference outcome through components. The number of components is a tuning choice. Too few may miss relevant relationships; too many may capture noise or incidental features of the development samples.

Read the three curves together. RMSEC always falls as latent variables are added, because each one fits more of the development data, noise included; it can never tell you when to stop. Random-scan cross-validation promises 0.18% w/w at 5 latent variables, because the assessment scans’ replicates and batch-mates are in training and the model has partly memorised each batch’s offset through its excipient-lot signature. Whole-batch cross-validation is the only curve that turns upward, at 0.25% w/w, and that is the error new batches actually produce at step 9. Every candidate beats the benchmark of predicting the mean (1.88% w/w) by a wide margin, so the useful question is not whether PLS works but how many latent variables the evidence supports.
Compare candidate pipelines using the same resampling partitions and predefined performance measures. Preprocessing choices and selected variables count as development choices too. Repeatedly trying options can overfit the development assessment results, which is another reason to protect the final test set.
8. Judge performance where the decision matters
A high R² does not establish suitability. Examine:
- Prediction error: how far predictions fall from reference values.
- Bias: whether the model tends to overpredict or underpredict.
- Residual patterns: whether errors vary with moisture, batch, temperature or supplier.
- Endpoint performance: whether the error is acceptable where the drying decision is made.
- Applicability: whether the procedure can flag unsupported samples or conditions.
A model can perform well over the broad drying range while being inadequate near the endpoint. Aggregate performance can hide the weakness that matters operationally.
Choose a pipeline that meets the intended need and can be maintained. Complexity is useful when it delivers dependable improvement.
9. Freeze, refit and test
Lock the selected preprocessing, variables, algorithm, tuning settings and decision rules. Fit the selected pipeline to the development set. Then apply it to the untouched test batches.
Report performance against the predefined requirements, including relevant batch-level results and uncertainty. Do not adjust the model repeatedly while inspecting the test results and still call that evaluation independent.

The figure answers step 8’s questions in order. The prediction error in the endpoint window meets the step-1 requirement. The bias there is small overall, −0.06% w/w. But the residual pattern says more than either number: errors cluster by batch, and B10 and B14 read about 0.4% w/w drier than their Karl Fischer results across the whole drying curve. A model that reads drier than the reference stops drying early, so that is the finding to take into step 10. Before anyone recalibrates, it is a step-4 question: what was different about where the probe sat, or which excipient lot those batches used?
If testing reveals an inadequacy, investigate and revise as needed. Recognize that the inspected test set has now influenced development; a revised procedure needs a new independent assessment.
10. Establish suitability for use and monitor it
Predictive testing is part of the evidence for an analytical procedure. Pharmaceutical implementation also needs an appropriate sampling procedure, reference-method support, intended-use validation, operating instructions, exception handling and change control. Current Q14 and Q2(R2) provide the development and validation context [3, 4].
Deploy the versioned pipeline, including preprocessing parameters, not only the model coefficients. Define responses to missing spectra, probe fouling, out-of-domain samples and unavailable predictions.
Monitor reference-check errors and relevant diagnostics over time. A supplier change or altered process environment may need investigation, additional samples or controlled redevelopment. An automatic model update is not a substitute for deciding whether the change is scientifically and operationally justified. Reading 7 works that case.
Where the analyst sits
The analyst asks whether X represents the material, whether Y is trustworthy, whether the test resembles future use, and whether an error is acceptable for the decision.
That is the link to analytical procedure development: the intended purpose decides what evidence the complete measurement system must supply.
For discussion
- Why is a random split of individual scans potentially misleading when many scans come from the same batch?
- Which preprocessing steps learn parameters from data? Where must they be fitted during cross-validation?
- A model has excellent overall error but systematic bias near the drying endpoint. Is it suitable for endpoint control? What additional evidence is needed?
- A team changes its model after reviewing the test results. What has changed about the role of that test set?
Bridge back to the week
Next: From One Wavelength to a Whole Spectrum, which looks inside PCA, class modeling and PLS. Return to Week 11.
Data and sources
The synthetic moisture dataset: spectra and Karl Fischer references (720 scans × 141 wavelengths, with each scan’s batch, sample, drying time, reference and split role), split plan, tuning curves, test predictions, test summary, simulation assumptions, reproduction script and requirements. Figures: 3840 × 2160 pixels, computed with fixed seeds. PLS is a plain NIPALS PLS1 in NumPy, so the script shows every step rather than hiding it in a library call.
[1] M. Kuhn and K. Johnson, Applied Predictive Modeling (Springer, 2013). Chapters 2–4 introduce the modeling workflow, preprocessing, splitting, resampling, overfitting and tuning. This reading is an original pharmaceutical adaptation. DOI.
[2] Authors’ chapter guide: Chapter 2 for the overview, Chapter 3 for preparation, Chapter 4 for tuning and evaluation. Detailed contents.
[3] International Council for Harmonisation (ICH) Q14, Analytical Procedure Development. Development and lifecycle context for model-based analytical procedures. Guidance page.
[4] ICH Q2(R2), Validation of Analytical Procedures. Validation in relation to the intended purpose. Guidance page.
The drying case, the 30-batch dataset, the endpoint and the step-1 requirement are constructed teaching examples, not a recommended sample size, acceptance criterion or validated procedure.