diff --git a/README.md b/README.md index 72ca71e..225b9e9 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,13 @@ with eval_data as ( select * from {{ dbt_ml.detect_anomalies(ref('model'), 'eval_data', threshold) }} ``` +If using a forecasting model, you can use the forecast macro in the same way. Here we are forecasting 30 units ahead with 80% confidence. +```sql +# forecast_model.sql + +select * from {{ dbt_ml.forecast(ref('model'), 30, 0.8) }} +``` + ### Tuning hyperparameters BigQuery ML supports tuning model hyperparameters[2], as does `dbt_ml`. In order to specify which hyperparameters to tune, and which parameterspace to use, one can use the `dbt_ml.hparam_candidates` and `dbt_ml.hparam_range` macros that map to the corresponding BigQuery ML methods. diff --git a/macros/forecast.sql b/macros/forecast.sql new file mode 100644 index 0000000..9a03598 --- /dev/null +++ b/macros/forecast.sql @@ -0,0 +1,10 @@ +{% macro forecast(relation, horizon = 30, confidence_level = 0.8) %} + ml.forecast( + model {{ relation }}, + struct( + {{ horizon }} AS horizon, + {{ confidence_level }} AS confidence_level + ) + ) +{% endmacro %} +