Improve DEB calibration and training metrics

This commit is contained in:
2569718930@qq.com
2026-06-07 22:51:18 +08:00
parent 12935f502f
commit 41e819735d
9 changed files with 690 additions and 57 deletions
+46
View File
@@ -128,6 +128,52 @@ def test_calculate_deb_prediction_keeps_raw_and_adds_versioned_bias_correction(m
assert result["bias_samples"] == 3
def test_calculate_deb_prediction_prefers_bucket_calibration_when_enough_samples(monkeypatch):
monkeypatch.setattr(
"src.analysis.deb_algorithm.load_history",
lambda _: {
"ankara": {
"2026-04-11": {
"actual_high": 21.0,
"deb_prediction": 20.4,
"forecasts": {"ECMWF": 20.4, "GFS": 20.4},
},
"2026-04-12": {
"actual_high": 22.0,
"deb_prediction": 21.4,
"forecasts": {"ECMWF": 21.4, "GFS": 21.4},
},
"2026-04-13": {
"actual_high": 23.0,
"deb_prediction": 22.4,
"forecasts": {"ECMWF": 22.4, "GFS": 22.4},
},
"2026-04-14": {
"actual_high": 24.0,
"deb_prediction": 23.4,
"forecasts": {"ECMWF": 23.4, "GFS": 23.4},
},
"2026-04-15": {
"actual_high": 25.0,
"deb_prediction": 24.4,
"forecasts": {"ECMWF": 24.4, "GFS": 24.4},
},
}
},
)
result = calculate_deb_prediction(
"ankara",
{"ECMWF": 25.4, "GFS": 25.4},
)
assert result["raw_prediction"] == 25.4
assert result["prediction"] == 26.0
assert result["version"] == "deb_v2_bucket_calibrated"
assert result["bias_adjustment"] == 0.6
assert result["bias_samples"] == 5
def test_compute_hourly_model_errors_basic():
from src.analysis.deb_algorithm import compute_hourly_model_errors