I hereby claim:
- I am santiagocasas on github.
- I am santicas (https://keybase.io/santicas) on keybase.
- I have a public key ASADjPQPAhyCIiR2FUo4tPWImOCITahwdNpgr8ulUHrujQo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
Verifying my Blockstack ID is secured with the address 1GjMeGXGmiiqC1kpTHamK46BvDxrexr5AW https://explorer.blockstack.org/address/1GjMeGXGmiiqC1kpTHamK46BvDxrexr5AW |
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
from pandas.plotting import register_matplotlib_converters ##needed to properly use datetime in plots | |
register_matplotlib_converters() ##needed to properly use datetime in plots | |
from datetime import datetime,timedelta | |
from sklearn.metrics import mean_squared_error | |
from scipy.optimize import curve_fit | |
from scipy.optimize import fsolve |
giturl_confirmed = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv' | |
giturl_deaths = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Deaths.csv' | |
giturl_recovered = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Recovered.csv' | |
casestr='Deaths' #'Confirmed' #'Recovered', 'Deaths' | |
chosen_plotmodel = 'Logistic' #'Logistc' | |
if casestr=='Confirmed': | |
curl = giturl_confirmed |
datesformatted = [datetime.strptime(da, '%m/%d/%y') | |
for da in corona_cases_df.columns.values] | |
daterange = pd.DatetimeIndex(datesformatted) | |
daterange | |
>>> | |
DatetimeIndex(['2020-01-22', '2020-01-23', '2020-01-24', '2020-01-25', | |
'2020-01-26', '2020-01-27', '2020-01-28', '2020-01-29', | |
'2020-01-30', '2020-01-31', '2020-02-01', '2020-02-02', | |
'2020-02-03', '2020-02-04', '2020-02-05', '2020-02-06', |
country_official_list = (corona_cases_df.index.get_level_values('Country/Region').values) | |
wanted_countries = ['China', 'Korea','Italy', 'France', 'US'] | |
countries_list = [np.unique(np.array([s for s in country_official_list if cou in s])) | |
for cou in wanted_countries] | |
countries_list = np.array(countries_list).flatten() | |
countries_list.sort() | |
countries_list | |
>>> |
cases_percountry = {} | |
df_dict = {} | |
for country in countries_list: | |
cou = corona_cases_df.loc[pd.IndexSlice[:, country], :].sum() | |
cases_percountry[country] = cou[cou > 0] | |
datesformat = [datetime.strptime(da, '%m/%d/%y') | |
for da in cases_percountry[country].index] | |
df_dict[country] = pd.DataFrame(cases_percountry[country], | |
columns=['Cases'], index=datesformat) |
for country in countries_list: | |
print(country) | |
dates=df_dict[country].index | |
plt.semilogy(dates, np.array(list(df_dict[country]['Cases'].values)), label=country) | |
plt.legend(loc='lower right') | |
plt.tick_params(rotation=45, labelsize=12) | |
plt.ylabel(casestr, fontsize=14) | |
plt.xlim([dates[0]-np.timedelta64(3,'D'), dates[-1]+np.timedelta64(10,'D')]) | |
plt.show() |
def expo_model(x,p,N0=3,x0=1): | |
return N0*(1+p)**(x-x0) | |
def logistic_model(x,a,b,c): | |
return c/(1+np.exp(-(x-b)/a)) | |
def gompertz_model(x,a,b,c): | |
return c*np.exp(-b*np.exp(-x/a)) |
tt= np.linspace(0,100,100) | |
plt.plot(tt, logistic_model(tt,4.8,50,100000), c='b', label='Logisitc') | |
plt.plot(tt, expo_model(tt, 0.23), c='g', label='Exponential') | |
plt.plot(tt, gompertz_model(tt, 12, 49, 100000), c='r', label='Gompertz') | |
plt.legend() | |
plt.xlabel('Time') | |
plt.ylabel('Cases') | |
plt.ylim(-1000,150000) |