Isole les features locales des labels et lance un protocole temporel propre
This commit is contained in:
22
clean_targets.py
Normal file
22
clean_targets.py
Normal file
@@ -0,0 +1,22 @@
|
||||
"""Labels futurs isolés : ce module n'est jamais importé par clean_features."""
|
||||
|
||||
from datetime import date, timedelta
|
||||
from statistics import median
|
||||
|
||||
|
||||
def target(states, prediction_time, horizon):
|
||||
# Le dernier état disponible à t est celui de la veille (hypothèse J+1).
|
||||
start = date.fromisoformat(prediction_time) - timedelta(days=1)
|
||||
end = start + timedelta(days=horizon)
|
||||
a, b = states.get(start.isoformat()), states.get(end.isoformat())
|
||||
if not a or not b:
|
||||
return None
|
||||
shared = a["prices"].keys() & b["prices"].keys()
|
||||
if len(shared) < 3:
|
||||
return None
|
||||
return dict(
|
||||
delta_cents=median((b["prices"][s] - a["prices"][s]) * 100 for s in shared),
|
||||
available_at=b["available_at"],
|
||||
stations=len(shared),
|
||||
horizon=horizon,
|
||||
)
|
||||
Reference in New Issue
Block a user