## ----eval=FALSE---------------------------------------------------------------
#  # In R (or add to .Renviron)
#  Sys.setenv(CHRONOS_API_URL = "https://xyz.inference.ml.azure.com/score")
#  Sys.setenv(CHRONOS_API_TOKEN = "your api key here")

## ----eval=FALSE---------------------------------------------------------------
#  library(finnts)
#  
#  # setup chronos2 api keys
#  
#  hist_data <- timetk::m4_monthly %>%
#    dplyr::filter(
#      date >= "2010-01-01",
#      id == "M2"
#    ) %>%
#    dplyr::rename(Date = date) %>%
#    dplyr::mutate(id = as.character(id))
#  
#  run_info <- set_run_info(
#    project_name = "finnts_fcst",
#    run_name = "finn_sub_component_run"
#  )
#  
#  prep_data(
#    run_info = run_info,
#    input_data = hist_data,
#    combo_variables = c("id"),
#    target_variable = "value",
#    date_type = "month",
#    forecast_horizon = 6
#  )
#  
#  prep_models(
#    run_info = run_info,
#    models_to_run = c("chronos2"),
#  )
#  
#  train_models(
#    run_info = run_info,
#    run_global_models = FALSE
#  )
#  
#  final_models(run_info = run_info)
#  
#  finn_output_tbl <- get_forecast_data(run_info = run_info)
#  head(finn_output_tbl)
#  
#  # A tibble: 6 × 17
#  #   Combo id    Model_ID            Model_Name Model_Type Recipe_ID Run_Type        Train_Test_ID Best_Model Horizon Date       Target Forecast lo_95 lo_80 hi_80 hi_95
#  #   <chr> <chr> <chr>               <chr>      <chr>      <chr>     <chr>                   <dbl> <chr>        <dbl> <date>      <dbl>    <dbl> <dbl> <dbl> <dbl> <dbl>
#  # 1 M2    M2    chronos2--local--R1 chronos2   local      R1        Future_Forecast             1 Yes              1 2015-07-01     NA    2342. 1573. 1840. 2844. 3111.
#  # 2 M2    M2    chronos2--local--R1 chronos2   local      R1        Future_Forecast             1 Yes              2 2015-08-01     NA    2128. 1359. 1626. 2630. 2897.
#  # 3 M2    M2    chronos2--local--R1 chronos2   local      R1        Future_Forecast             1 Yes              3 2015-09-01     NA    1849. 1080. 1347. 2351. 2618.
#  # 4 M2    M2    chronos2--local--R1 chronos2   local      R1        Future_Forecast             1 Yes              4 2015-10-01     NA    1890. 1121. 1388. 2393. 2659.
#  # 5 M2    M2    chronos2--local--R1 chronos2   local      R1        Future_Forecast             1 Yes              5 2015-11-01     NA    1868. 1098. 1365. 2370. 2637.
#  # 6 M2    M2    chronos2--local--R1 chronos2   local      R1        Future_Forecast             1 Yes              6 2015-12-01     NA    1731.  961. 1228. 2233. 2500.

## ----eval=FALSE---------------------------------------------------------------
#  # Run Chronos2 as a global model
#  train_models(
#    run_info = run_info,
#    run_global_models = TRUE # Chronos2 will train on all combos together
#  )
#  
#  prep_models(
#    run_info = run_info,
#    models_to_run = c("chronos2"),
#  )

## ----eval=FALSE---------------------------------------------------------------
#  Sys.setenv(CHRONOS_API_URL = "https://xyz.inference.ml.azure.com/score")
#  Sys.setenv(CHRONOS_API_TOKEN = "your api key here")

