<article class=“article fmt article-content”><h2>原文链接:http://tecdat.cn/?p=27042</h2><h3>原文出处:拓端数据部落公众号</h3><p>该数据依据世界各国提供的新病例数据提供。</p><h2>获取工夫序列数据</h2><pre><code>df=pd.read_csv(“C://global.csv”)</code></pre><h2>摸索数据</h2><p>此表中的数据以累积的模式出现,为了找出每天的新病例,咱们须要减去这些值</p><p></p><pre><code>df.head(10)</code></pre><p></p><p>这些数据是依据国家和地区报告新病例的数据,但咱们只想预测国家的新病例,因而咱们应用 groupby 依据国家对它们进行分组</p><p></p><h2>总结数据</h2><p>执行 groupby 以依据一个国家的新病例来汇总数据,而不是依据地区</p><pre><code>d1=df.groupby([‘Country/Region’]).sum()</code></pre><p></p><p></p><h2>形容随机抉择的国家的累计新病例增长</h2><pre><code>from numpy.random import seed plt.plot(F[i], label = RD[i]) plt.show()</code></pre><p></p><p></p><p></p><p></p><pre><code># 咱们不须要前两列d1=d1.iloc[:,2:]</code></pre><p></p><pre><code># # 查看是否有空值d1.isnull().sum().any()</code></pre><p></p><p>咱们能够对每个国家进行预测,也能够对所有国家进行预测,这次咱们对所有国家进行预测</p><pre><code>dlycnmdcas.head()</code></pre><p></p><pre><code>dalycnfreces.index</code></pre><pre><code>dal_cnre_ces.index = pd.to_datetime(dailyonfrmd_as.index)</code></pre><p></p><p></p><pre><code>plt.plot(dalnimedases)</code></pre><p></p><pre><code>ne_ces = daiy_onme_as.diff().dropna().astype(np.int64)newcaes</code></pre><p></p><p></p><pre><code>plt.plot(ne_s[1:])</code></pre><p></p><pre><code>nw_s.shape</code></pre><pre><code>(153,)</code></pre><h2>将数据拆分为训练和测试数据</h2><pre><code>ct=0.75trin_aa,tet_aa = train_test_split(ne_ces, pct)</code></pre><pre><code>(116,)</code></pre><pre><code>plt.plot(tainta)plt.plot(tesata)</code></pre><p></p><h2>数据标准化</h2><pre><code>scaler = MinMaxScaler()</code></pre><pre><code>testa.shape </code></pre><pre><code>(38, 1)</code></pre><h2>创立序列</h2><pre><code>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)</code></pre><pre><code>X_st.shape</code></pre><p></p><p></p><p></p><pre><code>Xtrn.shape</code></pre><p></p><pre><code># 序列的样本 X_trn[0], yran[0]</code></pre><p></p><h2>为股票价格预测设计 RNN 模型</h2><p>模型:</p><ol><li>LSTM</li><li>GRU</li></ol><pre><code>model.summary()</code></pre><p></p><pre><code>model.fit(X_trn y_rin, epochs=50, batch_size=200)</code></pre><p></p><p></p><p></p><pre><code>yprd = (mod.predict(X_test))MSE = mean_squared_error(ytue, y_rd)plt.figure(figsize=(14,6))</code></pre><p></p><pre><code>meRU= Sqtal([ keras.layers.GRU(model_GRU.fit(Xtrn, ytin,epochs=50,batch_size=150)</code></pre><p></p><p></p><pre><code>pe_rut = {}y_ue = (y_et.reshape(-1,1))y_prd = (modlGU.predict(X_test))MSE = mean_squared_error(y_ue, ed)</code></pre><p></p><h2>用于预测新病例的机器学习算法</h2><p>筹备数据</p><pre><code>d__in.shape</code></pre><p></p><pre><code>moel=LinearRegression(nos=-2)</code></pre><p></p><h2>ARIMA</h2><p>COVID-19 新病例预测的自回归综合挪动平均线</p><pre><code>#咱们不须要前两列df1.head()daly_nfrd_cses = df1.sum(axis=0)day_cnir_ase.index = pd.to_datetime(da_onieses.index)</code></pre><pre><code>new_cs = dacofmecss.diff().dropna().astype(np.int64)tri_ta,tet_ata = trintt_it(nw_es, pct)</code></pre><p></p><pre><code>ero = men_squred_eror(ts_ar, pricos)</code></pre><p></p><p></p><p></p><pre><code>plt.figure(figsize=(12,7))plt.plot(tanat)</code></pre><p></p><p></p><p>最受欢迎的见解</p><p>1.在python中应用lstm和pytorch进行工夫序列预测</p><p>2.python中利用长短期记忆模型lstm进行工夫序列预测剖析</p><p>3.应用r语言进行工夫序列(arima,指数平滑)剖析</p><p>4.r语言多元copula-garch-模型工夫序列预测</p><p>5.r语言copulas和金融工夫序列案例</p><p>6.应用r语言随机稳定模型sv解决工夫序列中的随机稳定</p><p>7.r语言工夫序列tar阈值自回归模型</p><p>8.r语言k-shape工夫序列聚类办法对股票价格工夫序列聚类</p><p>9.python3用arima模型进行工夫序列预测</p></article>