This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
import os | |
from glob import glob | |
from PIL import Image | |
import numpy as np |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Utility function to retrieve data from a single country | |
def get_country_df(world_df, country_name): | |
# Some countries have several Provinces/States, must aggregate | |
country_df = world_df[world_df['Country/Region'] == country_name] \ | |
.groupby(["Country/Region", "Date"]) \ | |
.sum() \ | |
.sort_values(by='Date') | |
# Restore columns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Imports for performing ML analysis | |
from sklearn.linear_model import LinearRegression | |
from scipy.optimize import curve_fit | |
from datetime import timedelta | |
# Set range of data to build model | |
# It might make sense to skip part of the initial points, when the exponential trend was still not evident | |
START_DATE = datetime(2020, 2, 23).date() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Estimate a reasonable value for Y tick given the maximum number of cases | |
Y_GRID_TICK = 10**int(np.log10(country_df['Confirmed'].max()))/2 | |
ax = plt.gca() | |
sns.set_style("whitegrid", {'grid.linestyle': ':'}) | |
ax.xaxis.set_major_locator(ticker.MultipleLocator(4)) | |
# Plot | |
country_df.plot(x='Date', y=["Confirmed", "Deaths", "Recovered"], figsize=(18,9), ax=ax, marker='o') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Save the country's name in a variable, so that it can be easily changed to show data | |
# from another country. | |
country_name = "Italy" | |
# Get data for a single country, sorted by date | |
country_df = world_df[world_df['Country/Region'] == country_name].sort_values(by='Date') | |
# Compute daily increase, in absolute number | |
country_df['Increase'] = country_df['Confirmed'].diff() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
csv_files = glob.glob(DATA_DIR + "/*.csv") | |
# Auxiliary function to extract date from file name | |
def extract_date(file_name): | |
date_str = os.path.basename(file_name)[:-4] | |
date = datetime.strptime(date_str, '%m-%d-%Y').date() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git clone https://github.com/CSSEGISandData/COVID-19 | |
cd COVID-19 | |
conda create --name jupyter python=3 matplotlib seaborn \ | |
pandas scikit-learn | |
conda activate jupyter | |
conda install -c conda-forge jupyterlab | |
mkdir notebooks && cd notebooks | |
jupyter lab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Basic imports for path | |
import os, sys, glob | |
# Data loading and | |
import pandas as pd | |
import numpy as np | |
# Plotting | |
import seaborn as sns | |
import matplotlib.pyplot as plt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Module to parse dataset.""" | |
# Imports. | |
import os | |
from os.path import join | |
import glob | |
import pandas as pd | |
from PIL import Image | |
import numpy as np |