COVID-19 Predictions: A Machine Learning and Statistical Approach
By: Karthik Bhaskar
Tags: Artificial Intelligence, Data Science, Covid 19, Machine Learning, Deep Learning

Photo by CDC on Unsplash

Before anything. I’d like to disclose that I’m nowhere near close to an epidemiologist or a doctor. I am a Master’s Student at the University of Toronto working on Deep Learning based Recommendation System. With that said, most of the studies, commentaries, and conclusions in this work are the results of my own experience with machine learning as well as some online articles and some very shallow research on Covid-19 dataset, but most come from basic math and stats knowledge.

These results are not the actual results. I am just posting this to encourage others. I truly believe we can always make better decisions when we have data and appropriate tools on our side. This is my attempt on helping somehow.

Data:

The White House Office of Science and Technology Policy (OSTP) pulled together coalition research groups and companies (including Kaggle) to prepare the COVID-19 Open Research Dataset (CORD-19) to attempt to address key open scientific questions on COVID-19. Those questions are drawn from National Academies of Sciences, Engineering, and Medicine’s (NASEM) and the World Health Organization (WHO).

Link to the dataset: https://www.kaggle.com/c/covid19-global-forecasting-week-1

Machine Learning Approach

Load the necessary resources and data.

Loading Data and Resources

The following code snippet allows us to see the spread of Covid-19 worldwide in real number and log-scaled values.

Snippets for plotting real-valued and log-scaled spread of Covid-19

By running the above snippets on the dataset. We get the following graphs:

Results of Covid-19 Spread across worldwide

From the chart above, we can clearly see the exponential trend of the disease, and we can also see that the spread seemed to be slowing down a big at the beginning of March until it began accelerating again, as can be seen in the semi-logarithmic chart on the right.

In the real world, true exponentials do not exist. The important thing when trying to understand the development of the disease is to understand if we are past or behind the inflection point. The inflection point is the point right in the middle of the logistic curve, where the disease will start slowing down until it reaches full stop.

The Growth Factor is the ratio between the number of cases one day and the number of cases in the previous day. It shows us if the disease is growing or not.

Growth Factor = 1 (Number of cases isn’t growing) => Inflection Point Growth Factor < 1 (Number of cases decreasing) Growth Factor > 1 (Number of cases increasing)

Now, we plot the Growth Factor of the Covid-19 disease using the following code snippet.

Growth Factor Code Snippet

Growth Factor for Covid-19

We can see in the chart that at mid February we were very close to being at the point of inflection but after that we can see that the trend is going up.

Simple Baseline: Linear Regression

x = np.arange(0, len(global_cases)).reshape(-1, 1)

y = np.log(global_cases.values)



model = LinearRegression().fit(x, y)



print('R-Squared: %s' % model.score(x, y))

Based on the logarithmic scale of the number of cases we are able to fit a linear regression pretty well with a R-Squared of 0.7704062276422439.

Plot the predictions of Linear Regression

Predictions of Covid19

As you can see this is a result of simple baseline, we can also use Random Forest or any other regression type model to predict. In the following code snippet, I am using Random Forest model, to predict the future trend of the spread of Covid-19 disease.

x_2 = np.arange(0, 79).reshape(-1, 1) # Random Forest Model

predictions_rf = rf_model.predict(x_2) #Future Predictions

first_date = pd.to_datetime(min(global_cases.index))

last_date = (first_date + timedelta(days=78)).strftime('%Y-%m-%d')

first_date = first_date.strftime('%Y-%m-%d')

index = pd.date_range(first_date, last_date) #Linear Random Forest Predictions in upcoming months fig, ax = plt.subplots(figsize=(10, 4))



sns.lineplot(x=index, y=predictions_lr, linewidth=3)



sns.despine(top=True, left=True)



ax.grid(axis='both', alpha=.2)



every_nth = 2

for n, label in enumerate(ax.xaxis.get_ticklabels()):

if n % every_nth != 0:

label.set_visible(False)



ax.tick_params(axis='both', which='both', bottom=False, left=False)





plt.show()

Random Forest Model — Covid-19 Prediction of upcoming weeks

The linear regression and random forest model predicts that in 20 days we’ll have almost 1.7 million people infected. This is obviously a very simple linear regression and random forest model using some very basic data. We could surely do a much better job using other features like, total population, infection probability etc. The model also doesn’t take into consideration the measures taken by governments to reduce the spread of the infection and obviously it also doesn’t take into account the development of medicine and vaccination.

Statistical Approach:

Reimplemented the model proposed by researchers from TU Eindhoven in my Github repository. They proposed to fit a simple sigmoid function to each of the measurements of a country:

E(Y_t) = M / (1 + exp (-𝛽 ( t — 𝛼 ) )

with M the maximal number of cases, 𝛼 the number of days at which the expected number of counts is half way the maximum,and 𝛽 > 0 the growth parameter.

Special caution should be taken with exponential models such as these Sigmoid based models. I am not saying that this is the ideal approach.

Here is the link for the research paper and the code that I implemented. Please take a look at it, if you want to understand the approach. The statistical approach results are as follows:

Statistical Approach: Covid-19 Spread in different countries like France and Canad

From the statistical approach, we can clearly see a steep rise in the number of Covid-19 cases in the upcoming weeks. Again these are not the actual results.

Stay Safe and Stay Indoors.

Thanks for Reading!

Reference: