Iterate over the rows in Forecast.from_dataframe()
This commit is contained in:
parent
77806b14b9
commit
804a4a0966
1 changed files with 20 additions and 28 deletions
|
|
@ -222,40 +222,32 @@ class Forecast(meta.Base):
|
||||||
"""
|
"""
|
||||||
forecasts = []
|
forecasts = []
|
||||||
|
|
||||||
for timestamp_idx in data.index:
|
rows = data[["actual", "prediction", "low80", "high80", "low95", "high95"]]
|
||||||
start_at = timestamp_idx.to_pydatetime()
|
|
||||||
actual = int(data.loc[timestamp_idx, "actual"])
|
|
||||||
prediction = float(round(data.loc[timestamp_idx, "prediction"], 5))
|
|
||||||
|
|
||||||
# Explicit type casting. SQLAlchemy does not convert
|
|
||||||
# `float('NaN')`s into plain `None`s.
|
|
||||||
|
|
||||||
low80 = data.loc[timestamp_idx, "low80"]
|
|
||||||
high80 = data.loc[timestamp_idx, "high80"]
|
|
||||||
low95 = data.loc[timestamp_idx, "low95"]
|
|
||||||
high95 = data.loc[timestamp_idx, "high95"]
|
|
||||||
|
|
||||||
low80 = None if math.isnan(low80) else float(round(low80, 5))
|
|
||||||
|
|
||||||
high80 = None if math.isnan(high80) else float(round(high80, 5))
|
|
||||||
|
|
||||||
low95 = None if math.isnan(low95) else float(round(low95, 5))
|
|
||||||
|
|
||||||
high95 = None if math.isnan(high95) else float(round(high95, 5))
|
|
||||||
|
|
||||||
|
for (
|
||||||
|
timestamp_idx,
|
||||||
|
actual,
|
||||||
|
prediction,
|
||||||
|
low80,
|
||||||
|
high80,
|
||||||
|
low95,
|
||||||
|
high95,
|
||||||
|
) in rows.itertuples(name=None):
|
||||||
forecasts.append(
|
forecasts.append(
|
||||||
cls(
|
cls(
|
||||||
pixel=pixel,
|
pixel=pixel,
|
||||||
start_at=start_at,
|
start_at=timestamp_idx.to_pydatetime(),
|
||||||
time_step=time_step,
|
time_step=time_step,
|
||||||
train_horizon=train_horizon,
|
train_horizon=train_horizon,
|
||||||
model=model,
|
model=model,
|
||||||
actual=actual,
|
actual=int(actual),
|
||||||
prediction=prediction,
|
prediction=float(round(prediction, 5)),
|
||||||
low80=low80,
|
# Explicit type casting. SQLAlchemy does not convert
|
||||||
high80=high80,
|
# `float('NaN')`s into plain `None`s.
|
||||||
low95=low95,
|
low80=None if math.isnan(low80) else float(round(low80, 5)),
|
||||||
high95=high95,
|
high80=None if math.isnan(high80) else float(round(high80, 5)),
|
||||||
|
low95=None if math.isnan(low95) else float(round(low95, 5)),
|
||||||
|
high95=None if math.isnan(high95) else float(round(high95, 5)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue