<jupyter_start><jupyter_text>Inputs<jupyter_code>LOADS = 'out/loads.csv'

# (unix) timestamp of time offset
INITIAL_TIME = 1247270400

# time slot length
DELTA = 10 * 60
DELTA_ALIAS = '10T' # see: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#timeseries-offset-aliases

# # adjusts flexibility of trend; increase to make more flexible; default is `0.05`
# CHANGEPOINT_PRIOR_SCALE = 0.05

# # number of samples of the predicted distribution
# NUMBER_OF_SAMPLES = 300

# number of predicted time slots
WINDOW = 100<jupyter_output><empty_output><jupyter_text>Preparation<jupyter_code>l = pd.read_csv(LOADS)
metadata = MetadataParam(
    time_col="ds",
    value_col="y",
    freq=DELTA_ALIAS
)<jupyter_output><empty_output><jupyter_text>Preparing date times<jupyter_code>def prepare_df(load_type: str) -> pd.DataFrame:
  df = l[[load_type]].rename(columns={load_type: 'y'})
  df['ds'] = df.index
  df['ds'] = (INITIAL_TIME + df['ds'] * DELTA).apply(lambda x: datetime.fromtimestamp(x))
  return df<jupyter_output><empty_output><jupyter_text>Making predictions<jupyter_code>def predict(df: pd.DataFrame) -> ForecastResult:
  print(df)
  forecaster = Forecaster()
  return forecaster.run_forecast_config(
      df=df,
      config=ForecastConfig(
          model_template=ModelTemplateEnum.SILVERKITE.name,
          forecast_horizon=WINDOW,
          coverage=0.95,
          metadata_param=metadata
      )
  )<jupyter_output><empty_output><jupyter_text>Execution<jupyter_code>predictions = {}

for load_type in l.columns:
  df = prepare_df(load_type)
  prediction = predict(df)
  predictions[load_type] = prediction
  summary = prediction.model[-1].summary(max_colwidth=30)
  print(summary)
  ts = prediction.timeseries
  ts.plot().show()
  backtest = prediction.backtest
  backtest.plot().show()<jupyter_output><empty_output><jupyter_text>Store predictionsSaves predictions as a JSON dump. For each load type the dump constains a list of predictions for each time slot (past and future). A prediction consists of a list of samples.<jupyter_code>json.dump({k: v.tolist() for k, v in predictions.items()}, codecs.open('out/predictions.json', 'w', encoding='utf-8'), separators=(',', ':'), sort_keys=True, indent=4)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12351124834583149, 'fraction_numerical': 0.015880017644464048, 'mean_word_length': 5.48, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 27, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '644569', 'license': 'MIT', 'n_tokens_mistral': 827, 'n_tokens_neox': 793, 'n_words': 153, 'path': 'analysis/predict_jobs_greykite.ipynb', 'repo_name': 'jonhue/bachelors-thesis', 'size': '2267'}