关于数据挖掘:Python用RNN循环神经网络LSTM长期记忆GRU门循环单元回归和ARIMA对COVID19新冠疫情人数时间序列预测

5次阅读

共计 2083 个字符,预计需要花费 6 分钟才能阅读完成。

原文链接:http://tecdat.cn/?p=27042

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

获取工夫序列数据

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

摸索数据

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

df.head(10)

 

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

 

总结数据

执行 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:\]

# # 查看是否有空值



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)


最受欢迎的见解

1. 在 python 中应用 lstm 和 pytorch 进行工夫序列预测

2.python 中利用长短期记忆模型 lstm 进行工夫序列预测剖析

3. 应用 r 语言进行工夫序列(arima,指数平滑)剖析

4.r 语言多元 copula-garch- 模型工夫序列预测

5.r 语言 copulas 和金融工夫序列案例

6. 应用 r 语言随机稳定模型 sv 解决工夫序列中的随机稳定

7.r 语言工夫序列 tar 阈值自回归模型

8.r 语言 k -shape 工夫序列聚类办法对股票价格工夫序列聚类

9.python3 用 arima 模型进行工夫序列预测

正文完
 0