## ----eval=FALSE---------------------------------------------------------------
#  library(finnts)
#  
#  hist_data <- timetk::m4_monthly %>%
#    dplyr::filter(
#      date >= "2010-01-01",
#      id == "M2"
#    ) %>%
#    dplyr::rename(Date = date) %>%
#    dplyr::mutate(id = as.character(id))
#  
#  run_info <- set_run_info(
#    project_name = "finnts_fcst",
#    run_name = "chronos_bolt_base_run"
#  )
#  
#  prep_data(
#    run_info = run_info,
#    input_data = hist_data,
#    combo_variables = c("id"),
#    target_variable = "value",
#    date_type = "month",
#    forecast_horizon = 6
#  )
#  
#  prep_models(
#    run_info = run_info,
#    models_to_run = c("chronos-bolt-base"),
#  )
#  
#  train_models(
#    run_info = run_info,
#    run_global_models = FALSE
#  )
#  
#  final_models(run_info = run_info)
#  
#  finn_output_tbl <- get_forecast_data(run_info = run_info)
#  head(finn_output_tbl)
#  # A tibble: 6 × 17
#  #  Combo id    Model_ID  Model_Name Model_Type Recipe_ID Run_Type Train_Test_ID Best_Model Horizon Date       Target Forecast lo_95
#  #   <chr> <chr> <chr>     <chr>      <chr>      <chr>     <chr>            <dbl> <chr>        <dbl> <date>      <dbl>    <dbl> <dbl>
#  # 1 M2    M2    chronos-… chronos-b… local      R1        Future_…             1 Yes              1 2015-07-01     NA     2192 1401.
#  # 2 M2    M2    chronos-… chronos-b… local      R1        Future_…             1 Yes              2 2015-08-01     NA     2080 1289.
#  # 3 M2    M2    chronos-… chronos-b… local      R1        Future_…             1 Yes              3 2015-09-01     NA     2000 1209.
#  # 4 M2    M2    chronos-… chronos-b… local      R1        Future_…             1 Yes              4 2015-10-01     NA     2048 1257.
#  # 5 M2    M2    chronos-… chronos-b… local      R1        Future_…             1 Yes              5 2015-11-01     NA     1976 1185.
#  # 6 M2    M2    chronos-… chronos-b… local      R1        Future_…             1 Yes              6 2015-12-01     NA     1864 1073.
#  # # ℹ 3 more variables: lo_80 <dbl>, hi_80 <dbl>, hi_95 <dbl>

## ----eval=FALSE---------------------------------------------------------------
#  Sys.setenv(CHRONOS_API_URL = "https://xyz.inference.ml.azure.com/score")
#  Sys.setenv(CHRONOS_API_TOKEN = "your api key here")

## ----eval=FALSE---------------------------------------------------------------
#  library(finnts)
#  
#  hist_data <- timetk::m4_monthly %>%
#    dplyr::filter(
#      date >= "2010-01-01",
#      id == "M2"
#    ) %>%
#    dplyr::rename(Date = date) %>%
#    dplyr::mutate(id = as.character(id))
#  
#  run_info <- set_run_info(
#    project_name = "finnts_fcst",
#    run_name = "chronos_bolt_tiny_run"
#  )
#  
#  prep_data(
#    run_info = run_info,
#    input_data = hist_data,
#    combo_variables = c("id"),
#    target_variable = "value",
#    date_type = "month",
#    forecast_horizon = 6
#  )
#  
#  prep_models(
#    run_info = run_info,
#    models_to_run = c("chronos-bolt-tiny"),
#  )
#  
#  train_models(
#    run_info = run_info,
#    run_global_models = FALSE
#  )
#  
#  final_models(run_info = run_info)
#  
#  finn_output_tbl <- get_forecast_data(run_info = run_info)
#  head(finn_output_tbl)
#  # A tibble: 6 × 17
#  #   Combo id    Model_ID  Model_Name Model_Type Recipe_ID Run_Type Train_Test_ID Best_Model Horizon Date       Target Forecast lo_95
#  #   <chr> <chr> <chr>     <chr>      <chr>      <chr>     <chr>            <dbl> <chr>        <dbl> <date>      <dbl>    <dbl> <dbl>
#  # 1 M2    M2    chronos-… chronos-b… local      R1        Future_…             1 Yes              1 2015-07-01     NA     2192 1411.
#  # 2 M2    M2    chronos-… chronos-b… local      R1        Future_…             1 Yes              2 2015-08-01     NA     2096 1315.
#  # 3 M2    M2    chronos-… chronos-b… local      R1        Future_…             1 Yes              3 2015-09-01     NA     2064 1283.
#  # 4 M2    M2    chronos-… chronos-b… local      R1        Future_…             1 Yes              4 2015-10-01     NA     2080 1299.
#  # 5 M2    M2    chronos-… chronos-b… local      R1        Future_…             1 Yes              5 2015-11-01     NA     2024 1243.
#  # 6 M2    M2    chronos-… chronos-b… local      R1        Future_…             1 Yes              6 2015-12-01     NA     1936 1155.
#  # # ℹ 3 more variables: lo_80 <dbl>, hi_80 <dbl>, hi_95 <dbl>

