Как устранить ошибку атрибута «Объект Int64Index не имеет атрибута« inferred_freq »» - PullRequest
0 голосов
/ 18 апреля 2019

Я пытаюсь построить модель сезонной декомпозиции, чтобы изобразить тренды временного ряда и сезонность, используя код, который дает мне ошибку, которая говорит:

AttributeError: у объекта 'Int64Index' нетатрибут 'inferred_freq "

from plotly.plotly import plot_mpl
from statsmodels.tsa.seasonal import seasonal_decompose
result = seasonal_decompose(series, model='multiplicative')
fig = result.plot()
plot_mpl(fig)

Я слежу за моделью в по этой ссылке

Мой фрейм данных выглядит примерно так:

    date          Name    Count
1   2018-09-04    MALX     198
2   2018-09-06    MALX     200
3   2018-09-11    MALX     203
4   2018-09-16    MALX     215
5   2018-09-17    MALX     401

Я использую следующие пакеты:

import pandas as pd
import numpy as np
from pandas import Series
from matplotlib import pyplot
import matplotlib.pyplot as plt
series = pd.read_csv('Malx_data.csv', low_memory=False, usecols= ['date', 'Name', 'Count'])
series = series.loc[series['Name'] == 'MALX'].sort_values(by = 'day', ascending = True)
series['date'] = pd.to_datetime(series['date'])
series

Сообщение об ошибке трассировки выглядит следующим образом:

AttributeError                            Traceback (most recent call last)
<ipython-input-43-4e5d5e1e2756> in <module>()
      1 from plotly.plotly import plot_mpl
      2 from statsmodels.tsa.seasonal import seasonal_decompose
----> 3 result = seasonal_decompose(series, model='multiplicative')
      4 fig = result.plot()
      5 plot_mpl(fig)

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\statsmodels\tsa\seasonal.py in seasonal_decompose(x, model, filt, freq, two_sided, extrapolate_trend)
    106     """
    107     if freq is None:
--> 108         _pandas_wrapper, pfreq = _maybe_get_pandas_wrapper_freq(x)
    109     else:
    110         _pandas_wrapper = _maybe_get_pandas_wrapper(x)

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\statsmodels\tsa\filters\_utils.py in _maybe_get_pandas_wrapper_freq(X, trim)
     43         index = X.index
     44         func = _get_pandas_wrapper(X, trim)
---> 45         freq = index.inferred_freq
     46         return func, freq
     47     else:

AttributeError: 'Int64Index' object has no attribute 'inferred_freq'

1 Ответ

0 голосов
/ 11 июля 2019

Похоже, что сериал, который вы разлагаете, не имеет индекса временных рядов.Вы можете просто добавить его:

series.index = series.date
...