Browse Source

ARIMA Stability Test

master
杨浩然 4 years ago
parent
commit
8dc219c943
5 changed files with 46 additions and 2 deletions
  1. BIN
      COVID-19/Prediction/.vs/Prediction/v16/.suo
  2. +4
    -1
      COVID-19/Prediction/Prediction/ARIMA.py
  3. +3
    -0
      COVID-19/Prediction/Prediction/ARIMA.pyproj
  4. +1
    -1
      COVID-19/Prediction/Prediction/Holt_Winters.py
  5. +38
    -0
      COVID-19/Prediction/Prediction/StabilityTest.py

BIN
COVID-19/Prediction/.vs/Prediction/v16/.suo View File


+ 4
- 1
COVID-19/Prediction/Prediction/ARIMA.py View File

@ -8,7 +8,7 @@ import statsmodels.api as sm
from sklearn.metrics import mean_squared_error
#打开数据文件
dataset = pd.read_csv('E:\dase intro\COVID-19Analysis\COVID-19\covid-19-all.csv')
dataset = pd.read_csv('E:\DaseIntro\COVID-19Analysis\COVID-19\covid-19-all.csv')
#数据预处理
def parse_ymd(s):
@ -24,6 +24,9 @@ CN.index = pd.Index(pd.date_range('2020-01-22','2020-12-09',freq = '1D'))
US = dataset[dataset['Country/Region'] == 'US']
US.index = pd.Index(pd.date_range('2020-01-22','2020-12-09',freq = '1D'))
print(CN)
print(US)
#划分训练集、测试集
trainCN = CN[CN['Date'] < '2020-11-01 ']
testCN = CN[CN['Date'] >= '2020-11-01']

+ 3
- 0
COVID-19/Prediction/Prediction/ARIMA.pyproj View File

@ -24,6 +24,9 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="ARIMA.py" />
<Compile Include="StabilityTest.py">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
<!-- Uncomment the CoreCompile target to enable the Build command in

+ 1
- 1
COVID-19/Prediction/Prediction/Holt_Winters.py View File

@ -8,7 +8,7 @@ from statsmodels.tsa.api import ExponentialSmoothing
from sklearn.metrics import mean_squared_error
#打开数据文件
dataset = pd.read_csv('E:\dase intro\COVID-19Analysis\COVID-19\covid-19-all.csv')
dataset = pd.read_csv('E:\DaseIntro\COVID-19Analysis\COVID-19\covid-19-all.csv')
#数据预处理
def parse_ymd(s):

+ 38
- 0
COVID-19/Prediction/Prediction/StabilityTest.py View File

@ -0,0 +1,38 @@
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import statsmodels.api as sm
from statsmodels.graphics.tsaplots import acf,pacf,plot_acf,plot_pacf
from statsmodels.tsa.arima_model import ARMA
from statsmodels.tsa.stattools import adfuller
#打开数据文件
dataset = pd.read_csv('E:\DaseIntro\COVID-19Analysis\COVID-19\covid-19-all.csv')
#数据预处理
def parse_ymd(s):
year_s, mon_s, day_s = s.split('-')
return datetime.datetime(int(year_s), int(mon_s), int(day_s)).strftime("%Y-%m-%d")
dataset = dataset.fillna(0)
dataset['Date'] = pd.to_datetime(dataset['Date'])
dataset = dataset[['Country/Region','Confirmed','Recovered','Deaths','Date']].groupby(['Country/Region','Date']).sum().reset_index()
#取出中、美的数据
CN = dataset[dataset['Country/Region'] == 'China']
CN.index = pd.Index(pd.date_range('2020-01-22','2020-12-09',freq = '1D'))
US = dataset[dataset['Country/Region'] == 'US']
US.index = pd.Index(pd.date_range('2020-01-22','2020-12-09',freq = '1D'))
#检验Confirmed
CNconfirmedSeries = pd.DataFrame(CN['Confirmed'])
CNconfirmedSeries['Confirmed'] = CNconfirmedSeries['Confirmed'] - CNconfirmedSeries['Confirmed'].shift(1)
CNconfirmedSeries.plot(figsize=(8,6))
CNrecoveredSeries = pd.DataFrame(CN['Recovered'])
CNrecoveredSeries['Recovered'] = CNrecoveredSeries['Recovered'] - CNrecoveredSeries['Recovered'].shift(1)
CNrecoveredSeries.plot(figsize=(8,6))
CNdeathsSeries = pd.DataFrame(CN['Deaths'])
CNdeathsSeries['Deaths'] = CNdeathsSeries['Deaths'] - CNdeathsSeries['Deaths'].shift(1)
CNdeathsSeries.plot(figsize=(8,6))
plt.show()

Loading…
Cancel
Save