新冠肺炎的可视化和预测分析(附代码)
新冠肺炎現在情況怎么樣了?推薦一份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型擬合進行預測
全球趨勢
fig = px.line(ww_melt_df, x="date", y="value", color='variable', title="Worldwide Confirmed/Death Cases Over Time") fig.show()世界確診和死亡數
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()世界確診和死亡數(取對數)
國家(地區)增長
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()確診數和死亡數
死亡最多的國家
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()死亡率最高的國家
省份情況
出現新冠肺炎的主要國家的各省(州)的清單
放大美國:現在美國正在發生什么?
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()美國的死亡率情況
美國各州的確診數
歐洲
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()歐洲確診數
亞洲
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()亞洲確診數
亞洲每日確診數量
現在哪個國家正在復蘇?
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擬合進行預測
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
往期精彩回顧適合初學者入門人工智能的路線及資料下載機器學習在線手冊深度學習在線手冊AI基礎下載(pdf更新到25集)本站qq群1003271085,加入微信群請回復“加群”獲取一折本站知識星球優惠券,復制鏈接直接打開:https://t.zsxq.com/yFQV7am喜歡文章,點個在看
總結
以上是生活随笔為你收集整理的新冠肺炎的可视化和预测分析(附代码)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【实战】用机器学习来提升你的用户增长(二
- 下一篇: 特征锦囊:怎么批量把特征中的离群点给处理