关于Coronavirus数据简单的可视化分析(Plotly的一个例子)

王 茂南 2020年5月13日07:20:55
评论
1 14969字阅读49分53秒
摘要这一篇简单对Coronavirus数据进行简单的分析. 因为这个是我的一个期末大作业, 我就在这里记录一下详细的分析的步骤. 主要集中在可视化和与其他数据集联合分析的部分.

简介

这一篇是关于对Coronavirus数据的一些简单分析. 这里会包括数据处理, 简单的数据可视化和简单的预测, 寻找变量与变量之间的关系. 我们下面在介绍的时候, 就会分成这三个部分一一进行介绍.

这个其实是我的一个大作业, 在这里也是记录一下我做大作业的一个步骤, 也是记录一下如何使用Plotly来进行可视化的展示.

 

相关的链接

 

数据集介绍

这一部分的内容和上面的关于课程作业的相关说明链接里的内容是一样的, 我自这里重新说明一下, 为了方便后面的介绍.

Coronavirus的数据集

首先关于Coronavirus的数据集来自github, COVID-19 Data Repository by the Center for Systems Science and Engineering (CSSE) at Johns Hopkins University

在这个仓库里面, 他会更新每一天的, 每一个国家的Coronavirus的确诊人数, 死亡人数和恢复人数. 也就是会有三张表格, 分别记录confirmed, death和recovered.

我们看一下数据的样例, 可以看到数据包括国家名称, 省或州的名字, 精度和纬度, 和每一天的人数(confirmed, death, recovered):

关于Coronavirus数据简单的可视化分析(Plotly的一个例子)

GDP, Population和Aging数据集

因为我们想要分析人数与国家发展, 国家人口和老龄化之间的关系, 所以我们还用到了另外三个数据集, 链接如下:

这些数据的格式基本都是一样的, 我们就看一下每个国家的人均GDP的数据的数据样例.

关于Coronavirus数据简单的可视化分析(Plotly的一个例子)

 

数据处理

合并各省(州)数据

因为我们之后是对整个国家进行分析, 但是在原始数据集中细分到了省和州的数据, 所以我们需要首先对他们进行合并.

我们使用group_by对数据进行合并, 同时对不同的变量采用不同的操作. 对每一天的人数, 我们将其求和, 也就是对一个国家不同省的人数求和, 得到那个国家当天的数据. 对经度和纬度我们求平均.

