atspy
atspy copied to clipboard
UnboundLocalError: local variable 'periodocity' referenced before assignment
I'm running AtsPy with a date-time index with frequency of A-DEC and receive a "periodicity' error. Could this be due to the "season = infer_from_data" not supporting A-DEC? If so, is there another option to manually specify a season value?
DatetimeIndex(['1997-12-31', '1998-12-31', '1999-12-31', '2000-12-31', '2001-12-31', '2002-12-31', '2003-12-31', '2004-12-31', '2005-12-31', '2006-12-31', '2007-12-31', '2008-12-31', '2009-12-31', '2010-12-31', '2011-12-31', '2012-12-31', '2013-12-31', '2014-12-31', '2015-12-31', '2016-12-31', '2017-12-31'], dtype='datetime64[ns]', freq='A-DEC')
<class 'pandas.core.frame.DataFrame'> The data has been successfully parsed by infering a frequency, and establishing a 'Date' index and 'Target' column. 15 An insample split of training size 15 and testing size 6 has been constructed
UnboundLocalError Traceback (most recent call last)
4 frames /usr/local/lib/python3.6/dist-packages/atspy/init.py in infer_periodocity(train) 145 periodocity = 1000 146 --> 147 return periodocity 148 149 def select_seasonality(train, season):
UnboundLocalError: local variable 'periodocity' referenced before assignment
'root cause - it is not able to infer_freq of the date column for that reason it is not able to satisfy any condition of def time_feature(df,perd): for that reason you are getting above error use that command to see infer_freq pd.infer_freq(df.index)
Solution -
- goto /usr/local/lib/python3.6/dist-packages/atspy/init.py
- change elif perd=="W": to elif perd=="W-SUN": if you are doing weekly prediction.
- restart your runtime or Jupyter notebook.
- re-run entire notebook again and the issue will get fixed.
- Done
@Team can we connect as def time_feature(df,perd): function is not generic.
@rahul4tripathi2 Thanks I always appreciate when someone comes with solutions. Would you be able to submit a pull request when you see changes needed? Best, Derek.
Below are the changes which i think should be done in infer_periodicity function. I'm not sure it is optimal code or not. https://pandas.pydata.org/pandas-docs/version/0.9.1/timeseries.html
def infer_periodocity(train): perd = pd.infer_freq(train.index) if perd in ["MS","M","BM","BMS"]: periodocity = 12 elif perd in ["BH","H"]: periodocity = 24 elif perd=="B": periodocity = 5 elif perd=="D": periodocity = 7 elif perd in ["W-SUN","W-MON","W-TUE","W-WED","W-THU","W-FRI","W-SAT"]: periodocity = 52 elif perd in ["Q","QS","BQ","BQS"]: periodocity = 4 elif perd in ["A","BA","AS","BAS"]: periodocity = 10 elif perd in ["T","min"]: periodocity = 60 elif perd=="S": periodocity = 60 elif perd in ["L","ms"]: periodocity = 1000 elif perd in ["U","us"]: periodocity = 1000 elif perd=="N": periodocity = 1000
return periodocity