{"id":4670,"date":"2020-05-08T15:32:26","date_gmt":"2020-05-08T13:32:26","guid":{"rendered":"https:\/\/www.codemotion.com\/magazine\/?p=4670"},"modified":"2022-01-05T20:04:56","modified_gmt":"2022-01-05T19:04:56","slug":"epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus","status":"publish","type":"post","link":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\/","title":{"rendered":"Epidemic Intelligence, part 2: data, models and machine learning in the age of Coronavirus"},"content":{"rendered":"\t\t\t\t<div class=\"wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-493e6e06      \"\n\t\t\t\t\tdata-scroll= \"1\"\n\t\t\t\t\tdata-offset= \"30\"\n\t\t\t\t\tstyle=\"\"\n\t\t\t\t>\n\t\t\t\t<div class=\"uagb-toc__wrap\">\n\t\t\t\t\t\t<div class=\"uagb-toc__title\">\n\t\t\t\t\t\t\tTable Of Contents\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"uagb-toc__list-wrap \">\n\t\t\t\t\t\t<ol class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#non-parametric-models\" class=\"uagb-toc-link__trigger\">Non-parametric models<\/a><li class=\"uagb-toc__list\"><a href=\"#neural-networks-come-into-play\" class=\"uagb-toc-link__trigger\">Neural networks come into play<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#codemotion-online-tech-conferenceshaping-the-future-with-deep-learning\" class=\"uagb-toc-link__trigger\">Codemotion Online Tech ConferenceShaping the Future with Deep Learning<\/a><\/li><\/ul><\/li><li class=\"uagb-toc__list\"><a href=\"#setting-up-a-recurrent-lstm-network\" class=\"uagb-toc-link__trigger\">Setting up a recurrent LSTM network<\/a><li class=\"uagb-toc__list\"><a href=\"#a-bit-of-time-series-lore\" class=\"uagb-toc-link__trigger\">A bit of time series lore<\/a><li class=\"uagb-toc__list\"><a href=\"#conclusions\" class=\"uagb-toc-link__trigger\">Conclusions<\/a><\/ul><\/ol>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\n\n\n<p>In a <a href=\"https:\/\/www.codemotion.com\/magazine\/dev-hub\/machine-learning-dev\/epidemic-intelligence-data-models-and-machine-learning-in-the-age-of-coronavirus\/\" class=\"ek-link\">previous article<\/a>, we shared some reflections on <strong><span id=\"urn:local-annotation-227459\" class=\"textannotation disambiguated\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/machine_learning\">machine learning<\/span><\/strong> <strong>models for <span id=\"urn:enhancement-bd7a1aca\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> <span id=\"urn:enhancement-d8055e12\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/curve_fitting\">fitting<\/span> and <span id=\"urn:enhancement-4e036169\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">prediction<\/span><\/strong>, playing with a simple <span id=\"urn:enhancement-61e9d0a6\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data_set\">dataset<\/span> related to the spread of the  current <span id=\"urn:enhancement-c07bfbd4\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/coronavirus\">coronavirus<\/span> <span id=\"urn:enhancement-38639685\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/emergency\">emergency<\/span>. We looked at simple models and mentioned some more advanced ideas that rely upon <span id=\"urn:enhancement-1600e4cb\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/determinism\">deterministic<\/span> dynamical system theory to be properly understood. However, that article was  limited to so-called <em><span id=\"urn:enhancement-d8dac8f0\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/parametric_statistics\">parametric<\/span> models<\/em>, which try to fit and <span id=\"urn:enhancement-10218e53\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">predict<\/span> <span id=\"urn:enhancement-a4846e2b\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> by using a known parametrized function with a fixed number of <span id=\"urn:enhancement-3c85b1d6\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/parameter\">parameters<\/span>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Non-parametric models<\/h2>\n\n\n\n<p>For example, we considered an <span id=\"urn:enhancement-3167df28\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/exponential_function\">exponential<\/span> function that transforms an input signal <em>x<\/em> into an output signal <em>a <span id=\"urn:enhancement-55b22ff1\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/exponential_function\"><\/span><\/em>exp(<em>bx<\/em>) with <em>a<\/em>, <em>b <span id=\"urn:enhancement-bf09235c\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/parameter\"><\/span><\/em>parameters to be determined to <span id=\"urn:enhancement-6e7757df\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/curve_fitting\">best fit<\/span> the training <span id=\"urn:enhancement-151c11d6\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span>. The merits of this approach are that it is simple to implement, since it requires only an optimizer, and there are usually very few <span id=\"urn:enhancement-e6a88c58\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/parameter\">parameters<\/span>. Moreover, this is a <strong>white-box <span id=\"urn:enhancement-507f9d48\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span><\/strong>: we know the function &#8211; after all, we chose it! &#8211; so we have plenty of theoretical tools available to justify its use, assess <span id=\"urn:enhancement-492f39c7\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/errors_and_residuals_in_statistics\">errors<\/span>, and so on. We can also try to modify the function (as we did with the logistic example previously), with the knowledge, more or less, of what we are doing.<\/p>\n\n\n\n<p>On the other hand, a <strong>non-<span id=\"urn:enhancement-e3375669\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/parametric_statistics\">parametric<\/span> <span id=\"urn:enhancement-e7d9dde5\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span><\/strong> is just a <strong>black box<\/strong> which accepts signal <em>x<\/em> and emits another signal &#8211; <em>y<\/em> &#8211; according to some inner rule that is dependent on numerous <span id=\"urn:enhancement-75b1f1c7\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/parameter\">parameters<\/span> hidden within the <span id=\"urn:enhancement-1051ee98\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span>, whose interpretation is largely unknown. We cannot modify the <span id=\"urn:enhancement-56e0bc8\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> and its <span id=\"urn:enhancement-4cbdab98\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/parameter\">parameters<\/span> &#8211; usually much more numerous than in a <span id=\"urn:enhancement-83b9bf28\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/parametric_statistics\">parametric<\/span> <span id=\"urn:enhancement-c50807cf\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> &#8211; are tuned inside the black box. We have some external <span id=\"urn:enhancement-3e78790\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/parameter\">parameters<\/span> (known as &#8216;hyper-<span id=\"urn:enhancement-cfccfd2f\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/parameter\">parameters<\/span>) that are within our control, but their tuning is totally empirical, since the black-box nature of the <span id=\"urn:enhancement-142481fd\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> means that we cannot even form hypotheses with any degree of certainty.<\/p>\n\n\n\n<p>Put this way it seems that such <span id=\"urn:enhancement-7deaec02\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/scientific_modelling\">models<\/span> are difficult to deal with and frustrating to <span id=\"urn:enhancement-726c4c7d\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/calibration\">calibrate<\/span>. That is undoubtedly true, but they are also often very effective, in some cases amazingly so. Most readers will already have guessed: <strong>artificial neural networks<\/strong> belong to this family of <span id=\"urn:enhancement-f190db5f\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/scientific_modelling\">models<\/span>.<\/p>\n\n\n\n<p>In what follows we will play with some neural networks to analyse a simple <span id=\"urn:enhancement-f706f3c1\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data_set\">dataset<\/span> relating to the spread of COVID-19 in the state of New York, with the hope of gaining some insight into how these <span id=\"urn:enhancement-7bec72b2\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">models<\/span> should be applied and what can be expected from them. The <span id=\"urn:enhancement-2b1e2b2a\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/python_programming_language\">Python<\/span> snippets used below are by no means perfect, but nonetheless mediate between the use of library <span id=\"urn:enhancement-71fb11e7\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/method_computer_programming\">methods<\/span> and, wherever possible, demonstrating what happens &#8216;behind the scenes&#8217; by doing some <span id=\"urn:enhancement-33f99013\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/computation\">computation<\/span> by hand.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Neural networks come into play<\/h2>\n\n\n\n<p>As we will consider neural networks in the light of black boxes, to a certain extent we may ignore their inner <span id=\"urn:enhancement-eb98a0f8\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/structure\">structure<\/span> and look at them as algorithms. These networks take a numeric input vector and provide another numeric vector as output, sometimes as minimal as a single number. In this case the network defines a function <em>y <\/em>= <em>f<\/em>(<em>x<\/em><sub>1<\/sub>,&#8230;,<em>x<sub>n<\/sub><\/em>), but notice that this function needs to be built based on a <strong><span id=\"urn:enhancement-d39cb434\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/training_set\">training set<\/span><\/strong>.<\/p>\n\n\n\n<p>A <span id=\"urn:enhancement-bceb251d\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/training_set\">training set<\/span> contains <span id=\"urn:enhancement-73bad457\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> of the same format. For a function <em>y <\/em>= <em>f<\/em>(<em>x<\/em><sub>1<\/sub>,&#8230;,<em>x<sub>n<\/sub><\/em>), the <span id=\"urn:enhancement-67256118\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/training_set\">training set<\/span> is a set of pairs, called <em>samples<\/em>, (<em>y<\/em><sub>1<\/sub>,(<em>x<\/em><sub>11<\/sub>,&#8230;,<em>x<\/em><sub>1<\/sub><em><sub>n<\/sub><\/em>)),&#8230;,(<em>y<sub>m<\/sub><\/em>,(<em>x<sub>m<\/sub><\/em><sub>1<\/sub>,&#8230;,<em>x<sub>mn<\/sub><\/em>)) which are used to <span id=\"urn:enhancement-80c8fa2\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/calibration\">calibrate<\/span> the function so that <em>y<\/em><sub>1<\/sub>=<em>f<\/em>(<em>x<\/em><sub>11<\/sub>,&#8230;,<em>x<\/em><sub>1<\/sub><em><sub>n<\/sub><\/em>),&#8230;,<em>y<sub>m<\/sub><\/em>=<em>f<\/em>(<em>x<sub>m<\/sub><\/em><sub>1<\/sub>,&#8230;,<em>x<sub>mn<\/sub><\/em>). Notice that numbers <em>x<sub>ij<\/sub> <\/em>depend on two indexes: when dealing with neural networks be prepared to handle variables dependent on up to three indexes (improperly called <em><span id=\"urn:enhancement-45d3cb22\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/tensor\">tensors<\/span><\/em>, even if we ignore their coordinate <span id=\"urn:enhancement-3ed50753\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/rule_of_inference\">transformation rules<\/span>).<\/p>\n\n\n\n<p>A neural network has <strong>hidden <span id=\"urn:enhancement-b5214115\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/parameter\">parameters<\/span><\/strong> (called <strong>weights<\/strong>) which are changed each time a record of the training set fails an <span id=\"urn:enhancement-cb92f563\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/evaluation\">evaluation<\/span>, in order to make corrections that enable the next evaluation to provide the desired result. Thus <strong>the network &#8216;learns&#8217; the function<\/strong> values on the <span id=\"urn:enhancement-b18b00a2\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/training_set\">training set<\/span>. More precisely, one might say say that the function has to fit the <span id=\"urn:enhancement-773301f4\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/training_set\">training set<\/span> the best it can, and indeed neural networks can do this better than most other <span id=\"urn:enhancement-4de4fcf9\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/approximation\">approximation<\/span> and <span id=\"urn:enhancement-3d526b3f\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/interpolation\">interpolation<\/span> algorithms.<\/p>\n\n\n\n<p>The function that our neural network should learn here is the curve of cases and\/or the curve of deaths. However, it is not immediately able to do that, even though <strong>Neural networks are great at <span id=\"urn:enhancement-a6bbbebd\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/interpolation\">interpolating<\/span> functions in order to <span id=\"urn:enhancement-1f50e658\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/curve_fitting\">fit<\/span> known <span id=\"urn:enhancement-d54906b8\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> and approximate unknown <span id=\"urn:enhancement-59bd3043\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span><\/strong>. In our case, known <span id=\"urn:enhancement-e79225\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> are all cases diagnosed up until the present day, while unknown <span id=\"urn:enhancement-bd577e15\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> are all cases that will be diagnosed in the future. We are not interested in the curve between today and yesterday, so we are not interested in <span id=\"urn:enhancement-6a1d7113\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/interpolation\">interpolating<\/span> the curve but just in extrapolating from it.<\/p>\n\n\n\n<p>Usually the function <em>y <\/em>= <em>f<\/em>(<em>x<\/em><sub>1<\/sub>,&#8230;,<em>x<sub>n<\/sub><\/em>) a neural network needs to <span id=\"urn:enhancement-2555c99f\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/interpolation\">interpolate<\/span> depends on <span id=\"urn:enhancement-d361d792\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> which have no particular order: thus  <em>x<\/em><sub>1<\/sub>,&#8230;,<em>x<sub>n<\/sub><\/em> are seen simply as coordinates of a <span id=\"urn:enhancement-6c9bd23c\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/point_geometry\">point<\/span> in some multi-dimensional space, and the proximity relationships (such as their distances) are taken into account. But when <strong>dealing with time series, time ordering is essential<\/strong>.<\/p>\n\n\n\n<p>A &#8216;traditional&#8217; <strong>neural network is just a set of parallel layers<\/strong> that contains the network nodes (called <em>neurons<\/em>), which in turn contain network weights. Neurons are connected so that information passes from one <span id=\"urn:enhancement-f642aff4\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/abstraction_layer\">layer<\/span> through to the next, starting from the input <span id=\"urn:enhancement-975166b1\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/abstraction_layer\">layer<\/span> and ending with the output <span id=\"urn:enhancement-71a6f982\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/abstraction_layer\">layer<\/span>. The actual output is compared with the output expected from the training <span id=\"urn:enhancement-87484041\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span>, and <span id=\"urn:enhancement-8cd3c23\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/weight_function\">weights<\/span> inside nodes are adjusted by a <span id=\"urn:enhancement-f93feb37\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/rule_of_inference\">rule<\/span> called &#8216;backpropagation&#8217; (or a variant thereof). After each layer-passing process is completed, <span id=\"urn:enhancement-69db02f9\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/weight_function\">weights<\/span> are changed and their previous values are discarded, with the result that <span id=\"urn:enhancement-b548345d\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/weight_function\">weights<\/span> &#8216;have no memory&#8217;.<\/p>\n\n\n\n<p>A class of neural networks called <strong>recurrent networks<\/strong> has been devised since the 1980s to deal with time series. In a <span id=\"urn:enhancement-b135c74c\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/recurrent_neural_network\">recurrent<\/span> network, some neurons are connected with themselves, consequently their output is also part of their input. This <span id=\"urn:enhancement-fd55091a\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/logical_consequence\">implies<\/span> that these special networks &#8216;remember&#8217; <span id=\"urn:enhancement-ff752890\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> that have previously passed through the network. This is an oversimplified and <span id=\"urn:enhancement-f655d37f\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/qualitative_property\">qualitative<\/span> description but will suffice for our purposes. To learn more about this, read this excellent <a aria-label=\"good article by Stephen Grossberg on Scholarpedia (opens in a new tab)\" href=\"http:\/\/www.scholarpedia.org\/article\/Recurrent_neural_networks\" target=\"_blank\" rel=\"noreferrer noopener nofollow\" class=\"ek-link\">article by Stephen Grossberg on Scholarpedia<\/a>.<\/p>\n\n\n\n<p>There are several kinds of recurrent networks but the focus here is applying them to our problem in the form of <strong>black boxes<\/strong>. In order to do that we need to first deal with issues related to available <span style=\"user-select: auto;\" id=\"urn:enhancement-f025dac2\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span>.<\/p>\n\n\n\n<div class=\"uagb-cta__outer-wrap uagb-block-49dfed01\"><div class=\"uagb-cta__content-wrap uagb-cta__block uagb-cta__icon-position-right uagb-cta__content-right uagb-cta__content-stacked-tablet uagb-cta__button-valign-middle \"><div class=\"uagb-cta__left-right-wrap\"><div class=\"uagb-cta__content\"><div class=\"uagb-cta__title-wrap\"><h3 class=\"uagb-cta__title\">Codemotion Online Tech Conference<br>Shaping the Future with Deep Learning<\/h3><\/div><div class=\"uagb-cta-text-wrap\"><p class=\"uagb-cta__desc\">The impact of AI on our lives is already tangible and it is destined to grow exponentially. From Healthcare to Finance, from Marketing to Manufacturing, these and many more fields are experiencing a fast-paced revolution. <br><br>On May 27, join our free online event to learn from some of the most prominent DL experts in the world how you can play your own part in this monumental change.<\/p><\/div><\/div><div class=\"uagb-cta__link-wrapper uagb-cta__block-link-style\"><div class=\"uagb-cta__button-wrapper\"><a href=\"https:\/\/bit.ly\/2YfTgUz\" class=\"uagb-cta__button-link-wrapper uagb-cta__block-link uagb-cta-typeof-button\" target=\"_blank\" rel=\"noopener noreferrer\"><span class=\"uagb-cta__link-content-inner\"><span>JOIN FOR FREE<\/span><\/span><\/a><\/div><\/div><\/div><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Setting up a recurrent LSTM network<\/h2>\n\n\n\n<p>As in the <a href=\"https:\/\/www.codemotion.com\/magazine\/dev-hub\/machine-learning-dev\/epidemic-intelligence-data-models-and-machine-learning-in-the-age-of-coronavirus\/\" class=\"ek-link\">previous article<\/a> of this series, I will use a time series maintained by <span id=\"urn:enhancement-ffc9d7a8\" class=\"textannotation disambiguated wl-organization\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/the_new_york_times\">The New York Times<\/span>, with data based on reports from state and local health agencies (see <a href=\"https:\/\/www.nytimes.com\/interactive\/2020\/us\/coronavirus-us-cases.html\" class=\"ek-link\">this link<\/a>).<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">from git import Repo\nimport matplotlib.pyplot <span class=\"hljs-keyword\">as<\/span> plt\nimport numpy <span class=\"hljs-keyword\">as<\/span> np\nfrom os.path import join\nfrom pandas import read_csv\nfrom shutil import rmtree\nfrom tempfile import mkdtemp\n \n<span class=\"hljs-comment\"># Get data from github repository<\/span>\ntempdir = mkdtemp()\nrepo = Repo.clone_from(<span class=\"hljs-string\">\"https:\/\/github.com\/nytimes\/covid-19-data\"<\/span>, tempdir, branch=<span class=\"hljs-string\">\"master\"<\/span>, depth=<span class=\"hljs-number\">1<\/span>)\nwith open(join(tempdir, <span class=\"hljs-string\">\"us-states.csv\"<\/span>)) <span class=\"hljs-keyword\">as<\/span> cf:\n    DATA = read_csv(cf)\n<span class=\"hljs-keyword\">try<\/span>:\n    rmtree(tempdir)  <span class=\"hljs-comment\"># this may fail due to grant limitations...<\/span>\nexcept:\n    pass\n \n<span class=\"hljs-comment\">#Filter data we are interested in<\/span>\nNY_DATA = DATA.loc&#91;DATA.state == <span class=\"hljs-string\">\"New York\"<\/span>, &#91;<span class=\"hljs-string\">\"cases\"<\/span>, <span class=\"hljs-string\">\"deaths\"<\/span>]]\nCASES = np.<span class=\"hljs-keyword\">array<\/span>(NY_DATA.loc&#91;:, <span class=\"hljs-string\">\"cases\"<\/span>])\nDEATHS = np.<span class=\"hljs-keyword\">array<\/span>(NY_DATA.loc&#91;:, <span class=\"hljs-string\">\"deaths\"<\/span>])\n \n<span class=\"hljs-comment\"># Plot the data<\/span>\nfig, axes = plt.subplots(<span class=\"hljs-number\">2<\/span>, <span class=\"hljs-number\">2<\/span>, figsize=(<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">5<\/span>))\naxes&#91;<span class=\"hljs-number\">0<\/span>,<span class=\"hljs-number\">0<\/span>].plot(CASES, <span class=\"hljs-string\">\"r+\"<\/span>, label=<span class=\"hljs-string\">\"Cases: data\"<\/span>)\naxes&#91;<span class=\"hljs-number\">0<\/span>,<span class=\"hljs-number\">1<\/span>].plot(DEATHS, <span class=\"hljs-string\">\"k+\"<\/span>, label=<span class=\"hljs-string\">\"Deaths: data\"<\/span>)\naxes&#91;<span class=\"hljs-number\">0<\/span>,<span class=\"hljs-number\">0<\/span>].legend()\naxes&#91;<span class=\"hljs-number\">0<\/span>,<span class=\"hljs-number\">1<\/span>].legend()\naxes&#91;<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-number\">0<\/span>].hist(CASES)\naxes&#91;<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-number\">1<\/span>].hist(DEATHS)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"303\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image6-1.png\" alt=\"\" class=\"wp-image-4677\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image6-1.png 624w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image6-1-300x146.png 300w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/figure><\/div>\n\n\n\n<p>There are two time series provided with these <span id=\"urn:enhancement-64b85875\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span>: the time series of COVID-19 cases (officially diagnised cases &#8211; a number usually far removed from the real number of cases and difficult to correlate to the true statistics) and the time series of deaths in which COVID-19 is the proven cause.<\/p>\n\n\n\n<p>Since we want to use a neural network we need a training set. However, at the moment we only have a time series. If the aim is to predict, the time series may be used to provide a training set as follows: assume we have a time series <em>s<\/em><sub>0<\/sub>,&#8230;,<em>s<sub>N<\/sub> <\/em>, being <em>s<sub>i<\/sub><\/em> numbers detected at times <em>i<\/em>=0,2,&#8230;,<em>N<\/em>. If we assume that the series is such that the next value depends only on the previous value (Markov hypothesis) then the prediction of <em>s<sub>i<\/sub><\/em><sub>+1<\/sub> is just a function of <em>s<sub>i<\/sub><\/em>, so the function that needs to be learnt is <em>y <\/em>= <em>f<\/em>(<em>x<\/em>) such that <em>s<sub>i<\/sub><\/em><sub>+1<\/sub> = <em>f<\/em>(<em>s<sub>i<\/sub><\/em>) for <em>i <\/em>= 0,&#8230;,<em>N<\/em>\u22121.<\/p>\n\n\n\n<p>Therefore, our training data can be set up as (<em>s<\/em><sub>1<\/sub>,<em>s<\/em><sub>0<\/sub>),(<em>s<\/em><sub>2<\/sub>,<em>s<\/em><sub>1<\/sub>),&#8230;,(<em>s<sub>N<\/sub><\/em>,<em>s<sub>N<\/sub><\/em><sub>\u22121<\/sub>). This can be done even if the output <em>y <\/em>is a vector rather than a single number. &#8216;Multivariate&#8217; time series prediction is usually much harder than its &#8216;univariate&#8217; equivalent, but this is not the case when using neural networks. In fact, there&#8217;s not much difference between the methods &#8211; both work in the same way &#8211; and in any case, the univariate option fits the purpose of this article.<\/p>\n\n\n\n<p>Of course one could model more complex dependencies of the next value on those that precede it. For example, suppose we were to decide that the next value depended on the previous three values. In this situation, the function being modelled takes the form <em>y <\/em>= <em>f<\/em>(<em>x<\/em><sub>1<\/sub>,<em>x<\/em><sub>2<\/sub>,<em>x<\/em><sub>3<\/sub>) and the training set becomes<\/p>\n\n\n\n<p class=\"has-text-align-center\"><em>(s<sub>3<\/sub>,(s<sub>0<\/sub>,s<sub>1<\/sub>,s<sub>2<\/sub>)),(s<sub>4<\/sub>,(s<sub>1<\/sub>,s<sub>2<\/sub>,s<sub>3<\/sub>)),&#8230;(s<sub>N<\/sub>,(s<sub>N\u22123<\/sub>,s<sub>N\u22122<\/sub>,s<sub>N\u22121<\/sub>))<\/em><\/p>\n\n\n\n<p>The size of the input vector is called a <em>step<\/em> in this context. The previous example shows a three time-steps input, a one time-step output and a one step prediction. In general, the more steps used, the fewer samples can be arranged in the training set.<\/p>\n\n\n\n<p>It is not difficult to write a code that will produce such samples from a single series. In the first example we will consider one time-step input. In the following script I download data and prepare training sets as previously described, plotting both series and their histograms.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># We use this function to produce training data with given input step (output step=1)<\/span>\ndef extract_sample(series):\n    X = &#91;]\n    Y = &#91;]\n    <span class=\"hljs-keyword\">for<\/span> i in range(len(series)<span class=\"hljs-number\">-1<\/span>):\n        X.append(series&#91;i:i+<span class=\"hljs-number\">1<\/span>])\n        Y.append(series&#91;i+<span class=\"hljs-number\">1<\/span>])\n    <span class=\"hljs-keyword\">return<\/span> X, Y\n \n<span class=\"hljs-comment\"># Training sets for both series: we separate input (x) from output (y) data<\/span>\nX_CASES, Y_CASES = extract_sample(CASES)\nX_DEATHS, Y_DEATHS = extract_sample(DEATHS)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Now we have a training set, but we still need a model. There are many recurrent networks which may be used, but here we&#8217;ll use a classic model &#8211; the so-called <strong>LSTM<\/strong> (<em>Long-Short Term Model<\/em>). Dating back to 1997, this model is still a good choice in many cases (for example in <a href=\"https:\/\/www.codemotion.com\/magazine\/dev-hub\/machine-learning-dev\/bert-how-google-changed-nlp-and-how-to-benefit-from-this\/\" class=\"ek-link\"><span id=\"urn:local-annotation-259369\" class=\"textannotation disambiguated\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/natural_language_processing\">natural language processing<\/span><\/a>). The LTSM&#8217;s most striking feature is that some of the inner nodes of the network (nodes contain one or more weights) are used as network &#8216;memory&#8217; rather than for computational purposes.<\/p>\n\n\n\n<p>I won&#8217;t indulge in theoretical detail here, but will take the point of view of a developer and notice that <strong>this model is available for our use in the Keras Python library<\/strong>. In a momentit will be clear that taking this approach requires a bit of data preprocessing and the setting of a few parameters.<\/p>\n\n\n\n<p>Let&#8217;s start with the simplest case &#8211; a <strong>one-layer LSTM<\/strong>. It is more or less straightforward to <strong>design the model using Keras API<\/strong>, setting some external parameters to standard values and setting hyper-parameters through trial and error. Such parameters include the number of nodes, the number of epochs and the batch size. The model is compiled by using the Keras backend &#8211; either Theano or TensorFlow &#8211; and can then be used to train data via the <code>fit<\/code> method. Eventually the model can be used (and tested) using the <code>predict<\/code> method.<\/p>\n\n\n\n<p>We will use 80% of our sample as training samples, and the remaining data as test samples, and will concentrate on predicting deaths.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">from keras.models import Sequential\nfrom keras.layers import Dense\nfrom keras.layers import LSTM\n \ndef train_test(neural_network, X, Y, epochs=<span class=\"hljs-number\">5000<\/span>, training_percent_size = <span class=\"hljs-number\">0.8<\/span>):\n    <span class=\"hljs-comment\"># This function takes a dataset, splits it into training and testing sets<\/span>\n    <span class=\"hljs-comment\"># according to training_percent_size, trains a plain LSTM model on it<\/span>\n    <span class=\"hljs-comment\"># launches preditions on datasets, and plots the result.<\/span>\n    N = len(X)\n    <span class=\"hljs-comment\"># Extract training and testing samples and convert in numpy arrays<\/span>\n    n_training = int(N*training_percent_size)\n    X_TRAINING, Y_TRAINING = np.<span class=\"hljs-keyword\">array<\/span>(X&#91;:n_training]), np.<span class=\"hljs-keyword\">array<\/span>(Y&#91;:n_training])\n    X_TESTING, Y_TESTING = np.<span class=\"hljs-keyword\">array<\/span>(X&#91;n_training:]), np.<span class=\"hljs-keyword\">array<\/span>(Y&#91;n_training:])\n    <span class=\"hljs-comment\"># neural_network.fit expect a (samples, input-steps, output-steps) shaped X array<\/span>\n    X_TRAINING = X_TRAINING.reshape((X_TRAINING.shape&#91;<span class=\"hljs-number\">0<\/span>], X_TRAINING.shape&#91;<span class=\"hljs-number\">1<\/span>], <span class=\"hljs-number\">1<\/span>))\n    X_TESTING = X_TESTING.reshape((X_TESTING.shape&#91;<span class=\"hljs-number\">0<\/span>], X_TESTING.shape&#91;<span class=\"hljs-number\">1<\/span>], <span class=\"hljs-number\">1<\/span>))\n    <span class=\"hljs-comment\"># Training: shuffle=False prevents data shuffling, order is important! <\/span>\n    <span class=\"hljs-keyword\">for<\/span> i in range(epochs):\n        neural_network.fit(X_TRAINING, Y_TRAINING, epochs = <span class=\"hljs-number\">1<\/span>, verbose = <span class=\"hljs-number\">0<\/span>, shuffle = <span class=\"hljs-keyword\">False<\/span>)\n        neural_network.reset_states()\n    Y_PREDICTED = &#91;]    <span class=\"hljs-comment\"># we list predictions in this array<\/span>\n    <span class=\"hljs-keyword\">for<\/span> x in X_TESTING:\n        x = x.reshape((<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">1<\/span>))\n        y = neural_network.predict(x, verbose = <span class=\"hljs-number\">0<\/span>)\n        Y_PREDICTED.append(y&#91;<span class=\"hljs-number\">0<\/span>]&#91;<span class=\"hljs-number\">0<\/span>])\n    <span class=\"hljs-comment\"># Plot data in read and predictions in blue<\/span>\n    plt.plot(Y, <span class=\"hljs-string\">'r'<\/span>)\n    plt.plot(range(n_training, N), Y_PREDICTED, <span class=\"hljs-string\">'b'<\/span>)\n    plt.show()\n    <span class=\"hljs-comment\"># Test loss<\/span>\n    <span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"Loss =\"<\/span>, np.linalg.norm(Y_TESTING - np.<span class=\"hljs-keyword\">array<\/span>(Y_PREDICTED))**<span class=\"hljs-number\">2<\/span>\/len(Y_TESTING))\n    <span class=\"hljs-comment\"># The curve with prediction instead of testing values is returned<\/span>\n    <span class=\"hljs-keyword\">return<\/span> np.concatenate((Y_TRAINING, Y_PREDICTED))\n \n<span class=\"hljs-comment\"># Set up the network with one layer of 10 nodes<\/span>\nnn = Sequential()\nnn.add(LSTM(<span class=\"hljs-number\">10<\/span>, activation = <span class=\"hljs-string\">\"relu\"<\/span>, input_shape = (<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">1<\/span>)))\nnn.add(Dense(<span class=\"hljs-number\">1<\/span>))   <span class=\"hljs-comment\"># the layer has a 1-dimensional output (a number!)<\/span>\nnn.compile(loss=<span class=\"hljs-string\">\"mean_squared_error\"<\/span>, optimizer=<span class=\"hljs-string\">\"adam\"<\/span>)\n \nprediction = train_test(nn, X_DEATHS, Y_DEATHS)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"388\" height=\"248\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image7-1.png\" alt=\"\" class=\"wp-image-4678\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image7-1.png 388w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image7-1-300x192.png 300w\" sizes=\"auto, (max-width: 388px) 100vw, 388px\" \/><figcaption>Loss = 981606.9073794972<\/figcaption><\/figure><\/div>\n\n\n\n<p>The result is not bad for a simple trial. At the very least, the model seems to follow the trend of the deaths curve.<\/p>\n\n\n\n<p>To get a better result, the immediate impulse would be to add one more layer. Doing this with Keras is very simple, requiring just one more <code>model.add<\/code> instruction:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">nn2 = Sequential()\nnn2.add(LSTM(<span class=\"hljs-number\">10<\/span>, activation = <span class=\"hljs-string\">\"relu\"<\/span>, input_shape = (<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">1<\/span>), return_sequences=<span class=\"hljs-keyword\">True<\/span>))\nnn2.add(LSTM(<span class=\"hljs-number\">10<\/span>, activation = <span class=\"hljs-string\">\"relu\"<\/span>))\nnn2.add(Dense(<span class=\"hljs-number\">1<\/span>))  <span class=\"hljs-comment\"># the layer has a 1-dimensional output (a number!)<\/span>\nnn2.compile(loss=<span class=\"hljs-string\">\"mean_squared_error\"<\/span>, optimizer=<span class=\"hljs-string\">\"adam\"<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In the previous snippet, the <code>return_sequences=True<\/code> option adjusts the output of the first layer to the input shape expected from the second layer, which is set to the same number of nodes as the first layer to keep things simple. The result is as follows:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">prediction = train_test(nn2, X_DEATHS, Y_DEATHS)<\/code><\/span><\/pre>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"388\" height=\"248\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image8.png\" alt=\"\" class=\"wp-image-4679\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image8.png 388w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image8-300x192.png 300w\" sizes=\"auto, (max-width: 388px) 100vw, 388px\" \/><figcaption>Loss = 941738.1083957498<\/figcaption><\/figure><\/div>\n\n\n\n<p>Inserting a new layer didn&#8217;t result in any significant improvement.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A bit of time series lore<\/h2>\n\n\n\n<p>Instead of blindly continuing in our attempts to improve our naive neural network, let&#8217;s try something a little cleverer. Those readers used to time series fitting will undoubtedly already be outraged by the poor pre-processing done in the above example. Time series are most effectively studied when they are paths of <em>stationary processes<\/em> &#8211; solutions of stochastic dynamical systems whose behaviour maintains, roughly speaking, mean and variance within a certain range. However, looking at our data, the trend of the curve clearly depends on time; there is no iterative structure at a first glance.<\/p>\n\n\n\n<p>The good news is that, to some degree it is possible to transform a series into a stationary version, so that the transformation is invertible. The simplest way to do this is to look at the series of differences of the given series: <em>s<\/em><sub>0<\/sub>,<em>s<\/em><sub>1<\/sub>,&#8230;,<em>s<sub>N<\/sub><\/em>, thus<\/p>\n\n\n\n<p class=\"has-text-align-center\"><em>d<\/em><sub>1<\/sub> = <em>s<\/em><sub>1<\/sub> \u2212 <em>s<\/em><sub>0<\/sub>,&nbsp; <em>d<\/em><sub>2 <\/sub>= <em>s<\/em><sub>2<\/sub> \u2212 <em>s<\/em><sub>1<\/sub>,&nbsp; &#8230;,&nbsp; <em>d<\/em><em><sub>N<\/sub><\/em> = <em>s<\/em><em><sub>N<\/sub><\/em> \u2212 <em>s<\/em><em><sub>N<\/sub><\/em><sub>\u22121<\/sub><\/p>\n\n\n\n<p>In both cases, the transformation (<em>s<\/em><sub>1<\/sub>,&#8230;,<em>s<sub>N<\/sub><\/em>) \u2192 (<em>d<\/em><sub>1<\/sub>,&#8230;,<em>d<sub>N<\/sub><\/em>) is invertible (notice that we excluded <em>s<\/em><sub>0<\/sub> from the original series, kept aside as a sort of &#8216;initial condition&#8217;), and the inverse is given by the recursive relationship:<\/p>\n\n\n\n<p class=\"has-text-align-center\"><em>s<\/em><sub>1<\/sub> = <em>s<\/em><sub>0<\/sub> + <em>d<\/em><sub>1<\/sub>,&nbsp; <em>s<\/em><sub>2<\/sub> = <em>s<\/em><sub>1<\/sub> + <em>d<\/em><sub>2<\/sub>,&nbsp; &#8230;,&nbsp; <em>s<\/em><em><sub>N<\/sub><\/em> = <em>s<\/em><em><sub>N<\/sub><\/em><sub>\u22121<\/sub> + <em>d<\/em><em><sub>N<\/sub><\/em><\/p>\n\n\n\n<p>In some sense the original series is the cumulative series of the series of differences. Another option would be to define a difference series with a given step <em>k<\/em>:<\/p>\n\n\n\n<p class=\"has-text-align-center\"><em>d<sub>k<\/sub> <\/em>= <em>s<sub>k<\/sub> <\/em>\u2212 <em>s<\/em><sub>0<\/sub>,&nbsp; <em>d<sub>k<\/sub><\/em><sub>+1<\/sub> = <em>s<sub>k<\/sub><\/em><sub>+1<\/sub> \u2212 <em>s<\/em><sub>1<\/sub>,&nbsp; &#8230;,&nbsp; <em>d<sub>N<\/sub> <\/em>= <em>s<sub>N<\/sub> <\/em>\u2212 <em>s<sub>N<\/sub><\/em><sub>\u2212<\/sub><em><sub>k<\/sub><\/em><\/p>\n\n\n\n<p>Let us try our two coronavirus series with step <em>k<\/em>=1:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">def difference(s):\n    <span class=\"hljs-keyword\">return<\/span> &#91;s&#91;i+<span class=\"hljs-number\">1<\/span>] - s&#91;i] <span class=\"hljs-keyword\">for<\/span> i in range(len(s)<span class=\"hljs-number\">-1<\/span>)]\n \ndef cumulated(s0, d):\n    <span class=\"hljs-comment\"># cumulated(s&#91;0], difference(s)) == s<\/span>\n    s = &#91;s0]\n    <span class=\"hljs-keyword\">for<\/span> i in range(len(d)):\n        s.append(s&#91;i] + d&#91;i])\n    <span class=\"hljs-keyword\">return<\/span> s\n \nD_CASES = difference(CASES)\nD_DEATHS = difference(DEATHS)\n \nfig, axes = plt.subplots(<span class=\"hljs-number\">2<\/span>, <span class=\"hljs-number\">2<\/span>, figsize=(<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">5<\/span>))\naxes&#91;<span class=\"hljs-number\">0<\/span>,<span class=\"hljs-number\">0<\/span>].plot(D_CASES, <span class=\"hljs-string\">\"r+\"<\/span>, label=<span class=\"hljs-string\">\"Cases diff\"<\/span>)\naxes&#91;<span class=\"hljs-number\">0<\/span>,<span class=\"hljs-number\">1<\/span>].plot(D_DEATHS, <span class=\"hljs-string\">\"k+\"<\/span>, label=<span class=\"hljs-string\">\"Deaths diff\"<\/span>)\naxes&#91;<span class=\"hljs-number\">0<\/span>,<span class=\"hljs-number\">0<\/span>].legend()\naxes&#91;<span class=\"hljs-number\">0<\/span>,<span class=\"hljs-number\">1<\/span>].legend()\naxes&#91;<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-number\">0<\/span>].hist(D_CASES)\naxes&#91;<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-number\">1<\/span>].hist(D_DEATHS)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"611\" height=\"305\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image10.png\" alt=\"\" class=\"wp-image-4681\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image10.png 611w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image10-300x150.png 300w\" sizes=\"auto, (max-width: 611px) 100vw, 611px\" \/><\/figure><\/div>\n\n\n\n<p>Differentiation may be iterated, thus we may consider a second difference of the series (the series that expresses the difference of its difference), and so on. At each step the series become more and more similar to a stationary series. Of course, the k-th difference of a given series has k elements fewer than the original one.<\/p>\n\n\n\n<p>For example let us compute the third difference of our series:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">D3_CASES = difference(difference(difference(CASES)))\nD3_DEATHS = difference(difference(difference(DEATHS)))\n \nfig, axes = plt.subplots(<span class=\"hljs-number\">2<\/span>, <span class=\"hljs-number\">2<\/span>, figsize=(<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">8<\/span>))\naxes&#91;<span class=\"hljs-number\">0<\/span>,<span class=\"hljs-number\">0<\/span>].plot(D3_CASES, <span class=\"hljs-string\">\"r+\"<\/span>, label=<span class=\"hljs-string\">\"Cases diff^3\"<\/span>)\naxes&#91;<span class=\"hljs-number\">0<\/span>,<span class=\"hljs-number\">1<\/span>].plot(D3_DEATHS, <span class=\"hljs-string\">\"k+\"<\/span>, label=<span class=\"hljs-string\">\"Deaths diff^3\"<\/span>)\naxes&#91;<span class=\"hljs-number\">0<\/span>,<span class=\"hljs-number\">0<\/span>].legend()\naxes&#91;<span class=\"hljs-number\">0<\/span>,<span class=\"hljs-number\">1<\/span>].legend()\naxes&#91;<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-number\">0<\/span>].hist(D3_CASES)\naxes&#91;<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-number\">1<\/span>].hist(D3_DEATHS)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"617\" height=\"466\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image9.png\" alt=\"\" class=\"wp-image-4680\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image9.png 617w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image9-300x227.png 300w\" sizes=\"auto, (max-width: 617px) 100vw, 617px\" \/><\/figure><\/div>\n\n\n\n<p>Notice that the histograms tend to become more and more similar to normal distributions.<\/p>\n\n\n\n<p>Next, we will again perform the <strong>training of the neural network on differentiated data<\/strong>, and convert the results back into cumulative form. This performance produces an impressive improvement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">plt.figure(<span class=\"hljs-number\">0<\/span>)\nDX_DEATHS, DY_DEATHS = extract_sample(D_DEATHS)\nd_prediction = train_test(nn2, DX_DEATHS, DY_DEATHS)\n \n<span class=\"hljs-comment\"># We plot also the actual series<\/span>\nplt.figure(<span class=\"hljs-number\">1<\/span>)\nprediction = cumulated(Y_DEATHS&#91;<span class=\"hljs-number\">0<\/span>], d_prediction)\nplt.plot(prediction, <span class=\"hljs-string\">'b'<\/span>)\nplt.plot(Y_DEATHS, <span class=\"hljs-string\">'r'<\/span>)\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"Loss =\"<\/span>, np.linalg.norm(Y_DEATHS - np.<span class=\"hljs-keyword\">array<\/span>(prediction))**<span class=\"hljs-number\">2<\/span>\/len(Y_DEATHS))<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"375\" height=\"248\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image2-2.png\" alt=\"\" class=\"wp-image-4673\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image2-2.png 375w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image2-2-300x198.png 300w\" sizes=\"auto, (max-width: 375px) 100vw, 375px\" \/><figcaption>Loss = 13967.875774114951<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"388\" height=\"248\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image1-2.png\" alt=\"\" class=\"wp-image-4672\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image1-2.png 388w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image1-2-300x192.png 300w\" sizes=\"auto, (max-width: 388px) 100vw, 388px\" \/><figcaption>Loss = 25453.65511699591<\/figcaption><\/figure><\/div>\n\n\n\n<p>Another invertible transformation that it makes sense to apply to our case studies is the <strong>scaling transformation<\/strong>, by means of which we reduce our data to within a fixed interval. When using neural networks this is a worthwhile path to pursue, as such networks have nodes that usually output numbers between -1 and 1, unless otherwise stated. For example, one could use the &#8216;relu&#8217; activation function, popular in deep learning, which cuts negative values.<\/p>\n\n\n\n<p>The &#8216;relu&#8217; specification may be dropped, but the data has to be rescaled. First, here is a demonstration of the scaling function, which simply takes the minimum and maximum value of the series and linearly transforms the former into -1 and the latter into 1 (and all numbers in between accordingly). This scaling is applied to the difference series:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">def scaling(s, a = <span class=\"hljs-number\">-1<\/span>, b = <span class=\"hljs-number\">1<\/span>):\n    m = min(s)\n    M = max(s)\n    scale = (b - a)\/(M - m)\n    <span class=\"hljs-keyword\">return<\/span> a + scale * (s - m)\n \nDS_CASES = scaling(difference(CASES))\nDS_DEATHS = scaling(difference(DEATHS))\n \nfig, axes = plt.subplots(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">2<\/span>, figsize=(<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">4<\/span>))\naxes&#91;<span class=\"hljs-number\">0<\/span>].plot(DS_CASES, <span class=\"hljs-string\">\"r+\"<\/span>, label=<span class=\"hljs-string\">\"Cases diff+scaled\"<\/span>)\naxes&#91;<span class=\"hljs-number\">1<\/span>].plot(DS_DEATHS, <span class=\"hljs-string\">\"k+\"<\/span>, label=<span class=\"hljs-string\">\"Deaths diff+scaled\"<\/span>)\naxes&#91;<span class=\"hljs-number\">0<\/span>].legend()\naxes&#91;<span class=\"hljs-number\">1<\/span>].legend()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"610\" height=\"248\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image4-1.png\" alt=\"\" class=\"wp-image-4675\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image4-1.png 610w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image4-1-300x122.png 300w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/figure><\/div>\n\n\n\n<p>Finally, let us check our basic LSTM network on these data, and transform the results back again to provide a prediction as we did previously. The same parameters are used to train the network, but  the activation function is left as the default, which is a sigmoid function between -1 and 1.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">nn3 = Sequential()\nnn3.add(LSTM(<span class=\"hljs-number\">10<\/span>, input_shape = (<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">1<\/span>), return_sequences=<span class=\"hljs-keyword\">True<\/span>))\nnn3.add(LSTM(<span class=\"hljs-number\">10<\/span>))\nnn3.add(Dense(<span class=\"hljs-number\">1<\/span>))  <span class=\"hljs-comment\"># the layer has a 1-dimensional output (a number!)<\/span>\nnn3.compile(loss=<span class=\"hljs-string\">\"mean_squared_error\"<\/span>, optimizer=<span class=\"hljs-string\">\"adam\"<\/span>)\n \nplt.figure(<span class=\"hljs-number\">0<\/span>)\nDSX_DEATHS, DSY_DEATHS = extract_sample(DS_DEATHS)\nds_prediction = train_test(nn3, DSX_DEATHS, DSY_DEATHS)\n \n<span class=\"hljs-comment\"># We plot also the actual series<\/span>\nplt.figure(<span class=\"hljs-number\">1<\/span>)\nd_prediction = scaling(ds_prediction, min(D_DEATHS), max(D_DEATHS))\nprediction = cumulated(Y_DEATHS&#91;<span class=\"hljs-number\">0<\/span>], d_prediction)\nplt.plot(prediction, <span class=\"hljs-string\">'b'<\/span>)\nplt.plot(Y_DEATHS, <span class=\"hljs-string\">'r'<\/span>)\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"Loss =\"<\/span>, np.linalg.norm(Y_DEATHS - np.<span class=\"hljs-keyword\">array<\/span>(prediction))**<span class=\"hljs-number\">2<\/span>\/len(Y_DEATHS))<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"386\" height=\"248\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image3-2.png\" alt=\"\" class=\"wp-image-4674\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image3-2.png 386w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image3-2-300x193.png 300w\" sizes=\"auto, (max-width: 386px) 100vw, 386px\" \/><figcaption>Loss = 0.07472911340442429<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"388\" height=\"248\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image5-1.png\" alt=\"\" class=\"wp-image-4676\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image5-1.png 388w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/image5-1-300x192.png 300w\" sizes=\"auto, (max-width: 388px) 100vw, 388px\" \/><figcaption>Loss = 19749.745315784992<\/figcaption><\/figure><\/div>\n\n\n\n<p>Another improvement is obvious: our predictions are far from being reliable in the long term but give quite a reasonable approximation of the curve related to deaths.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusions<\/h2>\n\n\n\n<p>In this article we set up a simple non-parametric model to predict time series, and applied it to data on the spread of COVID-19. The techniques demonstrated here can be greatly improved on in several respects &#8211; by using stateful LSTM models, for example, and also by using different and more informative datasets.<\/p>\n\n\n\n<p>However, the aims of this article were:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>To point out the <strong>differences between the parametric<\/strong>(more math, specific domain considerations, etc.) <strong>and non-parametric models<\/strong> (framework use, guessing hyper-parameters, etc.).<\/li><li>To show how <strong>data preparation not a trivial task<\/strong> in machine learning algorithm implementation. Most of the code written here was the product of data handling, while the model was set up in a handful of API calls.<\/li><li>To point out that simply making a <strong>more complicated neural network does not imply a corresponding gain in performance<\/strong>. It is very easy to complicate the model in Keras, but this should be done only if actually needed.  Experiment by changing hyper-parameters to find a good combination rather than by adding layers.<\/li><li>To stress the importance of <strong>knowing what we are doing<\/strong>. Starting with some elementary techniques for time series, we improved the result by simply transforming the input data, without making any changes to the model!<\/li><\/ol>\n\n\n\n<p>Above all, <strong>human reflection about machine algorithms is always needed<\/strong>. Leaving relevant choices to the data scientists who design and implement the simulation remains the key to understanding a real phenomenon (such as viral spread).<\/p>\n\n\n\n\n\n\n\n<p>If you are interested in these topics, do not miss the opportunity to attend our <strong><span id=\"urn:local-annotation-918764\" class=\"textannotation disambiguated\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/deep_learning\">Deep Learning<\/span> online conference<\/strong>: <a href=\"https:\/\/bit.ly\/2YfTgUz\" class=\"ek-link\">click here for more information<\/a>!<\/p>\n\n\n","protected":false},"excerpt":{"rendered":"<p>In a previous article, we shared some reflections on machine learning models for data fitting and prediction, playing with a simple dataset related to the spread of the current coronavirus emergency. We looked at simple models and mentioned some more advanced ideas that rely upon deterministic dynamical system theory to be properly understood. However, that&#8230; <a class=\"more-link\" href=\"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\/\">Read more<\/a><\/p>\n","protected":false},"author":5,"featured_media":4682,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_editorskit_title_hidden":false,"_editorskit_reading_time":13,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","_uag_custom_page_level_css":"","_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[35],"tags":[5571,5100,4446,5572],"collections":[],"class_list":{"0":"post-4670","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-machine-learning","8":"tag-big-data","9":"tag-coronavirus","10":"tag-data-analysis","11":"tag-neural-networks","12":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v27.5) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Neural Networks in the age of Coronavirus - Codemotion Magazine<\/title>\n<meta name=\"description\" content=\"Using non-parametric models, and neural networks in particular, to predict numbers in the coronavirus epidemic.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Epidemic Intelligence, part 2: data, models and machine learning in the age of Coronavirus\" \/>\n<meta property=\"og:description\" content=\"Using non-parametric models, and neural networks in particular, to predict numbers in the coronavirus epidemic.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\/\" \/>\n<meta property=\"og:site_name\" content=\"Codemotion Magazine\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Codemotion.Italy\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-08T13:32:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-01-05T19:04:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/1-pKv3DL-enonlNJxzqhlWkQ-scaled.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"1013\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Paolo Caressa\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@www_caressa_it\" \/>\n<meta name=\"twitter:site\" content=\"@CodemotionIT\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Paolo Caressa\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"19 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/machine-learning\\\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/machine-learning\\\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\\\/\"},\"author\":{\"name\":\"Paolo Caressa\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#\\\/schema\\\/person\\\/11b502309bc50a6923aafd79c6259f85\"},\"headline\":\"Epidemic Intelligence, part 2: data, models and machine learning in the age of Coronavirus\",\"datePublished\":\"2020-05-08T13:32:26+00:00\",\"dateModified\":\"2022-01-05T19:04:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/machine-learning\\\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\\\/\"},\"wordCount\":2836,\"publisher\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/machine-learning\\\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/1-pKv3DL-enonlNJxzqhlWkQ-scaled.jpeg\",\"keywords\":[\"Big Data\",\"Coronavirus\",\"Data Analysis\",\"Neural Networks\"],\"articleSection\":[\"Machine Learning\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/machine-learning\\\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\\\/\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/machine-learning\\\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\\\/\",\"name\":\"Neural Networks in the age of Coronavirus - Codemotion Magazine\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/machine-learning\\\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/machine-learning\\\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/1-pKv3DL-enonlNJxzqhlWkQ-scaled.jpeg\",\"datePublished\":\"2020-05-08T13:32:26+00:00\",\"dateModified\":\"2022-01-05T19:04:56+00:00\",\"description\":\"Using non-parametric models, and neural networks in particular, to predict numbers in the coronavirus epidemic.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/machine-learning\\\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/machine-learning\\\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/machine-learning\\\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/1-pKv3DL-enonlNJxzqhlWkQ-scaled.jpeg\",\"contentUrl\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/1-pKv3DL-enonlNJxzqhlWkQ-scaled.jpeg\",\"width\":1013,\"height\":675,\"caption\":\"neural networks\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/machine-learning\\\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"AI\\\/ML\",\"item\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Machine Learning\",\"item\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/machine-learning\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Epidemic Intelligence, part 2: data, models and machine learning in the age of Coronavirus\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#website\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/\",\"name\":\"Codemotion Magazine\",\"description\":\"We code the future. Together\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#organization\",\"name\":\"Codemotion\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2019\\\/11\\\/codemotionlogo.png\",\"contentUrl\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2019\\\/11\\\/codemotionlogo.png\",\"width\":225,\"height\":225,\"caption\":\"Codemotion\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Codemotion.Italy\\\/\",\"https:\\\/\\\/x.com\\\/CodemotionIT\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#\\\/schema\\\/person\\\/11b502309bc50a6923aafd79c6259f85\",\"name\":\"Paolo Caressa\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b55795d60b54b1cc8b605f9967dbbe68b3fcf826249490cecafd797ee4f18d4c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b55795d60b54b1cc8b605f9967dbbe68b3fcf826249490cecafd797ee4f18d4c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b55795d60b54b1cc8b605f9967dbbe68b3fcf826249490cecafd797ee4f18d4c?s=96&d=mm&r=g\",\"caption\":\"Paolo Caressa\"},\"description\":\"I spent the first part of my life enjoying studies up to a math BS+MS and PhD. Next I worked both as math researcher (differential geometry) and as IT consultant (R&amp;D, feasibility studies, business analysis). Eventually I left academia and worked some years in finance (maths &amp; implementation of derivative pricings and risk management models), then again in IT (as technical consultant and writer, project manager, program manager). In the meanwhile I write books and articles on maths and computer science and I give lectures on workshops and conferences (applied maths, AI, etc.). I also serve as adjunct professor in the Engineering Department of \\\"Sapienza\\\" University of Rome (calculus and CS classes).\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/paolocaressa\\\/\",\"https:\\\/\\\/x.com\\\/www_caressa_it\"],\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/author\\\/paolo-caressa\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Neural Networks in the age of Coronavirus - Codemotion Magazine","description":"Using non-parametric models, and neural networks in particular, to predict numbers in the coronavirus epidemic.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\/","og_locale":"en_US","og_type":"article","og_title":"Epidemic Intelligence, part 2: data, models and machine learning in the age of Coronavirus","og_description":"Using non-parametric models, and neural networks in particular, to predict numbers in the coronavirus epidemic.","og_url":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\/","og_site_name":"Codemotion Magazine","article_publisher":"https:\/\/www.facebook.com\/Codemotion.Italy\/","article_published_time":"2020-05-08T13:32:26+00:00","article_modified_time":"2022-01-05T19:04:56+00:00","og_image":[{"width":1013,"height":675,"url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/1-pKv3DL-enonlNJxzqhlWkQ-scaled.jpeg","type":"image\/jpeg"}],"author":"Paolo Caressa","twitter_card":"summary_large_image","twitter_creator":"@www_caressa_it","twitter_site":"@CodemotionIT","twitter_misc":{"Written by":"Paolo Caressa","Est. reading time":"19 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\/#article","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\/"},"author":{"name":"Paolo Caressa","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/11b502309bc50a6923aafd79c6259f85"},"headline":"Epidemic Intelligence, part 2: data, models and machine learning in the age of Coronavirus","datePublished":"2020-05-08T13:32:26+00:00","dateModified":"2022-01-05T19:04:56+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\/"},"wordCount":2836,"publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/1-pKv3DL-enonlNJxzqhlWkQ-scaled.jpeg","keywords":["Big Data","Coronavirus","Data Analysis","Neural Networks"],"articleSection":["Machine Learning"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\/","url":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\/","name":"Neural Networks in the age of Coronavirus - Codemotion Magazine","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\/#primaryimage"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/1-pKv3DL-enonlNJxzqhlWkQ-scaled.jpeg","datePublished":"2020-05-08T13:32:26+00:00","dateModified":"2022-01-05T19:04:56+00:00","description":"Using non-parametric models, and neural networks in particular, to predict numbers in the coronavirus epidemic.","breadcrumb":{"@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\/#primaryimage","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/1-pKv3DL-enonlNJxzqhlWkQ-scaled.jpeg","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/1-pKv3DL-enonlNJxzqhlWkQ-scaled.jpeg","width":1013,"height":675,"caption":"neural networks"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codemotion.com\/magazine\/"},{"@type":"ListItem","position":2,"name":"AI\/ML","item":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/"},{"@type":"ListItem","position":3,"name":"Machine Learning","item":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/"},{"@type":"ListItem","position":4,"name":"Epidemic Intelligence, part 2: data, models and machine learning in the age of Coronavirus"}]},{"@type":"WebSite","@id":"https:\/\/www.codemotion.com\/magazine\/#website","url":"https:\/\/www.codemotion.com\/magazine\/","name":"Codemotion Magazine","description":"We code the future. Together","publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codemotion.com\/magazine\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codemotion.com\/magazine\/#organization","name":"Codemotion","url":"https:\/\/www.codemotion.com\/magazine\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","width":225,"height":225,"caption":"Codemotion"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Codemotion.Italy\/","https:\/\/x.com\/CodemotionIT"]},{"@type":"Person","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/11b502309bc50a6923aafd79c6259f85","name":"Paolo Caressa","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b55795d60b54b1cc8b605f9967dbbe68b3fcf826249490cecafd797ee4f18d4c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b55795d60b54b1cc8b605f9967dbbe68b3fcf826249490cecafd797ee4f18d4c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b55795d60b54b1cc8b605f9967dbbe68b3fcf826249490cecafd797ee4f18d4c?s=96&d=mm&r=g","caption":"Paolo Caressa"},"description":"I spent the first part of my life enjoying studies up to a math BS+MS and PhD. Next I worked both as math researcher (differential geometry) and as IT consultant (R&amp;D, feasibility studies, business analysis). Eventually I left academia and worked some years in finance (maths &amp; implementation of derivative pricings and risk management models), then again in IT (as technical consultant and writer, project manager, program manager). In the meanwhile I write books and articles on maths and computer science and I give lectures on workshops and conferences (applied maths, AI, etc.). I also serve as adjunct professor in the Engineering Department of \"Sapienza\" University of Rome (calculus and CS classes).","sameAs":["https:\/\/www.linkedin.com\/in\/paolocaressa\/","https:\/\/x.com\/www_caressa_it"],"url":"https:\/\/www.codemotion.com\/magazine\/author\/paolo-caressa\/"}]}},"featured_image_src":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/1-pKv3DL-enonlNJxzqhlWkQ-scaled-600x400.jpeg","featured_image_src_square":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/1-pKv3DL-enonlNJxzqhlWkQ-scaled-600x600.jpeg","author_info":{"display_name":"Paolo Caressa","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/paolo-caressa\/"},"uagb_featured_image_src":{"full":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/1-pKv3DL-enonlNJxzqhlWkQ-scaled.jpeg",1013,675,false],"thumbnail":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/1-pKv3DL-enonlNJxzqhlWkQ-scaled-150x150.jpeg",150,150,true],"medium":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/1-pKv3DL-enonlNJxzqhlWkQ-scaled-300x200.jpeg",300,200,true],"medium_large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/1-pKv3DL-enonlNJxzqhlWkQ-scaled-768x512.jpeg",768,512,true],"large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/1-pKv3DL-enonlNJxzqhlWkQ-scaled.jpeg",1013,675,false],"1536x1536":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/1-pKv3DL-enonlNJxzqhlWkQ-scaled.jpeg",1013,675,false],"2048x2048":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/1-pKv3DL-enonlNJxzqhlWkQ-scaled.jpeg",1013,675,false],"small-home-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/1-pKv3DL-enonlNJxzqhlWkQ-scaled.jpeg",100,67,false],"sidebar-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/1-pKv3DL-enonlNJxzqhlWkQ-scaled-180x128.jpeg",180,128,true],"genesis-singular-images":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/1-pKv3DL-enonlNJxzqhlWkQ-scaled-896x504.jpeg",896,504,true],"archive-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/1-pKv3DL-enonlNJxzqhlWkQ-scaled-400x225.jpeg",400,225,true],"gb-block-post-grid-landscape":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/1-pKv3DL-enonlNJxzqhlWkQ-scaled-600x400.jpeg",600,400,true],"gb-block-post-grid-square":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/05\/1-pKv3DL-enonlNJxzqhlWkQ-scaled-600x600.jpeg",600,600,true]},"uagb_author_info":{"display_name":"Paolo Caressa","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/paolo-caressa\/"},"uagb_comment_info":0,"uagb_excerpt":"In a previous article, we shared some reflections on machine learning models for data fitting and prediction, playing with a simple dataset related to the spread of the current coronavirus emergency. We looked at simple models and mentioned some more advanced ideas that rely upon deterministic dynamical system theory to be properly understood. However, that&#8230;&hellip;","lang":"en","_links":{"self":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/4670","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/comments?post=4670"}],"version-history":[{"count":14,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/4670\/revisions"}],"predecessor-version":[{"id":7062,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/4670\/revisions\/7062"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media\/4682"}],"wp:attachment":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media?parent=4670"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/categories?post=4670"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/tags?post=4670"},{"taxonomy":"collections","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/collections?post=4670"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}