## ----eval=FALSE---------------------------------------------------------------
#  Sys.setenv(TIMESFM_API_URL = "https://your-timesfm-endpoint.inference.ml.azure.com/score")
#  Sys.setenv(TIMESFM_API_TOKEN = "your api key here")

## ----eval=FALSE---------------------------------------------------------------
#  library(finnts)
#  
#  hist_data <- timetk::m4_monthly %>%
#    dplyr::filter(
#      date >= "2010-01-01",
#      id == "M2"
#    ) %>%
#    dplyr::rename(Date = date) %>%
#    dplyr::mutate(id = as.character(id))
#  
#  run_info <- set_run_info(
#    project_name = "finnts_fcst",
#    run_name = "timesfm_run"
#  )
#  
#  prep_data(
#    run_info = run_info,
#    input_data = hist_data,
#    combo_variables = c("id"),
#    target_variable = "value",
#    date_type = "month",
#    forecast_horizon = 6
#  )
#  
#  prep_models(
#    run_info = run_info,
#    models_to_run = c("timesfm"),
#  )
#  
#  train_models(
#    run_info = run_info,
#    run_global_models = FALSE
#  )
#  
#  final_models(run_info = run_info)
#  
#  finn_output_tbl <- get_forecast_data(run_info = run_info)
#  head(finn_output_tbl)
#  # A tibble: 6 × 17
#  #   Combo id    Model_ID  Model_Name Model_Type Recipe_ID Run_Type Train_Test_ID Best_Model Horizon Date       Target Forecast lo_95
#  #   <chr> <chr> <chr>     <chr>      <chr>      <chr>     <chr>            <dbl> <chr>        <dbl> <date>      <dbl>    <dbl> <dbl>
#  # 1 M2    M2    timesfm-… timesfm    local      R1        Future_…             1 Yes              1 2015-07-01     NA    2394. 1730.
#  # 2 M2    M2    timesfm-… timesfm    local      R1        Future_…             1 Yes              2 2015-08-01     NA    2082. 1418.
#  # 3 M2    M2    timesfm-… timesfm    local      R1        Future_…             1 Yes              3 2015-09-01     NA    1977. 1313.
#  # 4 M2    M2    timesfm-… timesfm    local      R1        Future_…             1 Yes              4 2015-10-01     NA    2025. 1360.
#  # 5 M2    M2    timesfm-… timesfm    local      R1        Future_…             1 Yes              5 2015-11-01     NA    1841. 1177.
#  # 6 M2    M2    timesfm-… timesfm    local      R1        Future_…             1 Yes              6 2015-12-01     NA    1672. 1008.

## ----eval=FALSE---------------------------------------------------------------
#  # In R (or add to .Renviron)
#  Sys.setenv(NIXTLA_BASE_URL = "https://your-azure-deployed-timegen.azure.com/")
#  Sys.setenv(NIXTLA_API_KEY = "your_api_key_here")
#  # Note that the current version of nixtlar requires base url to end with "/"

