Fermi-LAT 4FGL-DR4 Random Forest Classifier (v2.0.0)
Leak-free 3-class (Blazar / Pulsar / Other) and binary (Blazar / Pulsar) scikit-learn Random Forest classifiers (300 trees, max_depth=10, min_samples_leaf=4, class_weight="balanced") trained on public NASA Fermi-LAT 4FGL-DR4 gamma-ray observations and depth-harmonized multi-wavelength survey counterparts (radio, AllWISE mid-infrared, and X-ray).
All six v2 models are exported in two safe, portable formats:
.skops(skops.io): nativescikit-learndeserialization withoutpicklecode-execution risks..onnx(skl2onnxwithzipmap=False): runtime-stableTreeEnsembleClassifiergraphs outputting clean float32 probability arrays ((N, 3)for 3-class[P(blazar), P(pulsar), P(other)],(N, 2)for binary[P(blazar), P(pulsar)]).
See config.json for exact feature orderings, clipping/fill bounds, SHA-256 checksums, and evaluation metrics.
What Changed in v2.0.0
- Removed the
is_plec(PLSuperExpCutoff) catalog leak: In4FGL-DR4,PLSuperExpCutoffis assigned almost exclusively to bright, already-confirmed pulsars (269 / 320confirmed pulsars vs.0 / 2,563unassociated sources). Dropping it removes a confirmation-bias shortcut so models evaluate unlabeled sources honestly on spectral curvature, slope, variability, flux, significance, and multi-wavelength counterparts. - Added a confirmed
Otherclass (246sources): Instead of forcing every source onto a 0-to-1 blazar/pulsar axis, the 3-class models add246confirmed non-blazar, non-pulsar gamma-ray sources (rdg,snr,glc,pwn,hmb,bin,lmb,nov,sbg,nlsy1,agn,gal,sfr,css,sey,ssrq,gc), while keeping132unconfirmedsppspatial coincidences out of training.
Exported Models & 5-Fold Out-of-Fold Benchmarks
Evaluated with StratifiedKFold(n_splits=5, shuffle=True, random_state=42) on 4,499 confirmed sources for 3-class (3,933 blazars, 320 pulsars, 246 other) and 4,253 sources for binary (3,933 blazars, 320 pulsars).
3-Class Models ([blazar, pulsar, other])
| Model ID | Features | Macro ROC-AUC | OvR ROC (Blz / Psr / Oth) |
PR-AUC (Blz / Psr / Oth) |
Prec at ≥ 0.60 (Blz / Psr / Oth) |
Unassoc ≥ 0.60 (Blz / Psr / Oth) |
|---|---|---|---|---|---|---|
rf_3class_gamma_6feat |
6 | 0.8729 |
0.9122 / 0.9651 / 0.7415 |
0.9820 / 0.6859 / 0.2682 |
97.5% / 64.0% / 54.8% |
818 / 299 / 176 (1,293) |
rf_3class_mw_21feat (flagship) |
21 | 0.9369 |
0.9554 / 0.9790 / 0.8763 |
0.9916 / 0.8023 / 0.5023 |
98.5% / 80.1% / 72.1% |
743 / 362 / 119 (1,224) |
rf_3class_mw_sky_blind_20feat |
20 | 0.9346 |
0.9538 / 0.9786 / 0.8715 |
0.9912 / 0.7999 / 0.4887 |
98.6% / 80.6% / 72.3% |
711 / 360 / 108 (1,179) |
At strict ≥ 0.70 probability, rf_3class_mw_21feat achieves 98.9% blazar precision (452 unassociated), 86.4% pulsar precision (212 unassociated), and 82.7% other precision (36 unassociated; 700 total calls).
Leak-Free Binary Models ([blazar, pulsar])
| Model ID | Features | ROC-AUC | PR-AUC (Pulsar) | Bal. Acc (0.50) |
Prec / Rec (0.70) |
Unassoc P ≥ 0.70 / P ≤ 0.30 |
|---|---|---|---|---|---|---|
rf_binary_gamma_6feat |
6 | 0.9770 |
0.8556 |
91.4% |
76.6% / 78.8% |
612 / 1,243 |
rf_binary_mw_21feat |
21 | 0.9880 |
0.9140 |
94.0% |
88.1% / 78.8% |
674 / 1,048 |
rf_binary_mw_sky_blind_20feat |
20 | 0.9885 |
0.9106 |
94.0% |
88.5% / 79.7% |
639 / 1,102 |
In the leak-free binary comparison, adding multi-wavelength counterparts lifts ROC-AUC by +0.0110 (p < 0.001) and pulsar PR-AUC by +0.0584 (p < 0.001), while the +1.0° RA shifted-sky null control drops to 0.9742 ROC-AUC (-0.0028, p = 0.107), confirming zero spatial or catalog leakage.
Quickstart
1. Load safely with skops (Flagship 3-Class Model)
import numpy as np
import skops.io as sio
model_path = "models/rf_3class_mw_21feat.skops"
untrusted = sio.get_untrusted_types(file=model_path)
print("Audited types:", untrusted)
clf = sio.load(model_path, trusted=untrusted)
# Example 21-feature vector ordered per config.json["models"]["rf_3class_mw_21feat"]["features"]
X = np.array([[
2.25, 0.94, -11.4, 20.23, 1.0, 10.87, # 6 gamma-ray features
1.0, 1.13, 0.53, 0.0, 0.0, 0.0, # 6 radio features
0.0, 0.0, 0.20, 3.67, 1.70, # 5 WISE infrared features
0.0, -15.5, -4.5, 0.0 # 4 X-ray features
]], dtype=np.float64)
probs = clf.predict_proba(X)[0] # [P(blazar), P(pulsar), P(other)]
print(f"P(blazar)={probs[0]:.3f}, P(pulsar)={probs[1]:.3f}, P(other)={probs[2]:.3f}")
2. Run portable inference with onnxruntime (no scikit-learn required)
import numpy as np
import onnxruntime as ort
sess = ort.InferenceSession("models/rf_3class_mw_21feat.onnx", providers=["CPUExecutionProvider"])
input_name = sess.get_inputs()[0].name
X = np.array([[
2.25, 0.94, -11.4, 20.23, 1.0, 10.87,
1.0, 1.13, 0.53, 0.0, 0.0, 0.0,
0.0, 0.0, 0.20, 3.67, 1.70,
0.0, -15.5, -4.5, 0.0
]], dtype=np.float32)
labels, probs = sess.run(None, {input_name: X})
print(f"pred_class={labels[0]}, probs=[{probs[0, 0]:.3f}, {probs[0, 1]:.3f}, {probs[0, 2]:.3f}]")
Feature Schema & Missing-Value Handling
All multi-wavelength counterpart checks are performed inside each 4FGL-DR4 95% error ellipse (r_ell_95 <= 1.0) across depth-harmonized radio (LoTSS DR3, RACS-mid, NVSS, SUMSS at S_1.4eq >= 2.5 mJy), AllWISE mid-IR, and X-ray (eROSITA-DE DR1/DR2, ROSAT 2RXS) catalogs.
Gamma-Ray Features (Indices 0..5)
| Index | Name | Definition & Bounds |
|---|---|---|
| 0 | pl_index |
4FGL photon spectral index (PL_Index) |
| 1 | log_var |
log10(clip(variability_index.fillna(1.0), 0.1, None)) |
| 2 | log_eflux |
log10(clip(energy_flux, 1e-16, None)) (100 MeV–100 GeV, erg/cm²/s) |
| 3 | abs_b |
abs(bii.fillna(0.0)) (omitted in *_sky_blind_* models) |
| 4 | is_curved |
1.0 if spectrum_type in {"LogParabola", "PLSuperExpCutoff"}, else 0.0 |
| 5 | sig |
detection_significance.fillna(0.0) (Signif_Avg) |
Multi-Wavelength Features (Indices 6..20 in 21feat; 5..19 in sky_blind_20feat)
| Name | Definition & Sentinel Fill When Missing |
|---|---|
has_radio_95 |
1.0 if S_1.4eq >= 2.5 mJy inside r_ell_95 <= 1.0, else 0.0 |
log_radio_s14 |
log10(clip(S_1.4eq, 0.1, None)) when has_radio_95 == 1, else -1.0 |
log_radio_to_gamma |
log10(clip(S_1.4eq, 0.1, None)) - (log_eflux + 12.0) when has_radio_95 == 1, else -3.0 |
has_radio_alpha |
1.0 if two-band radio spectral index alpha is finite and has_radio_95 == 1, else 0.0 |
radio_alpha_filled |
clip(radio_alpha, -3.5, 2.5) when has_radio_alpha == 1, else 0.0 |
is_steep_radio |
1.0 if has_radio_alpha == 1 and radio_alpha < -1.1, else 0.0 |
has_wise_strip_95 |
1.0 if an AllWISE match lies in 0.50 <= W1-W2 <= 1.85 and 1.90 <= W2-W3 <= 4.45 inside 95% ellipse, else 0.0 |
has_radio_wise_strip_95 |
1.0 if radio counterpart also matches a WISE Blazar Strip source inside 95% ellipse, else 0.0 |
wise_w1_w2_filled |
clip(W1 - W2, -1.0, 3.0) if finite, else 0.0 |
wise_w2_w3_filled |
clip(W2 - W3, -1.0, 6.0) if finite, else 0.0 |
wise_strip_dist_filled |
clip(wise_strip_dist, 0.0, 5.0) if finite, else 5.0 |
has_xray_95 |
1.0 if X-ray detection inside 95% ellipse (ROSAT 2RXS clipped to 1e-15..1e-10), else 0.0 |
log_xray_flux |
log10(clip(xray_flux, 1e-16, 1e-9)) when has_xray_95 == 1, else -15.5 |
log_fx_fg |
clip(log10(clip(xray_flux, 1e-16, 1e-9)) - log_eflux, -4.5, 2.5) when has_xray_95 == 1, else -4.5 |
xray_hr_filled |
clip(xray_hr, -1.0, 1.0) when has_xray_95 == 1 and finite, else 0.0 |
Included Predictions Table
data/fermi_4fgl_3class_predictions.csv contains all 2,563 unassociated 4FGL-DR4 sources scored by the v2 3-class and binary models (p_blazar_3c_mw, p_pulsar_3c_mw, p_other_3c_mw, sky-blind 3-class probabilities, leak-free binary probabilities, and labels at 0.60 / 0.70).
Limitations
- Small, heterogeneous
Otherclass:Othercombines246confirmed non-blazar, non-pulsar emitters across supernova remnants, pulsar wind nebulae, globular clusters, radio galaxies, binaries, and novae, so its precision (72.1%at≥ 0.60,82.7%at≥ 0.70) trails blazars and pulsars. - X-ray survey asymmetry:
eROSITA-DEpublic data covers the western Galactic hemisphere (180° <= l < 360°), while the eastern half relies on shallower all-skyROSAT 2RXS. - Candidate prioritization, not confirmation: High
P(pulsar)scores rank sky fields for follow-up observations; confirming a pulsar requires detecting periodic radio or gamma-ray pulsations.
Reproducing, Verifying & Downloading
python -m pip install -r requirements.txt
python scripts/verify_artifacts.py
Download via hf:
hf download BinxNet/fermi-4fgl-rf-classifier --local-dir ./fermi-4fgl-rf-classifier
- Downloads last month
- -
Evaluation results
- 5-Fold OOF Macro OvR ROC-AUC (3-Class MW 21-feat) on NASA Fermi-LAT 4FGL-DR4 + Multi-Wavelength Surveysself-reported0.937
- 5-Fold OOF Pulsar OvR ROC-AUC (3-Class MW 21-feat) on NASA Fermi-LAT 4FGL-DR4 + Multi-Wavelength Surveysself-reported0.979
- 5-Fold OOF ROC-AUC (Leak-Free Binary MW 21-feat) on NASA Fermi-LAT 4FGL-DR4 + Multi-Wavelength Surveysself-reported0.988