1

残差图在我的图中未正确显示。我无法理解问题可能是什么。请在此处输入图像描述需要帮助。轴有问题。我正在提取 COVID 19 的数据,并且正在绘制一阶数据(固定集)。我已经删除了所有 nan 值。

数据格式为日期 value_diff 268 2020-10-16 745.0 269 2020-10-17 428.0 270 2020-10-18 465.0

ecomposition = seasonal_decompose(data_set_3, model='additive', period=7)

    trend = decomposition.trend
    seasonal = decomposition.seasonal
    residual = decomposition.resid

    plt.subplot(411)
    plt.plot(data_set_3, label='Original')
    plt.legend(loc='best')

    plt.subplot(412)
    plt.plot(trend, label='Trend')
    plt.legend(loc='best')

    plt.subplot(413)
    plt.plot(seasonal, label='Seasonality')
    plt.legend(loc='best')

    plt.subplot(414)
    plt.plot(residual, label='Residuals')
    plt.legend(loc='best')

    plt.tight_layout()

4

1 回答 1

0

将频率和周期添加到您的seasonal_decomposition 以进行平滑。它会起作用的。

from pandas_datareader import data as pdr
from statsmodels.graphics import tsaplots
import statsmodels.api as sm

current_date=datetime.datetime.now()
start_date=datetime.datetime(current_date.year,1,1)
df = pdr.get_data_yahoo("MSFT",start_date,current_date).reset_index()

decomposition=sm.tsa.seasonal_decompose(x=df['High'],model='additive',         extrapolate_trend='freq', period=30)
decomposition.plot()
plt.show()

decomposition_trend=decomposition.trend
ax= decomposition_trend.plot(figsize=(14,2))
ax.set_xlabel('Date')
ax.set_ylabel('Trend of time series')
ax.set_title('Trend values of the time series')
plt.show()

decomposition_residual=decomposition.resid
ax= decomposition_residual.plot(figsize=(14,2))
ax.set_xlabel('Date')
ax.set_ylabel('Residual of time series')
ax.set_title('Residual values of the time series')
plt.show()

decomposition_trend=decomposition.trend
ax= decomposition_trend.plot(figsize=(14,2))
ax.set_xlabel('Date')
ax.set_ylabel('Trend of time series')
ax.set_title('Trend values of the time series')
plt.show()
于 2021-04-17T21:07:54.750 回答