Ejemplo n.º 1
0
def fallback(mase_all, smape_all, train, test, m):
    naive = NaiveSeasonal(K=m)
    naive.fit(train)
    forecast = naive.predict(len(test))
    mase_all.append(np.vstack([
        mase_m4(train, test, forecast, m=m),
    ]))
    smape_all.append(np.vstack([
        smape_m4(test, forecast),
    ]))
Ejemplo n.º 2
0
    def test_predict_ensemble_local_models(self):
        naive = NaiveSeasonal(K=5)
        theta = Theta()
        naive_ensemble = NaiveEnsembleModel([naive, theta])
        naive_ensemble.fit(self.series1 + self.series2)
        forecast_naive_ensemble = naive_ensemble.predict(5)
        naive.fit(self.series1 + self.series2)
        theta.fit(self.series1 + self.series2)
        forecast_mean = 0.5 * naive.predict(5) + 0.5 * theta.predict(5)

        self.assertTrue(
            np.array_equal(forecast_naive_ensemble.values(),
                           forecast_mean.values()))
Ejemplo n.º 3
0
def naive2_groe(ts: TimeSeries, n: int, m: int):
    """
    Return the prediction of the naive2 baseline
    """
    # It will be better to use R functions
    ts_des = ts
    seasonOut = 1
    if m > 1:
        if check_seasonality(ts, m=int(m), max_lag=2 * m):
            _, season = extract_trend_and_seasonality(ts, m, model=ModelMode.MULTIPLICATIVE)
            ts_des = remove_from_series(ts, season, model=ModelMode.MULTIPLICATIVE)
            seasonOut = season[-m:].shift(m)
            seasonOut = seasonOut.append_values(seasonOut.values())[:n]
    naive2 = NaiveSeasonal(K=1)

    naive2.fit(ts_des)
    return naive2.predict(n) * seasonOut
Ejemplo n.º 4
0
                                        seasonal_periods=m)
            naive.fit(train)
            naive2.fit(train_des)
            naiveSeason.fit(train)
            try:
                ses.fit(train_des)
            except ValueError:
                # not useful anymore
                train_des = train_des.shift(-len(train_des)).append(train_des)
                #                 train_des = TimeSeries.from_times_and_values(train_des.shift(-11).time_index[:11],
                #                                                              2*train_des.values()[0]-train_des.values()[10::-1]) \
                #                                                             .append(train_des)
                ses.fit(train_des)
            holt.fit(train_des)
            damp.fit(train_des)
            forecast_naiveSeason = naiveSeason.predict(len(test))
            forecast_naiveDrift = naive.predict(len(test))
            forecast_naive = forecast_naiveSeason + forecast_naiveDrift - train.last_value(
            )
            forecast_naive2 = naive2.predict(len(test)) * seasonOut
            forecast_ses = ses.predict(len(test)) * seasonOut
            forecast_holt = holt.predict(len(test)) * seasonOut
            forecast_damp = damp.predict(len(test)) * seasonOut
            forecast_comb = ((forecast_ses + forecast_holt + forecast_damp) /
                             3)

            mase_all.append(
                np.vstack([
                    mase_m4(train, test, forecast_naiveSeason, m=m),
                    mase_m4(train, test, forecast_naive, m=m),
                    mase_m4(train, test, forecast_naive2, m=m),