新冠肺炎的可视化和Logistic增长模型预测分析(新手入坑) 您所在的位置:网站首页 全球确诊病例详情公布图 新冠肺炎的可视化和Logistic增长模型预测分析(新手入坑)

新冠肺炎的可视化和Logistic增长模型预测分析(新手入坑)

2023-10-02 08:15| 来源: 网络整理| 查看: 265

新冠肺炎的可视化和Logistic增长模型预测分析(新手入坑)

Jupyter notebook代码进行了全球性可视化分析,并对美国感染人数进行了预测; 本人GitHub项目: https://github.com/null421/COVID 参考GitHub项目: https://github.com/fengdu78/machine_learning_beginner/tree/master/covid19 数据来源: https://github.com/CSSEGISandData/COVID-19

全球新冠疫情发展趋势 subset = ww_trend['2020-01-22':'2020-05-05'] ax = subset.plot(figsize=(15, 10),linewidth=2,fontsize=10) plt.title('Worldwide Confirmed/Death Cases Over Time') plt.xlabel('date') plt.ylabel('Confirmed/Death') plt.show()

全球确诊/死亡/新增病例

ww_trend['mortality'] = ww_trend['deaths'] / ww_trend['confirmed'] x=ww_trend.mortality plt.figure(figsize = (15,10)) plt.plot(x)

全球致死率

可以看到世界疫情从三月中旬开始,便呈现指数级增长。在半个月内,全球确诊病例翻了一倍,死亡率也随之指数级上升。而三月中旬正好国内疫情进入攻坚后半段,形势好转,确诊人数各省逐步清零,但这时仅仅是国外疫情爆发的开始… 各大洲及国家新冠疫情发展趋势

1.亚洲

country_asian = country_data.query('date == @target_date') fig = px.choropleth( country_asian, locations="country", locationmode='country names', color="confirmed", hover_name="country", range_color=[1, 50000], color_continuous_scale='portland', title=f'Asian Countries with Confirmed Cases as of {target_date}', scope='asia', height=800) fig.show()

截至到2020/5/5亚洲确诊情况

top_asian_country = country_data[country_data['country'].isin([ 'China', 'Iran', 'Japan', 'South Korea','Turkey','India' ])] top_asian_country fig = px.line(top_asian_country, x='date', y='confirmed', color='country', title=f'DAILY Confirmed cases world wide') fig.show()

截至到2020/5/5部分国家确诊情况 2.欧洲

europe_country_list =list([ 'Austria','Belgium','Bulgaria','Croatia','Cyprus','Czechia','Denmark','Estonia','Finland','France','Germany','Greece','Hungary','Ireland', 'Italy', 'Latvia','Luxembourg','Lithuania','Malta','Norway','Netherlands','Poland','Portugal','Romania','Slovakia','Slovenia', 'Spain', 'Sweden', 'United Kingdom', 'Iceland', 'Russia', 'Switzerland', 'Serbia', 'Ukraine', 'Belarus', 'Albania', 'Bosnia and Herzegovina', 'Kosovo', 'Moldova', 'Montenegro', 'North Macedonia']) country_data['date'] = pd.to_datetime(country_data['date']) train_europe = country_data[country_data['country'].isin(europe_country_list)] #train_europe['date_str'] = pd.to_datetime(train_europe['date']) train_europe_latest = train_europe.query('date == @target_date') fig = px.choropleth( train_europe_latest, locations="country", locationmode='country names', color="confirmed", hover_name="country", range_color=[1, train_europe_latest['confirmed'].max()], color_continuous_scale='portland', title=f'European Countries with Confirmed Cases as of {target_date}', scope='europe', height=800) fig.show()

截至到2020/5/5欧洲确诊情况 3.各国家疫情对比

countries = country_data['country'].unique() print(f'{len(countries)} countries are in dataset:\n{countries}')

数据集中所包含的国家共187个

# 条形图的绘制--垂直条形图 plt.figure(figsize = (15,10)) plt.style.use('ggplot') # 绘制条形图 plt.bar(x = range(top_country.shape[0]), # 指定条形图x轴的刻度值 height = top_country.confirmed, # 指定条形图y轴的数值 tick_label =top_country.country, # 指定条形图x轴的刻度标签 color = 'steelblue', # 指定条形图的填充色 width = 1 ) plt.xlim(0, 10) # 添加y轴的标签 plt.ylabel('confirmed') # 添加条形图的标题 plt.title('Confirmed Cases on 5/5/20') # 显示图形 plt.show()

全球范围确诊前十一国家

# 条形图的绘制--垂直条形图 plt.figure(figsize = (15,10)) plt.style.use('ggplot') # 绘制条形图 plt.bar(x = range(top_country.shape[0]), # 指定条形图x轴的刻度值 height = top_country.deaths, # 指定条形图y轴的数值 tick_label =top_country.country, # 指定条形图x轴的刻度标签 color = 'steelblue', # 指定条形图的填充色 width = 1 ) plt.xlim(0, 10) # 添加y轴的标签 plt.ylabel('deaths') # 添加条形图的标题 plt.title('deaths Cases on 5/5/20') # 显示图形 plt.show()

各国家对应的死亡人数

x=top_country.country y=top_country.mortality plt.figure(figsize = (15,10)) plt.xlim(0, 10) plt.plot(x,y)

截至2020/5/5各国家死亡率

在本次数据中,值得注意的是俄罗斯。它确诊人数高,但是其死亡率却明显的低于其他十个国家 基于Logistic增长模型预测美国确诊数目

1.美国疫情分析

x=data['date'] y=data['confirmed'] fig=plt.figure(figsize=(20,5)) #建立画布 plt.plot(x, y,marker='*',linestyle='-') plt.title('疫情趋势图')#加标题 plt.ylabel('患病人数') plt.xlabel("日期") plt.show()

疫情趋势图

截至到2020/5/5,美国疫情仍在上升趋势,疫情拐点还未到来; 2.Logistic增长模型介绍(逻辑斯蒂增长模型) 增长模型 逻辑斯蒂模型,又叫阻滞增长模型 逻辑斯蒂曲线通常分为5个时期: a) 开始期,由于种群个体数很少,密度增长缓慢,又称潜伏期。 b) 加速期,随个体数增加,密度增长加快。 c) 转折期,当个体数达到饱和密度一半(K/2),密度增长最快。 d) 减速期,个体数超过密度一半(K/2)后,增长变慢。 e) 饱和期,种群个体数达到K值而饱和。

根据历史经验,2003年非典患者预测,部分学者利用逻辑斯蒂增长模型进行预测,并且准确率很高,所以我也尝试利用逻辑斯蒂增长模型进行新型冠状病毒患者数量,逻辑斯蒂增长模型具体为: 在这里插入图片描述 (其中K为环境最大容量,P0为初始容量,r为增长速率,r越大则增长越快(即更快的逼近上限)。)

3.预测 在这里插入图片描述 在这里插入图片描述 误差散点图 拟合图形 反思:

模型预测的结果是近90天内美国新冠肺炎最终的患者数量是145万人左右,拐点出现在第80天,即6月19日左右。模型拟合度较高,但结合实际仍存在偏差;模型预测5.6号-5.12号确诊人数在120万-130万之间浮动,但实际数据中美国在此期间早已突破130万确诊人数,在5.13号已经突破140万确诊人数(模型预测为131万)。因此后续还需要对模型进行进一步的调参以完善预测数据;

补充:遇到GitHub中ipynb文件打不开,可将github文件复制到 https://nbviewer.jupyter.org/ 进行打开



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有