Exemple #1
0
def fbprophet_univariate_best_r() -> float:
    """
      :return:  Provides best r for a randomly chosen data stream
                Takes about 12 hrs to run
    """
    mr = MicroReader()
    names = mr.get_stream_names()
    okay = False
    while not okay:
        name = random.choice(names)
        n_obs = len(mr.get_lagged_values(name=name))
        okay = n_obs > PROPHET_META['n_warm'] + 50 and '~' not in name
    url = 'https://www.microprediction.org/stream_dashboard.html?stream=' + name.replace(
        '.json', '')
    print('We will find the best fbprophet hyper-parameters for ' + url)
    print('There are ' + str(n_obs) + ' observations in the series.')
    print(
        "Prophet will be fit for most of them, after a burn_in, and for many different hyper-params. Don't hold your breathe."
    )

    best_r, best_value, info = optimal_r_for_stream(
        f=fbprophet_univariate_r2,
        name=name,
        k=10,
        optimizer=dlib_default_cube,
        n_burn=PROPHET_META['n_warm'] + 20,
        n_trials=50,
        n_dim=2)
    pprint(info)
    params = prophet_params(r=best_r, dim=2)
    pprint(params)
Exemple #2
0
def fbprophet_hyperparam_skater_factory(r: R_TYPE = None, param_names: [str] = None,   **kwargs):
    """ Useful for creating skaters based on hyper-parameters r and the
        method of modifying them suggested by the authors
     """
    assert param_names is not None
    dim = len(param_names)
    assert 2 <= dim <= 3
    model_params = prophet_params(r=r,dim=dim, param_names=param_names)
    return fbprophet_skater_factory(model_params=model_params, **kwargs)
from timemachines.skaters.optimization import optimal_r_for_stream
from timemachines.skaters.proph.prophskaters import fbprophet_univariate_r2
from timemachines.optimizers.optunacube import optuna_tpe_cube
from timemachines.skaters.proph.prophparams import PROPHET_META, prophet_params
from pprint import pprint
from timemachines.data.live import random_regular

# Illustrates how to find the best hyper-parameter r in (0,1), and interpret this as two prophet hyper-parameters
# We use a random stream from https://www.microprediction.org/browse_streams.html
# Your should expect this to take many hours. A time update is provided after the first function evaluation.


if __name__=='__main__':
    name, url = random_regular(min_len=PROPHET_META['n_warm'])
    print('We will find the best fbprophet hyper-parameters for '+url)
    print("Prophet will be fit for most of them, after a burn_in, and for many different hyper-params. Don't hold your breathe.")

    best_r, best_value, info = optimal_r_for_stream(f=fbprophet_univariate_r2,name=name,k=10,optimizer=optuna_tpe_cube,
                                                    n_burn=PROPHET_META['n_warm']+20,n_trials=50,n_dim=2)
    pprint(info)
    params = prophet_params(r=best_r,dim=2)
    pprint(params)