Olive oil line (12:20–13:44, extra virgin grading, prone to adulteration) ↗ Canola oil line (12:02–13:31, deodorizing and refining / acid value / peroxide value) ↗ Soybean oil line (08:00–09:28, hexane extraction) ↗
Today's question: if a bottle of oil is mislabeled (say, labeled “extra virgin olive oil” but actually blended with refined olive oil or another oil), can spectra + PCA reveal it? (We'll come back to this at the score plot — but you'll also see that PCA can sometimes be fooled by a single outlier.)
Full narration and captions; original simulated course spectra. Player and downloads · Interactive lab
| Sample | 900 cm⁻¹ | 915 cm⁻¹ | 931 cm⁻¹ | 946 cm⁻¹ | 961 cm⁻¹ | … |
|---|---|---|---|---|---|---|
| EVOO_r1 | 0.005 | 0.013 | -0.011 | 0.004 | 0.004 | … |
| COC_r1 | 0.015 | 0.048 | -0.002 | -0.021 | 0.048 | … |
| SOY_r1 | -0.018 | -0.041 | -0.046 | 0.007 | -0.016 | … |
| PEA_r3 | 0.084 | 0.073 | -0.026 | 0.077 | 0.095 | … |
| …(18 spectra in total) | …(60 wavenumber columns in total) | |||||
The table values come from the same CSV used in Colab NB10 (nb10_demo_spectra.csv), not made up separately.
Values are taken from column 50 (1647 cm⁻¹) and column 25 (1266 cm⁻¹) of the same spectral dataset, not invented.
t = the sample's score on this PC; pⱼ = the loading (weight) of wavelength j; xⱼ−x̄ⱼ = the mean-centered value at that wavelength
| Wavelength | Raw value x | x − x̄ (mean-centered) | ÷ SD (autoscaled) |
|---|---|---|---|
| Signal wavelength | 0.8 / 1.0 / 1.2 | −0.2 / 0 / 0.2 | −1 / 0 / 1 |
| Noise wavelength | 1.001 / 0.999 / 1.000 | 0.001 / −0.001 / 0 | 1 / −1 / 0 |
Both rows use the sample standard deviation (SD) (calculated as in W01 ↗; signal row SD=0.2, noise row SD=0.001).
The larger λₐ is, the more spread out the samples are along the a-th PC — and the more “important” that PC is.
The data come from the same simulated Raman spectra used in Colab NB10 (nb10_demo_spectra.csv); the PCA was computed live when this page was built, so the numbers are guaranteed to match NB10. Point color = oil; three points of the same color = three replicates.
Same data, with that one spectrum removed and PCA rerun live (Colab NB10 sections 3 and 7 have the full version).
oil as the target; set sample_id / group / instrument / rep / oil_zh as meta — leave the numeric wavenumber columns as they are, as featuresSee also tools.html: Orange workflow OR12 ↗
The Colab / R code below is an advanced option — you can finish today's analysis with the Orange steps on the previous page, no coding needed.
Advanced: Colab (scikit-learn, 5 lines):
Advanced: R (prcomp):
Colab NB10: Open NB10 in Colab ↗. Backup dataset: Five-sugar NIR backup dataset (chemometrics-teaching) →
| Time | Contents |
|---|---|
| 0:00–0:45 | Lecture: data table, scores/loadings, mean-centering / autoscaling, explained variance, how a single outlier hijacks a PC |
| 0:45–2:05 | Six oils × 3 replicates: Raman 785 rotating-station measurement + each group's NIR measurement (melt coconut oil first) |
| 2:05–2:30 | Preprocess in SpectraView (SNV / derivatives optional) and export an X matrix with one sample per row |
| 2:30–3:30 | Run PCA in Orange: score plot (colored by oil), loadings (vs wavenumber), explained variance; if you find an outlier, first check the raw spectrum and the measurement log, confirm the anomaly and record the reason, then remove or re-measure it and redo the PCA |
| 3:30–4:00 | Groups swap data and compare whether the score plots from different instruments (NIR) agree |
Colab NB10: Open NB10 in Colab ↗ · Beginner (no coding): Orange workflow OR12 ↗. Backup dataset: Five-sugar NIR backup dataset (chemometrics-teaching) →
Tap to tick — make sure you really can do it.