Python用RNN循环神经网络:LSTM长期记忆、GRU门循环单元、回归和ARIMA对COVID-19新冠疫情新增人数时间序列预测

该数据根据世界各国提供的新病例数据。

由Kaizong Ye,Sherry Deng撰写

获取时间序列数据

df=pd.read_csv("C://global.csv")

探索数据

此表中的数据以累积的形式呈现,为了找出每天的新病例,我们需要减去这些值

df.head(10)

这些数据是根据国家和地区报告新病例的数据,但我们只想预测国家的新病例,因此我们使用 groupby 根据国家对它们进行分组


视频

LSTM神经网络架构和原理及其在Python中的预测应用

探索见解

去bilibili观看

探索更多视频

总结数据

执行 groupby 以根据一个国家的新病例来汇总数据,而不是根据地区

d1=df.groupby(\['Country/Region'\]).sum()

描述随机选择的国家的累计新病例增长

from numpy.random import seed



    plt.plot(F\[i\], label = RD\[i\])

    plt.show()
# 我们不需要前两列

d1=d1.iloc\[:,2:\]

R语言结合新冠疫情COVID-19对股票价格预测:ARIMA,KNN和神经网络时间序列分析

阅读文章


# # 检查是否有空值



d1.isnull().sum().any()

我们可以对每个国家进行预测,也可以对所有国家进行预测,这次我们对所有国家进行预测


随时关注您喜欢的主题


dlycnmdcas.head()
dalycnfreces.index
dal\_cnre\_ces.index = pd.to\_datetime(dailyonfrmd\_as.index)
plt.plot(dalnimedases)
ne\_ces = daiy\_onme_as.diff().dropna().astype(np.int64)

newcaes
plt.plot(ne_s\[1:\])
nw_s.shape
(153,)

将数据拆分为训练和测试数据

ct=0.75

trin\_aa,tet\_aa = train\_test\_split(ne_ces, pct)
(116,)
``````
plt.plot(tainta)

plt.plot(tesata)

数据标准化

scaler = MinMaxScaler()
testa.shape
(38, 1)

创建序列

lentTe = len(ts_data)

for i in range(timmp, lenhTe):

    X\_st.append(tst\_aa\[i-tmStap:i\])

    y_tt.append(tesata\[i\])



X\_tet=np.array(X\_ts)

ytes=np.array(y_tt)

X_st.shape
Xtrn.shape
#  序列的样本 

X_trn\[0\], yran\[0\]

为股票价格预测设计 RNN 模型

模型:

  1. LSTM
  2. GRU
model.summary()
model.fit(X\_trn y\_rin, epochs=50, batch_size=200)
yprd = (mod.predict(X_test))

MSE = mean\_squared\_error(ytue, y_rd)



plt.figure(figsize=(14,6))
meRU= Sqtal(\[

                keras.layers.GRU(









model\_GRU.fit(Xtrn, ytin,epochs=50,batch\_size=150)
pe_rut = {}



y\_ue = (y\_et.reshape(-1,1))

y\_prd = (modlGU.predict(X\_test))

MSE = mean\_squared\_error(y_ue, ed)

用于预测新病例的机器学习算法

准备数据

d__in.shape
moel=LinearRegression(nos=-2)

ARIMA

COVID-19 新病例预测的自回归综合移动平均线

#我们不需要前两列

df1.head()

daly\_nfrd\_cses = df1.sum(axis=0)

day\_cnir\_ase.index = pd.to\_datetime(da\_onieses.index)
new_cs = dacofmecss.diff().dropna().astype(np.int64)



tri\_ta,tet\_ata = trintt\_it(nw\_es, pct)
ero = men\_squred\_eror(ts_ar, pricos)
plt.figure(figsize=(12,7))

plt.plot(tanat)


可下载资源

关于作者

Kaizong Ye拓端研究室(TRL)的研究员。

本文借鉴了作者最近为《R语言数据分析挖掘必知必会 》课堂做的准备。

​非常感谢您阅读本文,如需帮助请联系我们!

 
QQ在线咨询
售前咨询热线
15121130882
售后咨询热线
0571-63341498

关注有关新文章的微信公众号


永远不要错过任何见解。当新文章发表时,我们会通过微信公众号向您推送。

技术干货

最新洞察

This will close in 0 seconds