def test_random_skater(show=False):
     k = 3
     n = 100
     f = random.choice(MERLION_SKATERS)
     print(f.__name__)
     y = hospital(n=n)
     neg_y = [-yt for yt in y]
     e = [-1] * 90 + [100] + [-1] * 90
     x, x_std = prior(f=f, y=neg_y, k=k, e=e)
 def test_univariate_without_time(show=False):
     k = 3
     n = 100
     y = hospital(n=n)
     x, x_std, forecast, m = nprophet_iskater_factory(y=y, k=k)
     assert len(x) == k
     x1, x_std1, forecast1, m1 = nprophet_fit_and_predict_simple(y=y, k=k)
     if show:
         m.plot(forecast)
         m1.plot(forecast1)
         import matplotlib.pyplot as plt
         plt.show()
def test_univariate_with_time_and_advance_time(show=False):
    k = 3
    n = 100
    y = hospital(n=n)
    t = [i * 15 * 50 for i in range(len(y) + k)]
    x, x_std, forecast, m = prophet_iskater_factory(y=y, k=k, t=t)
    assert len(x) == k
    x1, x_std1, forecast1, m1 = prophet_fit_and_predict_with_time_and_advance_time(
        y=y, k=k, t=t)
    assert nearlysame(x1, x, 0.0001)
    if show:
        m.plot(forecast)
        m1.plot(forecast1)
        import matplotlib.pyplot as plt
        plt.show()
示例#4
0
def hospital_mean_square_error(f, k:int=1, n=120, n_burn=30, r=None)->float:
    """ Useful for a quick test of a skater, univariate and random hyper-param """
    y = hospital()[:n]
    return evaluate_mean_squared_error(f=f, y=y, k=k, r=r, n_burn=n_burn)
            model = NeuralProphet(**used_params)
            model.set_log_level(log_level='CRITICAL')
            df = pd.DataFrame(columns=['y'], data=y)
            df['ds'] = pd.date_range(start='2021-01-01',
                                     periods=len(y),
                                     freq=freq)
            metrics = model.fit(df, freq=freq, epochs=40, use_tqdm=False)
            future = model.make_future_dataframe(df)
            forecast = model.predict(future)
            x = [
                forecast['yhat' + str(j + 1)].values[-k + j] for j in range(k)
            ]
            x_std = [1.0] * k
            return x, x_std, forecast, model


if __name__ == '__main__':
    from timemachines.skatertools.data.real import hospital

    k = 3
    n = 500
    y = hospital(n=n)[-200:]
    x, x_std, forecast, m = nprophet_iskater_factory(y=y, k=k)
    print(x)
    assert len(x) == k
    x1, x_std1, forecast1, m1 = nprophet_fit_and_predict_simple(y=y, k=k)
    if True:
        m.plot(forecast)
        m1.plot(forecast1)
        import matplotlib.pyplot as plt
        plt.show()
                    model_params=model_params)
                s['m'] = True  # Flag indicating a model has been fit (there is no point keeping the model itself, however)
            else:
                x = [y[0]] * k
                x_std = None

            # Get running mean prediction errors from the prediction parade
            x_resid, x_resid_std, s['p'] = parade(p=s['p'], x=x, y=y[0])
            x_resid = nonecast(x_resid, y[0])
            x_resid_std = nonecast(x_resid_std, 1.0)

            # Compute center of mass between bias-corrected and uncorrected predictions

            x_corrected = np.array(x_resid) + np.array(x)
            x_center = nonecenter(m=[emp_mass, 1 - emp_mass],
                                  x=[x_corrected, x])
            x_std_center = nonecenter(m=[emp_std_mass, 1 - emp_std_mass],
                                      x=[x_resid_std, x_std])

            return x_center, x_std_center, s


if __name__ == '__main__':
    from timemachines.skatertools.data.real import hospital
    from timemachines.skatertools.evaluation.evaluators import evaluate_mean_absolute_error

    k = 5
    y = hospital(n=420)
    f = nprophet_skater_factory
    err2 = evaluate_mean_absolute_error(f=f, k=k, y=y, n_burn=400)
    print(err2)