前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >新冠肺炎的可视化和预测分析(附代码)

新冠肺炎的可视化和预测分析(附代码)

作者头像
黄博的机器学习圈子
发布2020-04-21 14:59:13
1.7K1
发布2020-04-21 14:59:13
举报

新冠肺炎现在情况怎么样了?推荐一份Jupyter notebook代码进行了分析,把数据可视化,并对感染人数进行了预测。 来源:https://www.kaggle.com/corochann/covid-19-eda-with-recent-update-on-april?scriptVersionId=32149572

本文的可视化通过ployly实现。

本文数据更新到4月14日,最新数据下载:

https://www.kaggle.com/corochann/covid-19-eda-with-recent-update-on-april/data?scriptVersionId=32149572

(下载train.csv、test.csv、usa_states2.csv) 到input的convid19目录即可,数据更新到2020-4-14。

原始数据是这里下载修改的:

https://github.com/CSSEGISandData/COVID-19

完整代码放在github下载:

https://github.com/fengdu78/machine_learning_beginner/tree/master/covid19

代码内容

这份分析代码主要分为以下几个部分:

  • 全球趋势
  • 国家(地区)增长
  • 省份情况
  • 放大美国:现在美国正在发生什么?
  • 欧洲
  • 亚洲
  • 现在哪个国家正在复苏?
  • 什么时候会收敛?通过S型拟合进行预测

全球趋势

代码语言:javascript
复制
fig = px.line(ww_melt_df, x="date", y="value", color='variable', 
              title="Worldwide Confirmed/Death Cases Over Time")
fig.show()

世界确诊和死亡数

代码语言:javascript
复制
fig = px.line(ww_melt_df, x="date", y="value", color='variable',
              title="Worldwide Confirmed/Death Cases Over Time (Log scale)",
             log_y=True)
fig.show()

世界确诊和死亡数(取对数)

国家(地区)增长

代码语言:javascript
复制
fig = px.bar(top_country_melt_df.iloc[::-1],
             x='value',
             y='country',
             color='variable',
             barmode='group',
             title=f'Confirmed Cases/Deaths on {target_date}',
             text='value',
             height=1500,
             orientation='h')
fig.show()

确诊数和死亡数

代码语言:javascript
复制
top30_countries = top_country_df.sort_values(
    'confirmed', ascending=False).iloc[:30]['country'].unique()
top30_countries_df = country_df[country_df['country'].isin(top30_countries)]
fig = px.line(top30_countries_df,
              x='date',
              y='confirmed',
              color='country',
              title=f'Confirmed Cases for top 30 country as of {target_date}')
fig.show()

死亡最多的国家

代码语言:javascript
复制
fig = px.bar(top_country_df[:30].iloc[::-1],
             x='mortality_rate',
             y='country',
             title=f'Mortality rate HIGH: top 30 countries on {target_date}',
             text='mortality_rate',
             height=800,
             orientation='h')
fig.show()

死亡率最高的国家

省份情况

出现新冠肺炎的主要国家的各省(州)的清单

放大美国:现在美国正在发生什么?

代码语言:javascript
复制
fig = px.choropleth(train_us_latest,
                    locations='province_code',
                    locationmode="USA-states",
                    color='confirmed',
                    scope="usa",
                    hover_data=['province', 'fatalities', 'mortality_rate'],
                    title=f'Confirmed cases in US on {target_date}')
fig.show()

美国的死亡率情况

代码语言:javascript
复制
train_us_march = train_us.query('date > "2020-03-01"')
fig = px.line(train_us_march,
              x='date', y='confirmed', color='province',
              title=f'Confirmed cases by state in US, as of {target_date}')
fig.show()

美国各州的确诊数

欧洲

代码语言:javascript
复制
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()

欧洲确诊数

亚洲

代码语言:javascript
复制
country_latest = country_df.query('date == @target_date')

fig = px.choropleth(
    country_latest,
    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()

亚洲确诊数

代码语言:javascript
复制
top_asian_country_df = country_df[country_df['country'].isin([
    'China', 'Indonesia', 'Iran', 'Japan', 'Korea, South', 'Malaysia',
    'Philippines'
])]

fig = px.line(top_asian_country_df,
              x='date',
              y='new_case',
              color='country',
              title=f'DAILY NEW Confirmed cases world wide')
fig.show()

亚洲每日确诊数量

现在哪个国家正在复苏?

代码语言:javascript
复制
fig = px.choropleth(
    country_latest,
    locations="country",
    locationmode='country names',
    color="new_case_peak_to_now_ratio",
    hover_name="country",
    range_color=[0, 1],
    # color_continuous_scale="peach",
    hover_data=['confirmed', 'fatalities', 'new_case', 'max_new_case'],
    title='Countries with new_case_peak_to_now_ratio')
fig.show()

可以看到中国是最安全的国家了

什么时候会收敛?通过Sigmoid拟合进行预测

代码语言:javascript
复制
plot_sigmoid_fitting(target_country_df_list,
                     pred_df_list,
                     title='Sigmoid fitting with all latest data')

确诊数预测,美国将会达到70万以上确诊

总结

本文推荐一份Jupyter notebook代码进行了分析,把数据可视化,并对感染人数进行了预测。

完整代码放在github下载:

https://github.com/fengdu78/machine_learning_beginner/tree/master/covid19

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-04-18,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 机器学习初学者 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 代码内容
  • 全球趋势
  • 国家(地区)增长
  • 省份情况
  • 放大美国:现在美国正在发生什么?
  • 欧洲
  • 亚洲
  • 现在哪个国家正在复苏?
  • 什么时候会收敛?通过Sigmoid拟合进行预测
  • 总结
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档