Ejemplo n.º 1
0
    def seasonal_features(cls, freq: str) -> List[TimeFeature]:
        offset = to_offset(freq)
        if offset.name == "M":
            return [MonthOfYear(normalized=False)]
        elif offset.name == "W-SUN":
            return [WeekOfYear(normalized=False)]
        elif offset.name == "D":
            return [DayOfWeek(normalized=False)]
        elif offset.name == "B":  # TODO: check this case
            return [DayOfWeek(normalized=False)]
        elif offset.name == "H":
            return [HourOfDay(normalized=False), DayOfWeek(normalized=False)]
        elif offset.name == "T":
            return [
                MinuteOfHour(normalized=False),
                HourOfDay(normalized=False),
            ]
        else:
            RuntimeError(f"Unsupported frequency {offset.name}")

        return []
Ejemplo n.º 2
0
    DayOfYearIndex,
    WeekOfYearIndex,
    MonthOfYearIndex,
)


@pytest.mark.parametrize(
    "feature, index",
    [
        (
            MinuteOfHour(),
            pd.date_range(
                "01-01-2015 00:00:00", periods=60 * 2 * 24, freq="1min"),
        ),
        (
            HourOfDay(),
            pd.date_range("01-01-2015 00:00:00", periods=14 * 24, freq="1h"),
        ),
        (DayOfWeek(), pd.date_range("01-01-2015", periods=365 * 5, freq="D")),
        (DayOfMonth(), pd.date_range("01-01-2015", periods=365 * 5, freq="D")),
        (DayOfYear(), pd.date_range("01-01-2015", periods=365 * 5, freq="D")),
        (WeekOfYear(), pd.date_range("01-01-2015", periods=53 * 5, freq="W")),
        (MonthOfYear(), pd.date_range("01-01-2015", periods=12 * 5, freq="M")),
        (Constant(), pd.date_range("01-01-2015", periods=5, freq="A")),
    ],
)
def test_feature_normalized_bounds(feature: TimeFeature,
                                   index: pd.DatetimeIndex):
    values = feature(index)
    assert isinstance(values, np.ndarray)
    for v in values:
Ejemplo n.º 3
0
    TabularEstimator, )
from gluonts.model.predictor import Predictor
from gluonts.time_feature import TimeFeature, HourOfDay, DayOfWeek, MonthOfYear


@pytest.mark.parametrize(
    "series, time_features, lag_indices, past_data, expected_df",
    [
        (
            pd.Series(
                list(range(5)),
                index=pd.period_range(
                    "2020-12-31 22:00:00", freq="H", periods=5),
            ),
            [MonthOfYear(), DayOfWeek(),
             HourOfDay()],
            [1, 2, 5],
            None,
            pd.DataFrame(
                {
                    "MonthOfYear": [0.5, 0.5, -0.5, -0.5, -0.5],
                    "DayOfWeek": [
                        0.0,
                        0.0,
                        4.0 / 6 - 0.5,
                        4.0 / 6 - 0.5,
                        4.0 / 6 - 0.5,
                    ],
                    "HourOfDay": [
                        22.0 / 23 - 0.5,
                        0.5,
)
from gluonts.model.predictor import Predictor
from gluonts.time_feature import TimeFeature, HourOfDay, DayOfWeek, MonthOfYear


@pytest.mark.parametrize(
    "series, time_features, lag_indices, past_data, expected_df",
    [
        (
            pd.Series(
                list(range(5)),
                index=pd.date_range(
                    "2020-12-31 22:00:00", freq="H", periods=5
                ),
            ),
            [MonthOfYear(), DayOfWeek(), HourOfDay()],
            [1, 2, 5],
            None,
            pd.DataFrame(
                {
                    "MonthOfYear": [0.5, 0.5, -0.5, -0.5, -0.5],
                    "DayOfWeek": [
                        0.0,
                        0.0,
                        4.0 / 6 - 0.5,
                        4.0 / 6 - 0.5,
                        4.0 / 6 - 0.5,
                    ],
                    "HourOfDay": [
                        22.0 / 23 - 0.5,
                        0.5,