Skip to main content

Feature Extraction Theory

Feature extraction (feature engineering) is the foundational step of the AstroSpectro pipeline. It consists of transforming a complex high-dimensional spectral signal — a spectrum with 3,921 flux channels — into a compact vector of 183 numerical descriptors that machine learning algorithms can use in an interpretable and scientifically valid way.

Key result

SHAP analysis of the reference model (spectro_only mode) attributes 96.8% of the total mean |SHAP| to physical spectral features, and 29 of its 30 most important descriptors are spectroscopic. The remainder (3.2%) comes from Gaia/photometric columns that the model also selected.

v6 · includes 4 Gaia/photometric features — see Data Leakage Audit

Our philosophy: Physics-Informed Machine Learning​

Rather than a "black box" approach (feeding raw spectra to a neural network), AstroSpectro adopts a hybrid and interpretable approach in three steps:

  1. Inform with physics — identify spectrally significant regions (absorption lines, continuum, molecular bands) from astrophysical knowledge
  2. Quantify the information — precisely measure the physical properties of each line (strength, width, profile) rather than simply knowing that it exists
  3. Learn the relationships — provide this rich and compact vector to XGBoost so it can discover the optimal decision boundaries between spectral types
Black Box (raw Deep Learning)
Not retained for AstroSpectro
Concrete example
CNN on the 3,921 raw flux channels
✓ Advantages
›No prior knowledge required
›Can capture unknown patterns
✗ Limitations
›Millions of parameters to train
›Requires ~10⁵–10⁶ annotated spectra
›Results hard to validate physically
›Sensitive to unmodelled instrumental noise
›"Why this type A?" — no answer
RETAINED
Physics-Informed + classical ML
Retained approach — AstroSpectro V2
Concrete example
XGBoost on 99 selected features (W(Hα), Ca II prominence…)
✓ Advantages
›99 interpretable features selected from 207
›SHAP validates decisions physically
›349,998 spectra — no need for millions
›Robust to noise (local features, not pixels)
›Every decision explained in astrophysical terms
›89.2% balanced accuracy (v6)
✗ Limitations
›Astrophysical expertise required to define lines
›May miss unknown patterns
v6 · includes 4 Gaia/photometric features — see Data Leakage Audit

The 6 V2 descriptor families​

The V2 pipeline builds a matrix X ∈ ℝ^(43019 × 183) by combining six complementary descriptor families, each encoding a distinct aspect of stellar physics.

Balmer lines
Hα – Hθ
~35
Hydrogen absorption series. Primary thermal indicator: maximum strength around 10,000 K (type A), weakens toward M and O.
Hα 6563 Å · Hβ 4861 Å · Hγ 4341 Å · Hδ 4102 Å · Hθ 3798 Å
→ PCA:PC1 (Balmer: 29.7% of top-10 |loadings|)
Ca II H&K + IR triplet
H 3968 · K 3933 · IR 8498–8662
~20
Ionised calcium in absorption. Sensitive to both metallicity ([Ca/H]) and stellar magnetic activity (emission core filling).
Ca II H 3968 Å · Ca II K 3933 Å · IR triplet 8498, 8542, 8662 Å
→ PCA:PC1 (Ca II: 9.3% of top-10 |loadings|)
Magnesium & α-elements
Mg b · Mg I 5184 · Mg II
~15
Mg b triplet and magnesium lines. Tracers of α-element enrichment — discriminates halo and Galactic disk populations.
Mg b 5167–5183 Å · Mg I 5184 Å · Mg II 4481 Å
→ PCA:PC1 (W(Mgb) = −0.171)
Iron peak metals
Fe, Cr, V, Ni, Ba, Sr...
~30
Iron peak element lines. Direct measurement of iron abundance and heavy metals. Dominate PC2.
Fe I 5270, 5335 Å · Cr I · V I · Ni I · Ba II · Sr II
→ PCA:PC2 ([Fe/H]proxy: +0.205)
Lick/SDSS/CaH indices
Lick IDS indices · CaH · TiO
~18
Standardised spectral indices. Narrow-band combinations calibrated to measure age and metallicity of stellar populations.
Lick IDS indices · CaH1, CaH2 · TiO1, TiO2 · SDSS composites
→ PCA:PC2 (metal index: +0.198)
Continuum · slopes · colours
Flux ratios · photom. indices
~65
Global spectral continuum shape. Largest family by count. Encodes temperature via blackbody slope and luminosity via spectral breaks.
fblue/fred · synthetic B−V · local slopes · photometric indices
→ PCA:PC1 (continuum: fblue/fred = +0.161)
183 features · 6 spectroscopic families · complete catalogue →

Concrete extraction — from spectrum to vector​

Spectral lines: prominence, FWHM, equivalent width​

For each absorption line defined in the line dictionary (feature_engineering.py), three fundamental metrics are extracted:

from specutils.analysis import equivalent_width, gaussian_fwhm

# Example for Hα (6562.8 Å)
window = SpectralRegion(6540 * u.AA, 6580 * u.AA)

prominence_ha = continuum - flux_minimum # line strength
fwhm_ha = gaussian_fwhm(spectrum, window) # full width at half maximum
ew_ha = equivalent_width(spectrum, window) # equivalent width W(Hα)

Physical interpretation:

  • Prominence: line depth → strength of the atomic transition in the atmosphere
  • FWHM: width → atmospheric pressure, surface gravity, thermal velocity
  • EW — W(line): equivalent width → abundance of the ionic species, temperature

Line ratios — composite physical proxies​

Ratios between lines are computed because they have direct physical meaning:

# Ca II K / Hβ — temperature proxy (varies with Teff)
feature_ratio_CaK_Hbeta = prominence_CaII_K / prominence_Hbeta

