Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I'm trying to use exponential smoothing in Pandas in Power BI and want the forecast always to commence after the maximum date in the actuals dataset, i.e. my last week of actuals data is 6/11/2022, so I want to forecast starting from there.
I'm trying to write some code to extract and feed this maximum date into the dataframe that will hold the finished predictions, but for some reason it's not correctly determining the maximum date. It always gives a value in 1970, which I assume to be the datetime equivalent of a zero value.
# 'dataset' holds the input data for this script
import pandas as pd
import numpy as np
dataset.set_index('Date')
dataset.index.freq='W'
from statsmodels.tsa.holtwinters import ExponentialSmoothing
model = ExponentialSmoothing(dataset['Volume'],trend='mul',seasonal='mul',seasonal_periods=52).fit()
lastweek = dataset.index.max()
range = pd.date_range(lastweek,periods=17,freq='W')
predictions = model.forecast(17)
predictions_range = pd.DataFrame({'Volume':predictions,'Date':range})
Extra info: I've been able to get some different code to work in Jupyter Notebook but for some reason this doesn't work in Power BI:
# 'dataset' holds the input data for this script
import pandas as pd
import numpy as np
dataset.set_index('Date')
dataset.index.freq='W'
from statsmodels.tsa.holtwinters import ExponentialSmoothing
model = ExponentialSmoothing(dataset['Volume'],trend='mul',seasonal='mul',seasonal_periods=52).fit()
lastweek = dataset.index.max()
lastweekdate = lastweek.to_pydatetime().date()
range = pd.date_range(lastweekdate,periods=17,freq='W')
predictions = model.forecast(17)
predictions_range = pd.DataFrame({'Volume':predictions,'Date':range})
Source is a very ordinary csv file which converts into dates and numbers:
Would appreciate anyone's help!
@Anonymous , These two lines have issues
lastweek = dataset.index.max()
lastweekdate = lastweek.to_pydatetime().date()
can you test this code outside on a sample data
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
104 | |
96 | |
80 | |
67 | |
62 |
User | Count |
---|---|
137 | |
106 | |
104 | |
81 | |
63 |