首先我们建立一个字典, 为index名称对应执行的操作.

  1. dict_groupby = {i:'sumfor i in confirm.columns.values[4:]}
  2. dict_groupby['Lat'] = 'mean'
  3. dict_groupby['Long'] = 'mean'
  4. dict_groupby

例如, 在这里建立的字典最终的结果大致如下.

  1. {...
  2.  '5/9/20': 'sum',
  3.  '5/10/20': 'sum',
  4.  '5/11/20': 'sum',
  5.  'Lat': 'mean',
  6.  'Long': 'mean'}

接着, 我们对每一个table应用上面的dict即可.

  1. # confirmed cases
  2. confirmCountry = confirm.groupby('Country/Region').agg(dict_groupby)
  3. # confirmCountry.drop('Cruise Ship', inplace=True)
  4. confirmCountry.head()

上面就完成了对confirmed这个表格数据各省的合并.

 

生成活跃人数数据集

原始的数据只包含三个最基本的数据集, 也就是确诊人数, 死亡人数和恢复人数. 我们在这里新建一个表, 表示活跃人数, 也就是仍在患病状态的人.

我们记他们为active people, 计算方式为: active=confirmed-death-recovery.

  1. # add active case: confirm-death-recovery
  2. activeCountry = (confirmCountry - deathCountry - recoveredCountry)
  3. activeCountry['Lat'] = -activeCountry.loc[:,'Lat'].values
  4. activeCountry['Long'] = -activeCountry.loc[:,'Long'].values
  5. activeCountry.head()

注意对于经度和纬度需要额外处理一下.

 

新增变量-大洲与ISO3

最后为了可以关联其他变量进行进行分析, 我们在表格中增加新的变量. 也就是与其他的数据集进行融合.

首先我们增加每一个国家所属大洲的信息, 这个信息需要使用python库country_converter, 我们在最开始进行了导入.

  1. import country_converter as coco

就是就是对table的中国家名称进行转换, 转换为所属大洲并在原始表格中新加一列数据.

  1. # add continent
  2. continent_name = coco.convert(names = list(confirmCountry.index.values), to='continent')
  3. # 对每一个表格进行增加
  4. confirmCountry['continent'] = continent_name
  5. deathCountry['continent'] = continent_name
  6. recoveredCountry['continent'] = continent_name
  7. activeCountry['continent'] = continent_name

结果如下图所示, 可以看到新增了continent的内容.

关于Coronavirus数据简单的可视化分析(Plotly的一个例子)

但是我们看到国家名称是在index处的, 于是我们新加一列, 表示国家名称.

  1. # add country name
  2. country_name = confirmCountry.index.values
  3. # 对每一个table进行增加国家名称
  4. confirmCountry['Country/Region'] = country_name
  5. deathCountry['Country/Region'] = country_name
  6. recoveredCountry['Country/Region'] = country_name
  7. activeCountry['Country/Region'] = country_name

接着我们新增每个国家的ISO3短代码, 这是由于在国家名称书写的时候, 可能会存在不一样的情况, 但是每一个国家的ISO3都是确定的. 这也方便了我们之后与其他数据集的合并.

  1. # add country code
  2. confirmCountry['ISO3'] = confirmCountry.apply(lambda x : coco.convert(x['Country/Region'], to='ISO3', not_found=None), axis=1)
  3. deathCountry['ISO3'] = deathCountry.apply(lambda x : coco.convert(x['Country/Region'], to='ISO3', not_found=None), axis=1)
  4. recoveredCountry['ISO3'] = recoveredCountry.apply(lambda x : coco.convert(x['Country/Region'], to='ISO3', not_found=None), axis=1)
  5. activeCountry['ISO3'] = activeCountry.apply(lambda x : coco.convert(x['Country/Region'], to='ISO3', not_found=None), axis=1)

 

数据合并-GPD,Aging,Population

有了上面的ISO3代码之后, 我们就可以与其他数据集进行合并了. 使用到的三个数据集在上面已经进行了介绍, 包括每个国家的人均GDP数据, 每个国家的人口老龄化数据和每个国家的人口数据.

首先我们合并GDP数据, 我们先从数据集中读取数据并保存在一个新的dataframe里面(原始的里面包含每一年的数据, 在这里我们只需要使用最新一年的数据即可).

  1. # --------------------
  2. # combine with GDP
  3. # --------------------
  4. GDP_data = pd.read_csv('/kaggle/input/coronavirus-analysis/GDP/GDP.csv')
  5. # -------------------
  6. # create new table
  7. # ------------------
  8. GDP_2018 = GDP_data.loc[:,['Country Code', '2018']] # 选取需要的字段
  9. GDP_2018.rename(columns={'Country Code':'ISO3', '2018':'GDP_2018'}, inplace=True# 重命名
  10. GDP_2018.dropna(subset=['GDP_2018'], inplace=True# 去除空值
  11. # --------------
  12. # start merge
  13. # -------------
  14. confirmCountry = pd.merge(confirmCountry, GDP_2018, on=['ISO3'])
  15. deathCountry = pd.merge(deathCountry, GDP_2018, on=['ISO3'])
  16. recoveredCountry = pd.merge(recoveredCountry, GDP_2018, on=['ISO3'])
  17. activeCountry = pd.merge(activeCountry, GDP_2018, on=['ISO3'])

其他的合并也是和上面的类似, 我们就不重复进行说明了. 最终, 我们对每一个表格增加了以下的新的变量,

  • 所属大洲, ISO3
  • 这个国家的人均GDP
  • 这个国家的老龄化情况这个国家的人口情况.

最后的表格如下所示.

关于Coronavirus数据简单的可视化分析(Plotly的一个例子)

到这里就完成了基本的数据处理, 下面是基本数据可视化的内容.

 

数据格式的转换

接着我们对上面的数据进行处理, 将段表变为长表格, 这个部分可以查看链接, Melt-dataframe变形. 这种处理的数据是会在动图显示的时候有用到, 其他的分析还是使用上面的数据.

首先对上面四张表的内容各自进行转换, 将其转换为长表.

  1. # 1. confirmed cases
  2. animationCountry = confirmCountry.copycopy()
  3. animationCountry.reset_index(drop=True, inplace=True)
  4. pd1 = pd.melt(animationCountry, id_vars=['Lat', 'Long', 'continent', 'Country/Region', 'ISO3', 'GDP_2018', 'Pop_2018', 'Aging_2018'], var_name = 'date', value_name='Confirmed')
  5. # 2. death cases
  6. animationCountry = deathCountry.copycopy()
  7. animationCountry.reset_index(drop=True, inplace=True)
  8. pd2 = pd.melt(animationCountry, id_vars=['Lat', 'Long', 'continent', 'Country/Region', 'ISO3', 'GDP_2018', 'Pop_2018', 'Aging_2018'], var_name = 'date', value_name='Death')
  9. # 3. recovered cases
  10. animationCountry = recoveredCountry.copycopy()
  11. animationCountry.reset_index(drop=True, inplace=True)
  12. pd3 = pd.melt(animationCountry, id_vars=['Lat', 'Long', 'continent', 'Country/Region', 'ISO3', 'GDP_2018', 'Pop_2018', 'Aging_2018'], var_name = 'date', value_name='Recovered')
  13. # 4. active cases
  14. animationCountry = activeCountry.copycopy()
  15. animationCountry.reset_index(drop=True, inplace=True)
  16. pd4 = pd.melt(animationCountry, id_vars=['Lat', 'Long', 'continent', 'Country/Region', 'ISO3', 'GDP_2018', 'Pop_2018', 'Aging_2018'], var_name = 'date', value_name='Active')

接着对上面的四个表进行merge, 这里会用到一个知识点, 多个表的merge, 具体的说明可以查看链接, 多个dataframe的merge. 在这里, 也就是下面的代码.

  1. # product new dataset
  2. data_frames = [pd1, pd2, pd3, pd4]
  3. df_merged = functools.reduce(lambda left, right: pd.merge(left, right,on=['Lat', 'Long', 'continent', 'Country/Region', 'ISO3', 'GDP_2018', 'Pop_2018', 'Aging_2018', 'date']), data_frames)

接着我们增加两个变量备用, 分别是致死率(death Rate)患病率(Sick Rate). 增加这两个变量是因为我们希望考虑患病人数的时候, 可以考虑这个国家的总人数. 很明显, 如果一个国家的人口越多, 那么得病的人也就会越多.

  1. # add two new variables
  2. df_merged['deathRate'] = df_merged['Death']/df_merged['Confirmed']
  3. df_merged['SickRate'] = df_merged['Confirmed']/df_merged['Pop_2018']
  4. df_merged.head()

最终处理好的数据如下所示, 就全部按照时间进行展开了:

关于Coronavirus数据简单的可视化分析(Plotly的一个例子)

 

关于Coronavirus数据的基础数据可视化

这一部分的目的就是为了我们更好的了解数据. 使用可视化的方式, 帮助我们对数据有更加深刻的理解.

分析总体的变化趋势

首先我们绘制全球的总体的变化趋势, 即每一天活跃人数和确诊人数的变化. 在这里y轴我们使用了log scale, 这是因为后期的数字上升实在是太快了, 为了更好地看出趋势, 我们在这里使用了log scale.

  1. matplotlib.style.use('default')
  2. # Start
  3. fig, ax1 = plt.subplots()
  4. fig.set_size_inches(16, 8)
  5. plt.set_cmap('RdBu')
  6. # plt.xkcd()
  7. # multiple line plot
  8. pos = np.where(confirmCountry.columns.values==latest_date)[0][0]+1 # 找出想画图画到的日期
  9. x = confirmCountry.columns.values[:pos]
  10. lw = 4
  11. a, = ax1.plot(x, confirmCountry.sum().values[:pos], linewidth=lw, label='Confirmed Cases', marker='o') # confirm
  12. b, = ax1.plot(x, activeCountry.sum().values[:pos], linewidth=lw, label='Active Cases', marker='o') # active
  13. plt.legend(handles = [a,b], fontsize=15)
  14. # add Vertical line
  15. ax1.plot(['2/12/20', '2/12/20'], [0, 10000000], lw=3, linestyle='--', alpha=0.7)
  16. ax1.plot(['3/12/20', '3/12/20'], [0, 10000000], lw=3, linestyle='--', alpha=0.7)
  17. ax1.plot([latest_date, latest_date], [0, 10000000], lw=3, linestyle='--', alpha=0.7)
  18. ax1.yaxis.set_tick_params(labelsize=15)
  19. # ax1.set_xticks(x) 
  20. xticks = [i if i in ['1/22/20' ,'2/12/20', '3/12/20', latest_date] else '' for i in x] # x轴几个标记点
  21. ax1.set_xticklabels(xticks, rotation=0, fontsize=15) # x轴设置trick
  22. ax1.set_ylabel("Number of Cases (log)", fontsize='x-large')
  23. ax1.set_xlabel('Date',  fontsize='x-large')
  24. ax1.set_title('Worldwide Corona Virus Cases - Confirmed, Active (Line Chart)', fontsize='x-large')
  25. plt.yscale('log')
  26. # plt.ylabel('logy')
  27. plt.show()

绘制出来的结果如下所示, 可以看到:

  • 从1/22到2/12这段时间, active cases增长迅速
  • 从2/12到3/12号这段时间, active cases出现了缓慢的下降.
  • 但是从3/12开始, 这个数字又开始了快速的上升.
关于Coronavirus数据简单的可视化分析(Plotly的一个例子)

 

对各个大洲进行分析

上面是全球的数据, 我们现在来分析一下各个大洲的数据的变化趋势, 我们这里以active cases作为例子, 其他的图都是类似的.

  1. plotCountry = activeCountry.groupby('continent').sum()
  2. plotCountry.drop(['Lat', 'Long', 'GDP_2018', 'Pop_2018', 'Aging_2018'], axis=1, inplace=True)
  3. plotCountry['continent'] = plotCountry.index.values
  4. matplotlib.style.use('default')
  5. fig, ax1 = plt.subplots()
  6. fig.set_size_inches(16, 8)
  7. plt.set_cmap('RdBu')
  8. x = plotCountry.columns.values[:-1] # 设置日期
  9. lw = 2
  10. for name in plotCountry.index.values:
  11.     ax1.plot(x, plotCountry.loc[name].values[:-1], linewidth=lw, label=name, marker='o', markersize=2.5) # confirm
  12. plt.legend(plotCountry.loc[:,'continent'])
  13. ax1.plot(['2/12/20', '2/12/20'], [0, 1000000], lw=3, linestyle='--', alpha=0.7)
  14. ax1.plot(['3/12/20', '3/12/20'], [0, 1000000], lw=3, linestyle='--', alpha=0.7)
  15. ax1.plot([latest_date, latest_date], [0, 1000000], lw=3, linestyle='--', alpha=0.7)
  16. ax1.yaxis.set_tick_params(labelsize=15)
  17. # ax1.set_xticks(x)
  18. xticks = [i if i in ['1/22/20', '2/12/20', '3/12/20', latest_date] else '' for i in x]
  19. ax1.set_xticklabels(xticks, rotation=0, fontsize=15)
  20. ax1.set_ylabel("Number of Cases (log)", fontsize='x-large')
  21. ax1.set_xlabel('Date',  fontsize='x-large')
  22. ax1.set_title('Active Corona Virus Cases in Each Continent - (Line Chart)', fontsize='x-large')
  23. # set y scale
  24. plt.yscale('log')
  25. plt.show()

最终的结果如下图所示:

关于Coronavirus数据简单的可视化分析(Plotly的一个例子)

可以看到:

  • 绿色的曲线表示亚洲, 一开始亚洲开始上升, 2/12号到达高点之后感染人数开始下降.
  • 欧洲, 美洲人数从2/12开始上升, 并且上升势头强劲.
  • 亚洲在3/12之后感染人数又开始上升.

我们后面在从国家层面分析的时候会解释上面现象出现的原因. 注意这里y轴都是log scale.

关于大洲人数的变化曲线, 我们也可以使用柱状图来表示, 同时做成动态图的形式, 清晰的展现出每个大洲每一天的人数的变化过程. 我们截取其中的一天的结果如下图所示, 这是2020年5月11日每个大洲的active cases的柱状图.

关于Coronavirus数据简单的可视化分析(Plotly的一个例子)

完整的动态图还是从最上面kaggle的主页点击进去查看.

 

对于各个国家的分析

我们分析一下出现上面情况的原因, 我们从每一个国家的数据入手进行查看. 我们会查看每一个国家的confirmed case的变化以及每一个国家的active cases的变化趋势. 这里我们还是以active cases作为示例进行解释.

这里绘图的代码也和上面的相似, 就不在这里重复了, 我们直接看结果 (在结果显示的时候, 我们只显示了人数超过某个特定阈值的国家的情况, 不然把所有的国家都进行可视化会看不清最后的结果).

关于Coronavirus数据简单的可视化分析(Plotly的一个例子)

通过结果, 我们可以解释一下上面各大洲的变化趋势.

  • 一开始, 从亚洲的中国开始, 感染人数迅速上升, 并在2/12号到达顶点
  • 接着从2/12号开始, 欧洲和美洲的国家感染人数开始快速上升, 特别是美国, 可以看到目前感染人数是最多的.
  • 同时, 从3/12号开始, 亚洲其他国家, 例如印度和土耳其, 感染人数也在上升, 导致上面按大洲分析的时候后期亚洲的感染人数再次上升.

 

使用Sunburst Chart显示更多细节

为了更好的显示大洲与国家之间的关系, 我们还绘制了Sunburst Chart, 且可以进行交互. 我们还是使用active case作为例子. 我们只绘制最后一天的数据.

  1. # plot the active case in world wide
  2. fig = px.sunburst(activeCountry, path=['continent', 'Country/Region'], values=latest_date,
  3.                   color='continent',
  4.                   color_continuous_scale='OrRd')
  5. fig.update_layout(title='Worldwide Corona Virus Cases in Each Country and Continent - Active Cases',
  6.                   font=dict(family="Courier New, monospace",
  7.                             size=13)
  8.                  )
  9. fig.update_layout(margin={"r":0,"t":50,"l":0,"b":0})
  10. fig.show()

绘制出的效果如下所示.

关于Coronavirus数据简单的可视化分析(Plotly的一个例子)

且这个图是可以进行交互的, 我们点击一个大洲, 可以看到其中国家详细的信息. 且鼠标放上去可以看到一个国家详细的信息, 例如我们点击欧洲, 鼠标放在挪威上, 可以看到对挪威active case的详细信息.

关于Coronavirus数据简单的可视化分析(Plotly的一个例子)

 

 

结合地图进行可视化

因为我们的数据与地图有关, 所以我们可以将数据与地图进行结合, 使其能够更加直观. 我们首先画出在5/11号这一天全球的active case的分布情况, 我们使用不同颜色代表不同的大洲, 圆圈的大小代表数量的多少.

  1. fig = px.scatter_geo(df_merged[df_merged['date']=='5/11/20'],
  2.                     locations = 'ISO3',
  3.                     size='Active', size_max = 55, color="continent")
  4. fig.update_layout(margin={"r":0,"t":50,"l":0,"b":0})
  5. fig.update_layout(title='Worldwide Corona Virus Cases Time Lapse - Active',
  6.                   font=dict(family="Courier New, monospace",size=13)
  7.                  )
  8. fig.show()

绘制的结果如下图所示, 可以看到美国现在active cases是很多的现在.

关于Coronavirus数据简单的可视化分析(Plotly的一个例子)

同样, 我们也可以将其制作为动态图, 显示每一天的变化. 代码基本是和上面一样的, 就是加上了animation_frame这个参数即可.

  1. fig = px.scatter_geo(df_merged,
  2.                     locations = 'ISO3',
  3.                     size='Active', size_max = 55,
  4.                     animation_frame="date", animation_group='Country/Region',color="continent")
  5. fig.update_layout(margin={"r":0,"t":50,"l":0,"b":0})
  6. fig.update_layout(title='Worldwide Corona Virus Cases Time Lapse - Active',
  7.                   font=dict(family="Courier New, monospace",size=13)
  8.                  )
  9. fig.show()

 

与其他数据集结合分析

上面只用到了Coronavirus的数据, 只是对其进行了简单的可视化, 从而帮助我们了解数据. 接下来, 我们要结合各个国家的GDP, Aging和Population进行分析.

直观分析

我们首先将aging和gdp的与confirm cases的图绘制出来.

  1. px.scatter(confirmCountry, x='GDP_2018', y='Aging_2018',
  2.            color='continent', size=latest_date, size_max=60,
  3.            hover_name="Country/Region", log_x=True)

结果如下所示, 其中x周表示gdp, y轴表示aging, 圆的大小表示每个国家的确诊的人数, 颜色表示所属的大洲.

关于Coronavirus数据简单的可视化分析(Plotly的一个例子)

可以看到右上角的圆的大小比较大, 这个说明在GDP和Aging较大的国家, 确诊的人数也是比较高的. 这有可能是因为冠状病毒对年龄大的人感染力比较强, 同时GDP的国家交通比较便利, 所以传播起来是比较快的.

 

计算相关系数

首先我们计算一下相关系数, 我们计算变量GDP_2018, Pop_2018, Aging_2018, Confirmed, Death, Recovered, Active, deathRate, SickRate之间的相关系数矩阵.

首先将自己要计算的列进行合并, 方便自己之后计算相关系数.

  1. # Correlations for Dataset
  2. correlationM = df_merged[df_merged['date']==latest_date][['GDP_2018','Pop_2018','Aging_2018','Confirmed', 'Death', 'Recovered', 'Active', 'deathRate', 'SickRate']]
  3. correlationM.reset_index(drop=True, inplace=True)
  4. correlationM.head()

接着就直接将计算Pearson correlation coefficient和可视化的部分放在一起了.

  1. # 绘制相关系数矩阵
  2. plt.figure(figsize = (10,10))
  3. ax = sns.heatmap(correlationM.corr(), annot=True, fmt='.1f', cmap="BuPu") # fmt表示保留的小数点
  4. # 设置y轴的字体的大小
  5. plt.yticks(rotation=0) # 让y轴的字进行旋转
  6. # ax.yaxis.set_tick_params(labelsize=15)
  7. plt.title('Correlations for Dataset', fontsize='xx-large')

最后的结果如下所示:

关于Coronavirus数据简单的可视化分析(Plotly的一个例子)

可以看到这里SickRate和GDP会有较大的关系, 我们单独画出他们的图(其实这里会有问题, 因为后面会使用log scale, 但是这里直接使用原始数据进行计算的)

 

简单的线性回归

上面我们从计算相关系数矩阵可以看到, SickRate和GDP之间的相关系数比较大, 于是我们画出这两个变量的散点图.

  1. px.scatter(df_merged[df_merged['date']==latest_date].dropna(subset=['deathRate','SickRate']),
  2.            x='GDP_2018', y='SickRate',
  3.            color='continent', size='Pop_2018', size_max=60,
  4.            hover_name="Country/Region", log_x=True, log_y=True)

结果如下图所示, 可以很明显的看出有一个线性的关系.

关于Coronavirus数据简单的可视化分析(Plotly的一个例子)

再上图中:

  • Each circle represent one country.
  • The x-axis represents the GDP
  • The y-axis represents the SickRate
  • The size of the circle represents the number of confirmed cases.
  • The color represent the continent.

我们接着尝试使用线性回归, 来看一下线性回归最后得到的R^2是多少. 注意我们在这里进行线性回归的时候, 对变量都取了log, 之后画图的时候再求e^n, 这是因为我们在图中使用了log scale.

  1. x = df_merged[df_merged['date']==latest_date].dropna(subset=['deathRate','SickRate'])['GDP_2018'].values.reshape(-1,1)
  2. y = df_merged[df_merged['date']==latest_date].dropna(subset=['deathRate','SickRate'])['SickRate'].values
  3. weight = df_merged[df_merged['date']==latest_date].dropna(subset=['deathRate','SickRate'])['Pop_2018'].values
  4. reg = LinearRegression().fit(np.log(x), np.log(y))
  5. y_pre = reg.predict(np.log(x))
  6. # get prediction
  7. pred_dataframe = pd.DataFrame(x, columns=['x'])
  8. pred_dataframe['y_pred'] = np.e**y_pre

上面完成了拟合和预测, 这里没有训练集和测试集之分.

  1. r2_score(y_true=np.log(y), y_pred=y_pre)

最后的结果如下图所示, R^2=0.54, 可以用.

关于Coronavirus数据简单的可视化分析(Plotly的一个例子)

我们将散点图和拟合的直线画在一起.

  1. fig = go.Figure()
  2. fig = px.scatter(df_merged[df_merged['date']==latest_date].dropna(subset=['deathRate','SickRate']),
  3.            x='GDP_2018', y='SickRate',
  4.            color='continent', size='Pop_2018', size_max=60,
  5.            hover_name="Country/Region", log_x=True, log_y=True)
  6. fig.add_trace(go.Scatter(x=pred_dataframe['x'],
  7.                          y=pred_dataframe['y_pred'],
  8.                          mode='lines',
  9.                          marker_color='rgba(152, 0, 0, .8)',
  10.                          name='Regression'))
  11. fig.update_layout(xaxis_type="log")
  12. fig.show()

从图上看还是有一个大体的趋势的.

关于Coronavirus数据简单的可视化分析(Plotly的一个例子)

其实在原文档里面还有一个对人数的预测的部分, 不过这个部分就是纯粹想让作业多一个部分, 没有什么意义, 所以就不在这里多讲了.

  • 微信公众号
  • 关注微信公众号
  • weinxin
  • QQ群
  • 我们的QQ群号
  • weinxin
王 茂南
  • 本文由 发表于 2020年5月13日07:20:55
  • 转载请务必保留本文链接:https://mathpretty.com/12198.html
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: