Skip to content

Commit

Permalink
Merge pull request #111 from T-Dunlap/fix_forecast_daily_returns
Browse files Browse the repository at this point in the history
fixing python model
  • Loading branch information
T-Dunlap authored Jan 17, 2024
2 parents 2c6e88d + cbbbc70 commit 428b35f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions models/demo_examples/python/forecast_daily_returns.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import pandas as pd
from prophet import Prophet

import pandas as pd # import packages
from prophet import Prophet

def model( dbt, session ):

dbt.config(
materialized="table",
packages=['pandas','Prophet','holidays==0.18'] # how to import python libraries in dbt's context
materialized="table", # the incremental materialization is also supported
packages=['pandas==1.5.3','Prophet','holidays==0.18'] # how to import python libraries in dbt's context
)

# use historical data to fit model
df = dbt.ref("agg_daily_returned_orders").to_pandas()
df = dbt.ref("agg_daily_returned_orders").to_pandas() # use dbt.ref to reference other models in your dbt project
df.columns = df.columns.str.lower()
m = Prophet()
m.fit(df)
Expand All @@ -18,4 +21,8 @@ def model( dbt, session ):
future = m.make_future_dataframe(periods=365)
df = m.predict(future)

return df
return df # return final dataset via data frame. This is required.

# The Preview button in the IDE is disabled, but you can iterate by building the object and then opening a new tab and running... select * from ref('forecast_daily_returns')
# Tests and Documentation can also be applied to python models, in the same manner as sql models (.yml file or custom tests).

0 comments on commit 428b35f

Please sign in to comment.