Application of partial least squares discriminant analysis to mid-infrared spectral data for discriminating green and roasted coffee processed by different post-harvest methods: MATLAB- and R-based computational tools and modeling pipelines
Related Experiment Video
Updated: Oct 31, 2026

Construction of Models for Nondestructive Prediction of Ingredient Contents in Blueberries by Near-infrared Spectroscopy Based on HPLC Measurements
Published on: June 28, 2016
Gentil A Collazos-Escobar1,2, Andrés F Bahamón-Monje1,3, Nelson Gutiérrez-Guzmán1
1Centro Surcolombiano de Investigación en Café (CESURCAFÉ), Departamento de Ingeniería Agrícola, Universidad Surcolombiana, Neiva-Huila, 410001, Colombia.
Abstract:
This article presents a mid-infrared spectral dataset of green and roasted specialty coffee subjected to wet (W), semi-dry (SD), and dry (Dr) post-harvest processing, accompanied by MATLAB-based feature-extraction tools and R-based Partial Least Squares Discriminant Analysis (PLS-DA) modeling pipelines for discriminating coffee according to its post-harvest processing method. The dataset comprises raw, baseline-corrected, Standard Normal Variate (SNV), Multiplicative Scatter Correction (MSC), and Savitzky-Golay first- (D1) and second-derivative (D2) spectra, enabling the investigation of spectral variability associated with post-harvest processing and roasting, as well as the influence of spectral preprocessing on classification performance. The MATLAB routines extract six quantitative spectral features: integral (INT), energy (ENG), standard deviation (STD), skewness (SKE), kurtosis (KURT), and entropy (ENT). The R workflow provides an interactive framework for PLS-DA modeling based on four predictor representations: (i) full-spectrum data, (ii) full-spectrum data restricted to predefined spectral regions, (iii) features extracted from the entire spectrum, and (iv) features extracted from predefined spectral regions. Models can be developed using green coffee, roasted coffee, or both stages and configured for either multiclass discrimination among W, SD, and Dr processing methods or pairwise binary discrimination (W vs. Dr, W vs. SD, and SD vs. Dr). The computational pipeline integrates class definition, stratified training-validation partitioning, model calibration and prediction, K-fold out-of-fold cross-validation (OOF-CV), holdout validation, confusion matrices, overall and class-specific classification metrics, and visualization of scores, loadings, variable importance in projection (VIP), and model diagnostics. Metadata describing the post-harvest processing method and coffee stage are included to facilitate sample traceability and model interpretation. The integrated dataset and computational tools provide a reproducible framework for investigating the potential of mid-infrared spectroscopy to discriminate coffee post-harvest processing methods and support further developments in coffee authentication, quality control, and the application of chemometric methods to agri-food spectral data.