# W(Mg b) / W(Na D) — sensitive to [Mg/Fe] and gravity
feature_ratio_EW_MgB_NaD = ew_mgb / ew_nad

# Balmer index — temperature gradient along the series
feature_balmer_temperature_index = (ratio_gamma_beta + ratio_delta_gamma) / 2

Why ratios rather than absolute values? Ratios are invariant to instrumental variations (flux normalization, seeing) and encode differences between populations rather than absolute levels.

Continuum — global spectrum morphology​

The shape of the continuum encodes temperature (blackbody slope) and luminosity class (spectral breaks):

# Local slopes (sigma-clipped, σ = 2.5 — robust to lines)
feature_slope_blue = fit_slope(flux, 3800, 4200) # UV → blue
feature_slope_red = fit_slope(flux, 5500, 6500) # red visible
feature_slope_deep_red = fit_slope(flux, 6500, 7500) # near IR

# Blue/red asymmetry — direct Teff proxy
feature_continuum_asymmetry = (f_blue - f_red) / (f_blue + f_red)

# D4000 break — age and metallicity indicator
feature_break_4000A_strength = flux_4050_4250 / flux_3750_3950

spectro_only=True mode — The scientific core​

The spectro_only=True mode is the required condition for scientifically rigorous results. It excludes all non-spectral variables from the feature vector.

Variables excluded and why​

VariableTypeReason for exclusion
ra, decAngular coordinatesEncode where the spectrum was observed, not the physics of the star
redshiftLAMOST metadataCorrelated with observation programs targeted by spectral type
seeing, snr_*Instrumental conditionsRelated to night quality, not stellar physics
parallax, teff_gspphotGaia columnsData leakage — these are targets/validation data, not features
Feature leakage

Without spectro_only=True, ra and dec can artificially increase the apparent accuracy: LAMOST observing programs target certain sky regions according to the expected spectral type. A model then learns to classify by position in the sky rather than by stellar physics, which does not generalize.

Implementation in the pipeline​

from src.pipeline.classifier import SpectralClassifier

clf = SpectralClassifier(
model_type="XGBoost",
prediction_target="main_class", # A / F / G / K / M
)

# spectro_only=True guarantees that only the 183 spectral features are used
clf.train_and_evaluate(features_df, spectro_only=True)

# Returns the run's metrics: balanced accuracy, ROC-AUC, per-class scores

SHAP validation — Physics confirmed​

SHAP analysis (SHapley Additive exPlanations) on the trained model makes it possible to verify a posteriori that the features being used are indeed physical.

Central result​

MetricValue
Spectroscopic features in the top-3029 of 30
Spectroscopic share of the summed mean |SHAP|96.8%
Gaia/photometric share of the summed mean |SHAP|3.2%
SHAP ranks 1–5feature_Mg_b_eq_width, feature_index_CaH2, feature_slope_deep_red, feature_CaIIK_eq_width, feature_Hα_eq_width

Why PCA and XGBoost rank features differently​

The reference model does not rank the Balmer lines first, while PCA's first axis is thermal. This is expected, because the two methods answer different questions:

  • PCA searches for the direction of maximum variance → Balmer varies more within the full population → thermal PC1
  • XGBoost searches for the optimal decision boundary → in the reference run, Mg b, the CaH2 band and the deep-red slope carry most of the separation between classes (Ca II K equivalent width is rank 4, Hα rank 5)
PCA : Which feature varies the most overall? → Balmer (T_eff)
XGBoost : Which feature best separates the classes? → Mg b, CaH2, deep-red slope

These two results are consistent and complementary — they answer different questions about the same physics.

Top SHAP features by spectral class​

Top three features per class in the reference run v6 (read off class_specific_importance.png; see SHAP Interpretability for the figure and caveats):

ClassTop three SHAP features
ACa II K equivalent width, G4300 index, CN₂ index
FMg b equivalent width, Na D equivalent width, continuum curvature
GMg 5184 equivalent width, CNO index, EW(Hα)/EW(Hβ) ratio
KMg b equivalent width, Hα equivalent width, deep-red slope
MCaH2 index, deep-red slope, continuum RMS

No physical interpretation per class is claimed; these are model-relevance rankings, not physical measurements.

---:|:---|:---| | A | Hα EW↓, Hβ FWHM↑, strong W(Hγ) | Very broad Balmer lines — hot stars > 7,500 K | | F | Moderate Hα, emerging Ca II K | Balmer → Ca II transition (6,000–7,500 K) | | G | Strong Ca II K+H, Mg b, W(Hα) | Solar-type star — metallicity + intermediate T_eff | | K | Very strong Ca II K, emerging TiO | Cool metal-rich stars (3,700–5,200 K) | | M | TiO, VO, CaH bands, Balmer↓ | Characteristic molecular bands < 3,700 K |


Connection with the PHY-3500 results​

The set of 183 descriptors is exactly the one used in the Baker, Caillat & Jean report (April 28, 2026). The same features simultaneously feed:

MethodUse of the 183 featuresResult
PCA183×183 covariance matrixPC1 = thermal axis (ρ(Teff) = +0.831)
UMAP + t-SNE183D → 91 PCA → 2D projectionEmerging Harvard sequence
HDBSCANClustering in UMAP space20 clusters · dwarf/giant distinction
XGBoost (reference run, G2)207 candidate features → 99 selected → decision boundaries89.2% balanced accuracy
SHAP (reference run, G2)Attribution by feature96.8% of the summed mean |SHAP| from physical features

The PCA, UMAP, t-SNE and HDBSCAN rows are PHY-3500 · G1 · 43,019 spectra; the XGBoost and SHAP rows describe the G2 reference run and are not computed on the same spectra.