最近我们被客户要求撰写关于神经网络的研究报告,包括一些图形和统计输出。

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

 相关视频:LSTM神经网络架构和工作原理及其在Python中的预测应用

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

视频

在Python和R语言中建立EWMA,ARIMA模型预测时间序列


获取时间序列数据

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)


Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