Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从数据中减少预测,但有严格的上升趋势?_Python_Time Series - Fatal编程技术网

Python 从数据中减少预测,但有严格的上升趋势?

Python 从数据中减少预测,但有严格的上升趋势?,python,time-series,Python,Time Series,我正在使用ARMA对未来4年进行时间序列预测。我的数据有一个不断上升的趋势,但由于某种原因,预测结果是下降的 from pandas import Series import numpy as np from scipy import stats import pandas as pd import matplotlib.pyplot as plt import statsmodels.api as sm from statsmodels.graphics.api import qqplot f

我正在使用ARMA对未来4年进行时间序列预测。我的数据有一个不断上升的趋势,但由于某种原因,预测结果是下降的

from pandas import Series
import numpy as np
from scipy import stats
import pandas as pd
import matplotlib.pyplot as plt
import statsmodels.api as sm
from statsmodels.graphics.api import qqplot
from sklearn.metrics import mean_squared_error

dta = pd.read_csv('/Users/nsilverblatt/Downloads/test11111 - Sheet1 (4).csv', header=0)

x = dta['Total Revenue (in thousands)'].astype(float)

x.index = pd.Index(sm.tsa.datetools.dates_from_range('2011', '2016'))

print(x)
arma_mod = sm.tsa.ARMA(x, (2,0)).fit()

print(arma_mod.params)

my_predictions = arma_mod.predict('2016', '2020', dynamic=True)
print(my_predictions)
这是我的CSV数据,第一行是2011年的总收入,最后一行是2016年的总收入

Total Revenue (in thousands)

3399886
3897900
4595798
4965460
5308164
5520344
以下是递减预测:

2016-12-31    5.481435e+06
2017-12-31    5.465197e+06
2018-12-31    5.279251e+06
2019-12-31    4.975813e+06
2020-12-31    4.626178e+06

从时间序列中去除线性趋势的一个简单方法是取n和n-1的差值。例如,
导入熊猫
<代码>系列=熊猫。系列(范围(10))<代码>(series-series.shift(1))`@aquil.abdullah这对我的代码有什么作用?你是说这会使我的预测趋势上升,这是基于输入(过去)数据的有意义的吗?不,我是说,如果你知道你的数据中有趋势,你可以使用差异从数据中删除该趋势。事实上,pandas提供了一个diff函数。如果您知道存在偏差,您可能希望将ARMA应用于去趋势数据。ARMA模型假设平稳序列,预测恢复为平均值。您可以指定线性趋势,也可以使用ARIMA模型,即使用差分。@user333700如何指定线性趋势?