本文整理汇总了Python中statsmodels.tsa.statespace.kalman_filter.KalmanFilter.memory_no_forecast方法的典型用法代码示例。如果您正苦于以下问题:Python KalmanFilter.memory_no_forecast方法的具体用法?Python KalmanFilter.memory_no_forecast怎么用?Python KalmanFilter.memory_no_forecast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类statsmodels.tsa.statespace.kalman_filter.KalmanFilter
的用法示例。
在下文中一共展示了KalmanFilter.memory_no_forecast方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_predict
# 需要导入模块: from statsmodels.tsa.statespace.kalman_filter import KalmanFilter [as 别名]
# 或者: from statsmodels.tsa.statespace.kalman_filter.KalmanFilter import memory_no_forecast [as 别名]
def test_predict():
# Tests of invalid calls to the predict function
warnings.simplefilter("always")
endog = np.ones((10, 1))
mod = KalmanFilter(endog, k_states=1, initialization="approximate_diffuse")
mod["design", :] = 1
mod["obs_intercept"] = np.zeros((1, 10))
mod["selection", :] = 1
mod["state_cov", :] = 1
# Check that we need both forecasts and predicted output for prediction
mod.memory_no_forecast = True
res = mod.filter()
assert_raises(ValueError, res.predict)
mod.memory_no_forecast = False
mod.memory_no_predicted = True
res = mod.filter()
assert_raises(ValueError, res.predict)
mod.memory_no_predicted = False
# Now get a clean filter object
res = mod.filter()
# Check that start < 0 is an error
assert_raises(ValueError, res.predict, start=-1)
# Check that end < start is an error
assert_raises(ValueError, res.predict, start=2, end=1)
# Check that dynamic < 0 is an error
assert_raises(ValueError, res.predict, dynamic=-1)
# Check that dynamic > end is an warning
with warnings.catch_warnings(record=True) as w:
res.predict(end=1, dynamic=2)
message = "Dynamic prediction specified to begin after the end of" " prediction, and so has no effect."
assert_equal(str(w[0].message), message)
# Check that dynamic > nobs is an warning
with warnings.catch_warnings(record=True) as w:
res.predict(end=11, dynamic=11, obs_intercept=np.zeros((1, 1)))
message = (
"Dynamic prediction specified to begin during" " out-of-sample forecasting period, and so has no" " effect."
)
assert_equal(str(w[0].message), message)
# Check for a warning when providing a non-used statespace matrix
with warnings.catch_warnings(record=True) as w:
res.predict(end=res.nobs + 1, design=True, obs_intercept=np.zeros((1, 1)))
message = "Model has time-invariant design matrix, so the design" " argument to `predict` has been ignored."
assert_equal(str(w[0].message), message)
# Check that an error is raised when a new time-varying matrix is not
# provided
assert_raises(ValueError, res.predict, end=res.nobs + 1)
# Check that an error is raised when a non-two-dimensional obs_intercept
# is given
assert_raises(ValueError, res.predict, end=res.nobs + 1, obs_intercept=np.zeros(1))
# Check that an error is raised when an obs_intercept with incorrect length
# is given
assert_raises(ValueError, res.predict, end=res.nobs + 1, obs_intercept=np.zeros(2))
# Check that start=None gives start=0 and end=None gives end=nobs
assert_equal(res.predict().shape, (1, res.nobs))
# Check that dynamic=True begins dynamic prediction immediately
# TODO just a smoke test
res.predict(dynamic=True)
# Check that full_results=True yields a FilterResults object
assert_equal(isinstance(res.predict(full_results=True), FilterResults), True)
# Check that an error is raised when a non-two-dimensional obs_cov
# is given
# ...and...
# Check that an error is raised when an obs_cov with incorrect length
# is given
mod = KalmanFilter(endog, k_states=1, initialization="approximate_diffuse")
mod["design", :] = 1
mod["obs_cov"] = np.zeros((1, 1, 10))
mod["selection", :] = 1
mod["state_cov", :] = 1
res = mod.filter()
assert_raises(ValueError, res.predict, end=res.nobs + 1, obs_cov=np.zeros((1, 1)))
assert_raises(ValueError, res.predict, end=res.nobs + 1, obs_cov=np.zeros((1, 1, 2)))
示例2: test_predict
# 需要导入模块: from statsmodels.tsa.statespace.kalman_filter import KalmanFilter [as 别名]
# 或者: from statsmodels.tsa.statespace.kalman_filter.KalmanFilter import memory_no_forecast [as 别名]
def test_predict():
# Tests of invalid calls to the predict function
warnings.simplefilter("always")
endog = np.ones((10,1))
mod = KalmanFilter(endog, k_states=1, initialization='approximate_diffuse')
mod['design', :] = 1
mod['obs_intercept'] = np.zeros((1,10))
mod['selection', :] = 1
mod['state_cov', :] = 1
# Check that we need both forecasts and predicted output for prediction
mod.memory_no_forecast = True
res = mod.filter()
assert_raises(ValueError, res.predict)
mod.memory_no_forecast = False
mod.memory_no_predicted = True
res = mod.filter()
assert_raises(ValueError, res.predict)
mod.memory_no_predicted = False
# Now get a clean filter object
res = mod.filter()
# Check that start < 0 is an error
assert_raises(ValueError, res.predict, start=-1)
# Check that end < start is an error
assert_raises(ValueError, res.predict, start=2, end=1)
# Check that dynamic < 0 is an error
assert_raises(ValueError, res.predict, dynamic=-1)
# Check that dynamic > end is an warning
with warnings.catch_warnings(record=True) as w:
res.predict(end=1, dynamic=2)
message = ('Dynamic prediction specified to begin after the end of'
' prediction, and so has no effect.')
assert_equal(str(w[0].message), message)
# Check that dynamic > nobs is an warning
with warnings.catch_warnings(record=True) as w:
res.predict(end=11, dynamic=11, obs_intercept=np.zeros((1,1)))
message = ('Dynamic prediction specified to begin during'
' out-of-sample forecasting period, and so has no'
' effect.')
assert_equal(str(w[0].message), message)
# Check for a warning when providing a non-used statespace matrix
with warnings.catch_warnings(record=True) as w:
res.predict(end=res.nobs+1, design=True, obs_intercept=np.zeros((1,1)))
message = ('Model has time-invariant design matrix, so the design'
' argument to `predict` has been ignored.')
assert_equal(str(w[0].message), message)
# Check that an error is raised when a new time-varying matrix is not
# provided
assert_raises(ValueError, res.predict, end=res.nobs+1)
# Check that an error is raised when a non-two-dimensional obs_intercept
# is given
assert_raises(ValueError, res.predict, end=res.nobs+1,
obs_intercept=np.zeros(1))
# Check that an error is raised when an obs_intercept with incorrect length
# is given
assert_raises(ValueError, res.predict, end=res.nobs+1,
obs_intercept=np.zeros(2))
# Check that start=None gives start=0 and end=None gives end=nobs
assert_equal(res.predict().forecasts.shape, (1,res.nobs))
# Check that dynamic=True begins dynamic prediction immediately
# TODO just a smoke test
res.predict(dynamic=True)
# Check that on success, PredictionResults object is returned
prediction_results = res.predict(start=3, end=5)
assert_equal(isinstance(prediction_results, PredictionResults), True)
# Check for correctly subset representation arrays
# (k_endog, npredictions) = (1, 2)
assert_equal(prediction_results.endog.shape, (1, 2))
# (k_endog, npredictions) = (1, 2)
assert_equal(prediction_results.obs_intercept.shape, (1, 2))
# (k_endog, k_states) = (1, 1)
assert_equal(prediction_results.design.shape, (1, 1))
# (k_endog, k_endog) = (1, 1)
assert_equal(prediction_results.obs_cov.shape, (1, 1))
# (k_state,) = (1,)
assert_equal(prediction_results.state_intercept.shape, (1,))
# (k_state, npredictions) = (1, 2)
assert_equal(prediction_results.obs_intercept.shape, (1, 2))
# (k_state, k_state) = (1, 1)
assert_equal(prediction_results.transition.shape, (1, 1))
# (k_state, k_posdef) = (1, 1)
assert_equal(prediction_results.selection.shape, (1, 1))
# (k_posdef, k_posdef) = (1, 1)
#.........这里部分代码省略.........