## ----eval=FALSE---------------------------------------------------------------
#  # install.packages("nixtlar")
#  library(nixtlar)
#  nixtla_client_setup(
#    base_url = "Base URL here",
#    api_key = "API key here"
#  )

## ----eval=FALSE---------------------------------------------------------------
#  Sys.setenv(NIXTLA_API_KEY = "your_api_key_here")

## ----eval=FALSE---------------------------------------------------------------
#  # install.packages("nixtlar")
#  library(nixtlar)
#  nixtla_set_api_key(api_key = "Your API key here")

## ----eval=FALSE---------------------------------------------------------------
#  # install.packages("nixtlar")
#  library(nixtlar)
#  
#  df <- nixtlar::electricity
#  
#  # Forecast next 8 steps
#  fcst <- nixtla_client_forecast(
#    df,
#    h = 8,
#    level = c(80, 95),
#    # if using azure deployed timegen
#    # model = "azureai"
#  )
#  
#  head(fcst)

## ----eval=FALSE---------------------------------------------------------------
#  library(finnts)
#  
#  # setup timegpt api keys
#  
#  # Checkout these data requirements provided by nixtla
#  # https://www.nixtla.io/docs/data_requirements/data_requirements
#  hist_data <- timetk::m4_monthly %>%
#    dplyr::filter(
#      date >= "2010-01-01",
#      id == "M2"
#    ) %>%
#    dplyr::rename(Date = date) %>%
#    dplyr::mutate(id = as.character(id))
#  
#  run_info <- set_run_info(
#    project_name = "finnts_fcst",
#    run_name = "finn_sub_component_run"
#  )
#  
#  prep_data(
#    run_info = run_info,
#    input_data = hist_data,
#    combo_variables = c("id"),
#    target_variable = "value",
#    date_type = "month",
#    forecast_horizon = 6
#  )
#  
#  prep_models(
#    run_info = run_info,
#    models_to_run = c("timegpt"),
#  )
#  
#  train_models(
#    run_info = run_info,
#    run_global_models = FALSE
#  )
#  
#  final_models(run_info = run_info)
#  
#  finn_output_tbl <- get_forecast_data(run_info = run_info)
#  head(finn_output_tbl)
#  
#  # A tibble: 6 x 17
#  #  Combo id    Model_ID      Model_Name Model_Type Recipe_ID Run_Type Train_Test_ID Best_Model Horizon
#  #  <chr> <chr> <chr>         <chr>      <chr>      <chr>     <chr>            <dbl> <chr>        <dbl>
#  # 1 M2    M2    timegpt--loc~ timegpt    local      R1        Future_~             1 Yes              1
#  # 2 M2    M2    timegpt--loc~ timegpt    local      R1        Future_~             1 Yes              2
#  # 3 M2    M2    timegpt--loc~ timegpt    local      R1        Future_~             1 Yes              3
#  # 4 M2    M2    timegpt--loc~ timegpt    local      R1        Future_~             1 Yes              4
#  # 5 M2    M2    timegpt--loc~ timegpt    local      R1        Future_~             1 Yes              5
#  # 6 M2    M2    timegpt--loc~ timegpt    local      R1        Future_~             1 Yes              6
#  # i 7 more variables: Date <date>, Target <dbl>, Forecast <dbl>, lo_95 <dbl>, lo_80 <dbl>,
#  #   hi_80 <dbl>, hi_95 <dbl>

## ----eval=FALSE---------------------------------------------------------------
#  prep_models(
#    run_info = run_info,
#    models_to_run = c("timegpt"),
#    num_hyperparameters = 4 # Will tune finetune_steps and finetune_depth
#  )

## ----eval=FALSE---------------------------------------------------------------
#  # Run TimeGPT as a global model
#  train_models(
#    run_info = run_info,
#    run_global_models = TRUE # TimeGPT will train on all combos together
#  )
#  
#  prep_models(
#    run_info = run_info,
#    models_to_run = c("timegpt"),
#  )

