Example #1
0
def test_special_date_feature_set_daily_squared_exponential():
    date_indices = pd.date_range(start="2016-12-24",
                                 end="2016-12-29",
                                 freq="D")
    reference_features = np.array(
        [
            [
                1.00000e00,
                3.67879e-01,
                1.83156e-02,
                1.23410e-04,
                1.12535e-07,
                0.00000e00,
            ],
            [
                3.67879e-01,
                1.00000e00,
                3.67879e-01,
                1.83156e-02,
                1.23410e-04,
                1.12535e-07,
            ],
        ],
        dtype=float,
    )

    squared_exp_kernel = squared_exponential_kernel(alpha=1.0)
    sfs = SpecialDateFeatureSet([CHRISTMAS_EVE, CHRISTMAS_DAY],
                                squared_exp_kernel)
    computed_features = sfs(date_indices)
    np.testing.assert_almost_equal(computed_features,
                                   reference_features,
                                   decimal=6)
Example #2
0
def test_special_date_feature_set_daily():
    date_indices = pd.date_range(start="2016-12-24",
                                 end="2016-12-31",
                                 freq="D")

    reference_features = np.array([
        [1, 0, 0, 0, 0, 0, 0, 0],
        [0, 1, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 1],
    ])
    sfs = SpecialDateFeatureSet([CHRISTMAS_EVE, CHRISTMAS_DAY, NEW_YEARS_EVE])
    computed_features = sfs(date_indices)

    assert (computed_features == reference_features
            ).all(), "Computed features do not match reference features."
Example #3
0
def test_custom_holiday_feature_set():

    custom_holidays = [
        Holiday("New Years Day", month=1, day=1),
        Holiday("Christmas Day", month=12, day=25)
    ]

    kernel = exponential_kernel(alpha=1.0)

    cfs = CustomHolidayFeatureSet(custom_holidays, kernel)
    sfs = SpecialDateFeatureSet([NEW_YEARS_DAY, CHRISTMAS_DAY], kernel)

    date_indices = pd.date_range(start=pd.to_datetime('20191101',
                                                      format='%Y%m%d'),
                                 end=pd.to_datetime('20200131',
                                                    format='%Y%m%d'),
                                 freq='D')

    assert (np.sum(cfs(date_indices) -
                   sfs(date_indices)) == 0), "Features don't match"
Example #4
0
def test_custom_date_feature_set():

    ref_dates = [
        pd.to_datetime('20191129', format='%Y%m%d'),
        pd.to_datetime('20200101', format='%Y%m%d')
    ]

    kernel = exponential_kernel(alpha=1.0)

    cfs = CustomDateFeatureSet(ref_dates, kernel)
    sfs = SpecialDateFeatureSet([BLACK_FRIDAY, NEW_YEARS_DAY], kernel)

    date_indices = pd.date_range(start=pd.to_datetime('20191101',
                                                      format='%Y%m%d'),
                                 end=pd.to_datetime('20200131',
                                                    format='%Y%m%d'),
                                 freq='D')

    assert (np.sum(cfs(date_indices) -
                   sfs(date_indices)) == 0), "Features don't match"
Example #5
0
def test_custom_date_feature_set():

    ref_dates = [
        pd.to_datetime("20191129", format="%Y%m%d"),
        pd.to_datetime("20200101", format="%Y%m%d"),
    ]

    kernel = exponential_kernel(alpha=1.0)

    cfs = CustomDateFeatureSet(ref_dates, kernel)
    sfs = SpecialDateFeatureSet([BLACK_FRIDAY, NEW_YEARS_DAY], kernel)

    date_indices = pd.date_range(
        start=pd.to_datetime("20191101", format="%Y%m%d"),
        end=pd.to_datetime("20200131", format="%Y%m%d"),
        freq="D",
    )

    assert (np.sum(
        cfs(date_indices) -
        sfs(date_indices).sum(0, keepdims=True)) == 0), "Features don't match"