Search code examples
pythonpandastime-seriesazure-timeseries-insights

ACF Time series: ValueError: operands could not be broadcast together with shapes


I have a time series object which has 2 columns index and item_count. I am trying to find its ACF and I get an error.

[IN]ts.head()
[OUT]   item_cnt_day
index   
2013-01-01  131479.0
2013-02-01  128090.0
2013-03-01  147142.0
2013-04-01  107190.0
2013-05-01  106970.0

There are 34 rows in the table say.

ts.shape
(34, 1)

import statsmodels.graphics.tsaplots as sgt 

sgt.plot_acf(ts.item_cnt_day, lags = 40, zero=False) #ACF means auto correlation function
#Lags 40 means that we are calculating correlation between a present series and series 40 time periods before.
#zero = false means that you dont calculate correltion between series now and now, because that will alwasy be onebb
plt.title("ACF S&P")
plt.show()


ValueError: operands could not be broadcast together with shapes (39,) (32,) (39,) 

Solution

  • Since the data of my series is 34 rows. Your lag cannot be more than 34.

    sgt.plot_acf(ts.item_cnt_day, lags = 33, zero=False) #ACF means auto correlation function
    

    lags=33 or any value of lags below 34 will not result in an error