【问题标题】:How can I calculate standardized residuals in python?如何计算python中的标准化残差?
【发布时间】:2020-02-28 03:51:30
【问题描述】:

如何从 arima 模型 sarimax 函数计算标准化残差?

假设我们有一些基本模型:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style='ticks', context='poster')
from statsmodels.tsa.statespace.sarimax import SARIMAX
from statsmodels.tsa.seasonal import seasonal_decompose
import seaborn as sns
#plt.style.use("ggplot")
import pandas_datareader.data as web
import pandas as pd
import statsmodels.api as sm
import scipy
import statsmodels.stats.api as sms
import matplotlib.pyplot as plt
import datetime

model = SARIMAX(df, order = (6, 0, 0), trend = "c");
model_results = model.fit(maxiter = 500);
print(model_results.summary());

我需要标准化器,所以当我们使用 model_results.plot_diagnostics(figsize = (16, 10)); 函数和基本的 plot 函数残差应该看起来一样。

【问题讨论】:

    标签: python arima


    【解决方案1】:

    我认为你可以使用https://stackoverflow.com/a/57155553/14294235中的“internally_studentized_residual”函数

    它应该像这样工作:

    model = SARIMAX(df, order = (6, 0, 0), trend = "c");
    
    model_results = model.fit(maxiter = 500);
    
    model_fittebd_y = model_results.fittedvalues
    
    resid_studentized = internally_studentized_residual(df,model_fitted_y)
    resid_studentized = -resid_studentized 
    
    plt.plot(resid_studentized)
    plt.axhline(y=0, color='b', linestyle='--')
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 2018-01-11
      • 2022-01-23
      • 2021-03-17
      • 2014-09-07
      • 2021-02-23
      • 2019-06-01
      • 2016-01-09
      • 1970-01-01
      • 2014-12-04
      相关资源
      最近更新 更多