Spectra Lab — chemometrics in your browser

Student access: coming soon. The interactive demo is open now.

Spectra Lab: chemometrics software for near-infrared calibration, in your browser

Partial least squares regression (PLS) and spectral preprocessing (SNV, Savitzky-Golay derivatives) for near infrared spectroscopy (near-infrared, NIR) data: upload spectra, compare preprocessing, validate with RMSECV and RPD, and flag outliers with Hotelling T2. Principal component analysis is coming next. No install, no vendor lock-in.

Works with spectra from any NIR instrument — if you can export it as a table of numbers, Spectra Lab can calibrate on it.

Spectra Lab validation screen with PLS metrics, predicted versus reference plot and residuals, next to a benchtop NIR analyzer

Interactive demo: spectral preprocessing, PLS regression and model validation

Choose a preprocessing method and watch what it does to the spectra, the RMSECV-versus-components curve, the predicted-versus-reference scatter, and the validation metrics. Start with raw spectra, then try SNV: on this real meat data it lowers the error, then compare the derivatives.

Sample spectra (5 of 172 samples) vs wavelength
    RMSECV vs number of PLS components
    Predicted vs reference fat (%) with 1:1 line

    Results computed by the Spectra Lab engine on a real public meat dataset (172 training samples, fat % as-is), 5-fold cross-validation.

    What is a Savitzky Golay filter (Savitzky-Golay algorithm)?

    A Savitzky Golay filter (also written Savitzky-Golay; the Savitzky-Golay algorithm or Savitzky-Golay smoothing) fits a low-order polynomial to a short moving window of points along each spectrum. The fitted value smooths noise; the fitted slope or curvature gives the first or second derivative, which removes baseline offsets and slopes before partial least squares regression. Window size and polynomial order set the trade-off between noise removal and losing real absorption features. In the demo above, compare "SG 1st derivative" and "SG 2nd derivative" with the raw spectra to see that trade-off on real data.

    Tour the Lab

    Six screens take you from a raw CSV to a filed validation report. Pick a step on the left; on a phone the tabs scroll sideways.

    Spectra Lab import screen showing a CSV upload with one row per sample, reference values and a preview table

    Upload a CSV with one row per sample and your reference values alongside the wavelengths. Spectra Lab previews the table so you can check the columns, the row count and the reference range before anything is computed.

    Learn more: importing spectra into Spectra Lab

    Real datasets, real results

    We ran real public NIR datasets through Spectra Lab, the same engine students use, not just simulated teaching spectra. The results line up with published work, and each one teaches a lesson worth repeating yourself.

    Mango dry matter: error on an unseen season Published paper (PLS) 1.01 Lab, SG 1st derivative 1.00 Lab, SG 2nd derivative 1.03 Lab, raw spectra 1.06 Lab cross-validation 0.87 0 1.5 % DM

    Cross-validation says 0.87; a season the model never saw says about 1.0. Our results match the published 1.01 on the full data.

    Meat fat: inside vs outside the calibration range Cross-validation 2.64 Test set (in range) 2.00 Extrapolation set 5.02 0 6 % fat

    Same model, same day: error more than doubles on samples outside the range it was trained on.

    Protein: as-is vs dry-matter basis (RPD, higher is better) As-is (wet sample) 5.66 Dry-matter basis 3.26 0 7 RPD

    The spectrum sees the wet sample, so calibrate as-is and convert for reporting. Background: As-Is vs. Dry Matter in NIR.

    Spectra Lab overview: model leaderboard with RMSECV, R2 and RPD quality bands, and an RPD comparison chart for the meat and mango models
    Lab overview: every model ranked by RPD, with quality bands (screening, rough quantitative, quantitative).
    Spectra Lab validation report for the mango dry matter model: RMSECV 0.85, R2 0.86, RPD 2.7 and the cross-validation curve by number of PLS factors
    Validation report on real mango data: metrics and the error curve that picks the number of PLS factors.

    Data: mango dry matter from Anderson, Walsh, Subedi and Hayes (2020), Postharvest Biology and Technology 168, dataset CC BY 4.0 (Mendeley Data, doi 10.17632/46htwnp833), teaching subset of 600 + 100 spectra, 684-990 nm. Meat: public-domain dataset of 240 finely chopped meat samples, 850-1050 nm transmission, fat, moisture and protein by wet chemistry (reported as-is). Results computed by Spectra Lab, PLS with 5-fold cross-validation.

    Learn by practicing

    Spectra Lab is built for learning by doing. Every concept comes as a short exercise with a goal, the steps, what you should see and why it matters, and the workbench explains each step as you go.

    1. Your first model. Import spectra, train PLS and read RMSECV, R2 and RPD.
    2. When preprocessing hurts. Compare raw spectra with SNV and see a model fall apart.
    3. Derivatives and baselines. Savitzky-Golay 1st vs 2nd derivative: baseline removed, noise added.
    4. Get a second opinion. Score new spectra against a model and see which samples get flagged.
    5. Try your own data. Import your CSV, train raw and one preprocessing, compare RPD.

    Next, with the real datasets above: inside vs outside the calibration range, a new season, and as-is vs dry-matter basis.

    Spectra Lab Start here page: learn chemometrics by doing it, with the five steps of building a calibration
    The Start here page walks through the method before the first exercise.

    Problems Spectra Lab solves

    These are the questions analysts and statisticians keep asking about calibration. Here is what the Lab does about each one today.

    “Which preprocessing should I use?”

    Compare methods side by side on your own spectra and see the error change; the demo shows SNV can destroy a signal.

    “How many PLS components should I keep?”

    The RMSECV-per-component curve and the chosen minimum, so over-fitting is visible.

    “My RMSECV looks good, will it hold on new samples?”

    RMSECV, R2 CV, RPD and bias side by side, plus Second Opinion on new spectra.

    Coming next: a separate test-set partition by lot or date.

    “Is this sample an outlier or a real product?”

    Hotelling T2 and Q residual flags per sample.

    “The software is expensive or tied to one instrument.”

    Runs in the browser on CSV from any instrument; no installation.

    “It worked on one instrument and fails on another.”

    The course lesson on calibration transfer is available today.

    Coming next: calibration transfer (slope/bias and standardization).

    Based on recurring questions from analysts and statisticians in public Q&A forums and the calibration literature.

    Free chemometrics resources on SpectroScience

    Interactive labs

    PLS factors, calibration, validation and troubleshooting

    Open the interactive labs

    Calculators

    Model diagnostics, calibration method selector and feasibility checker

    Open the calculators

    NIR Calibration and Chemometrics guide

    Read the guide

    NIR laboratory guide

    Read the guide

    NIR glossary

    Open the glossary

    NIR vs wet chemistry

    Compare the methods

    Practice quizzes

    Test yourself

    PDF: NIR cheat sheet

    Download the cheat sheet

    PDF: NIR glossary

    Download the glossary

    PDF: NIR troubleshooting guide

    Download the troubleshooting guide

    What you can do with Spectra Lab chemometrics software

    Import spectra (CSV)

    Upload your spectral data as a CSV file with one row per sample, alongside the reference values you already measured with wet chemistry.

    Preprocess (SNV, Savitzky-Golay 1st and 2nd derivative)

    Standard normal variate and Savitzky-Golay 1st and 2nd derivatives, applied consistently to every spectrum and compared side by side. Multiplicative scatter correction and baseline correction are coming.

    Calibrate (PLS regression with cross-validation)

    Build partial least squares regression models against your reference values, with cross-validation that keeps the component count honest.

    Validate and second-opinion (RMSECV, RPD, bias, T2/Q outliers, PDF report)

    Get RMSECV, RPD and bias in one view, inspect Hotelling T2 and Q residual outlier diagnostics, and export a PDF report you can file with the method.

    From calibration curve to NIR calibration in near infrared spectroscopy

    A single-wavelength calibration curve goes back to the Beer-Lambert law: absorbance is proportional to concentration, so one wavelength and a linear fit can quantify one analyte in a clean matrix. Real samples are not clean. Scattering, particle size, temperature and overlapping absorption bands break the single-wavelength assumption.

    Multivariate calibration solves this by using hundreds of wavelengths at once and letting partial least squares regression find the combinations that carry the information and reject the rest. Spectra Lab walks that whole path for you: Beer-Lambert calculator, NIR calibration methods compared: MLR, PCR, PLS and ANN, and How to build a PLS model in practice: from raw spectra to validated calibration.

    Calibration curve versus multivariate NIR calibration One wavelength: calibration curve concentrationabsorbance Whole spectrum: multivariate (PLS) calibration wavelength (hundreds of points) PLS
    Left: one wavelength and a straight line, as in the Beer-Lambert law. Right: partial least squares regression uses the whole near-infrared spectrum, which copes with scattering, particle size and overlapping bands.

    What is partial least squares regression? PLS vs principal component analysis (PCA), in plain words

    PCA: what is in my spectra?

    Principal component analysis is exploration. It finds the directions of largest variance in the spectral data and shows you whether your samples cluster, drift or split into groups. There is no reference value involved. Use it to understand your set, find outliers and see whether your calibration population is really one population.

    How to run PCA on NIR spectra step by step · How to interpret a PCA score plot

    spectra latent reference

    PLS: what is in my spectra that predicts moisture?

    Partial least squares regression is prediction with a purpose. It rotates the same kind of components, but it chooses them so that they also explain your reference values. That is why PLS regression usually beats PCA followed by regression when you actually want a number out of the instrument.

    Comprehensive chemometrics: PLS regression tutorial

    Model validation like a lab manager: RMSECV, RPD, bias and Hotelling T2

    A calibration is only as good as its validation. Spectra Lab reports the numbers a lab manager asks for, and lets you pull them into a report you can defend in an audit.

    RMSECV
    Root mean square error of cross-validation: the error you should expect on new samples from the same population, computed by leaving samples out and predicting them back.
    RMSEP and bias
    When you have an independent test set you also get RMSEP, and the bias tells you whether the model is systematically high or low rather than just noisy.
    RPD thresholds
    RPD is the ratio of reference standard deviation to prediction error. As a rule of thumb, below about 2.5 a model is only good enough for screening, and above about 3 it can be considered for quantitative use.
    Hotelling T2 and Q outliers
    T2 flags samples that sit far from the calibration centre; Q residuals flag samples the model cannot reconstruct. Together they separate unusual samples from bad spectra.

    Read more: Cross-validation in NIR calibration: leave-one-out vs k-fold · Choosing the right NIR calibration validation approach · How to detect NIR spectral outliers.

    Learning path: the course lessons that teach each step

    Spectra Lab is the practice bench for the NIR spectroscopy course. Each stage of the workflow maps to a lesson that explains the theory behind it.

    New to NIR and chemometrics? Get learner access with the NIR course.

    Read the articles behind each step

    Field-tested explanations from the SpectroScience blog, each paired with something you can try in Spectra Lab.

    Frequently asked questions

    What is partial least squares regression?
    Partial least squares (PLS) regression is a chemometric method that predicts a property, such as moisture or protein, from many correlated variables, such as the absorbances at every wavelength of a near-infrared spectrum. It finds a few latent components that explain the spectra and the property together, then regresses on them.
    What is a Savitzky-Golay filter used for in spectroscopy?
    It smooths spectra and calculates first or second derivatives by fitting a polynomial in a moving window. Derivatives remove baseline offsets and slopes, which often improves NIR calibration models.
    Is Spectra Lab free?
    The interactive demo on this page is free to use now. Student access to the full Lab is coming soon, and NIR course students will hear first.
    Which instruments' spectra work with Spectra Lab?
    It is instrument-independent. Any NIR analyzer or spectrometer whose spectra you can export as numbers will work, regardless of make or model.
    What file format does Spectra Lab accept?
    Spectra Lab accepts CSV files with one row per sample.
    Is my data private?
    Your uploads stay inside your own Spectra Lab account and are used only to run your calibrations; they are not shared with other users.
    PLS or PLS-DA?
    PLS regression predicts a continuous value such as moisture or protein, and that is what Spectra Lab does today. PLS-DA (discriminant analysis) predicts a class, such as pass or fail; it is on the Spectra Lab roadmap.
    How many samples do I need?
    As a working rule, start with at least 6 to 10 samples per PLS component you expect to need, spread across the whole range of the property you want to predict.
    How many components should I use in a PLS regression?
    Choose the minimum of the cross-validated error curve, and prefer fewer components when the curve is flat.
    What if RMSEP or RMSECV has no clear minimum?
    Pick the first component count after which the error stops improving meaningfully. A flat curve can mean the signal is weak or the preprocessing is unsuitable.
    Should I mean-center or autoscale spectra before PLS?
    Mean-centering is standard. Autoscaling gives noisy wavelengths equal weight and is usually avoided for spectra.
    How much variance should PCA capture?
    There is no fixed threshold. Use enough components to describe the systematic variation, checked with score and loading plots.
    How do I know a new sample is within my calibration?
    Check Hotelling T2 and Q residuals against the calibration limits; Spectra Lab flags both.
    Can I cross-validate with replicate scans?
    Keep all replicates of one sample in the same fold, otherwise the error looks better than it is.

    Spectra Lab is coming soon for students

    Student access is not open yet. NIR course students will be the first to know when it opens. Until then, try the free demo above and learn the method behind every button in the course.