-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
bugSomething isn't workingSomething isn't workingmodule:forecastingforecasting module: forecasting, incl probabilistic and hierarchical forecastingforecasting module: forecasting, incl probabilistic and hierarchical forecasting
Description
Describe the bug
The naive model with "last" strategy really picks the last value, even if that's a NaN value. Can we make this more robust, similar to how the "mean" strategy actually does a nanmean under the hood? I could offer a PR to make it pick the last non-NaN value, taking into account the requested seasonal periodicity.
To Reproduce
import numpy as np
import pandas as pd
from sktime.forecasting.base import ForecastingHorizon
from sktime.forecasting.naive import NaiveForecaster
data = pd.Series(
index=pd.date_range(
"2021-06-01 00:00", periods=12, freq="1h", closed="left"
),
data=[1, 2, 3, 1, 2, 3, np.nan, 2, 3, 1, 2, 3]
)
train_data = data[:7]
test_data = data[7:]
print(train_data)
# 2021-06-01 00:00:00 1.0
# 2021-06-01 01:00:00 2.0
# 2021-06-01 02:00:00 3.0
# 2021-06-01 03:00:00 1.0
# 2021-06-01 04:00:00 2.0
# 2021-06-01 05:00:00 3.0
# 2021-06-01 06:00:00 NaN
# Freq: H, dtype: float64
fh = ForecastingHorizon(test_data.index, is_relative=False)
model = NaiveForecaster(strategy="last", sp=3)
model.fit(train_data)
forecast_data = model.predict(fh)
print(forecast_data)
# 2021-06-01 07:00:00 2.0
# 2021-06-01 08:00:00 3.0
# 2021-06-01 09:00:00 NaN # Let's make this a 1
# 2021-06-01 10:00:00 2.0
# 2021-06-01 11:00:00 3.0
# dtype: float64Expected behavior
Additional context
Versions
Details
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingmodule:forecastingforecasting module: forecasting, incl probabilistic and hierarchical forecastingforecasting module: forecasting, incl probabilistic and hierarchical forecasting