<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/can-we-predict-flu-deaths-with-machine-learning-and-r-2/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://datascienceplus.com/can-we-predict-flu-deaths-with-machine-learning-and-r/"> R Programming – DataScience+</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Among the many R packages, there is the outbreaks package. It contains datasets on epidemics, on of which is from the 2013 outbreak of influenza A H7N9 in China, as analysed by <a rel="nofollow" href="http://dx.doi.org/10.5061/dryad.2g43n" target="_blank">Kucharski et al</a> (2014). I will be using their data as an example to test whether we can use Machine Learning algorithms for predicting disease outcome.</p>
<p>To do so, I selected and extracted features from the raw data, including age, days between onset and outcome, gender, whether the patients were hospitalised, etc. Missing values were imputed and different model algorithms were used to predict outcome (death or recovery). The prediction accuracy, sensitivity and specificity. The thus prepared dataset was devided into training and testing subsets. The test subset contained all cases with an unknown outcome. Before I applied the models to the test data, I further split the training data into validation subsets.</p>
<p>The tested modeling algorithms were similarly successful at predicting the outcomes of the validation data. To decide on final classifications, I compared predictions from all models and defined the outcome “Death” or “Recovery” as a function of all models, whereas classifications with a low prediction probability were flagged as “uncertain”. Accounting for this uncertainty led to a 100% correct classification of the validation test set.</p>
<p>The training cases with unknown outcome were then classified based on the same algorithms. From 57 unknown cases, 14 were classified as “Recovery”, 10 as “Death” and 33 as uncertain.</p>
<h2>The data</h2>
<p>The dataset contains case ID, date of onset, date of hospitalisation, date of outcome, gender, age, province and of course the outcome: Death or Recovery. I can already see that there are a couple of missing values in the data, which I will deal with later.</p>
<pre># install and load package
if (!require(&quot;outbreaks&quot;)) install.packages(&quot;outbreaks&quot;)
library(outbreaks)
fluH7N9.china.2013_backup &lt;- fluH7N9.china.2013 # back up original dataset in case something goes awry along the way

# convert ? to NAs
fluH7N9.china.2013$age[which(fluH7N9.china.2013$age == &quot;?&quot;)] &lt;- NA

# create a new column with case ID
fluH7N9.china.2013$case.ID &lt;- paste(&quot;case&quot;, fluH7N9.china.2013$case.ID, sep = &quot;_&quot;)
head(fluH7N9.china.2013)
<em>## case.ID date.of.onset date.of.hospitalisation date.of.outcome outcome gender age province
## 1 case_1 2013-02-19 </em></pre>