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()
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()
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()
countries = country_data['country'].unique()
print(f'{len(countries)} countries are in dataset:\n{countries}')
# 条形图的绘制--垂直条形图
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)
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()
根据历史经验,2003年非典患者预测,部分学者利用逻辑斯蒂增长模型进行预测,并且准确率很高,所以我也尝试利用逻辑斯蒂增长模型进行新型冠状病毒患者数量,逻辑斯蒂增长模型具体为:
(其中K为环境最大容量,P0为初始容量,r为增长速率,r越大则增长越快(即更快的逼近上限)。)
补充:遇到GitHub中ipynb文件打不开,可将github文件复制到
https://nbviewer.jupyter.org/ 进行打开