{"id":4050,"date":"2020-04-18T16:13:00","date_gmt":"2020-04-18T14:13:00","guid":{"rendered":"https:\/\/www.codemotion.com\/magazine\/?p=4050"},"modified":"2023-05-30T15:33:35","modified_gmt":"2023-05-30T13:33:35","slug":"epidemic-intelligence-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-data-models-and-machine-learning-in-the-age-of-coronavirus\/","title":{"rendered":"Epidemic Intelligence, part 1: 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-67176003 wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-undefined uagb-block-2dcb5712     \"\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=\"#the-easiest-thing-getting-data\" class=\"uagb-toc-link__trigger\">The easiest thing: getting data<\/a><li class=\"uagb-toc__list\"><a href=\"#parametric-epidemic-models-exponential-and-logistics\" class=\"uagb-toc-link__trigger\">Parametric epidemic models: exponential and logistics<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#exponential-modelling\" class=\"uagb-toc-link__trigger\">Exponential modelling<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#logistic-modelling\" class=\"uagb-toc-link__trigger\">Logistic modelling<\/a><\/li><\/ul><\/li><li class=\"uagb-toc__list\"><a href=\"#remarks-on-epidemic-model-parameters-learning\" class=\"uagb-toc-link__trigger\">Remarks on epidemic model parameters learning<\/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 class=\"eplus-NYRdmI\">The current global <span id=\"urn:enhancement-d3c91fd7\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/emergency\">emergency<\/span> due to the spread of the <span id=\"urn:enhancement-ee68a833\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/coronavirus\">coronavirus<\/span> in several countries shows how fragile our society&#8217;s equilibrium is when faced with &#8216;interior&#8217; threats such as an <span id=\"urn:enhancement-830eaccc\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/epidemic\">epidemic<\/span>. Treatments to relieve symptoms and a vaccine will eventually be found, but in the meantime <strong><span id=\"urn:enhancement-45831975\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/human\">humankind<\/span> seems to be helpless against the <span id=\"urn:enhancement-ffa35312\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/virus\">virus<\/span><\/strong>. The only effective weapon available to us is stopping direct contact between people, in order to segregate the infected from the healthy.<\/p>\n\n\n\n<p class=\"eplus-UOrART\">In a sense this is a blow to <span id=\"urn:enhancement-5ccd700f\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/human\">humankind&#8217;s<\/span> self esteem: <a href=\"https:\/\/www.codemotion.com\/magazine\/articles\/events\/codemotion-milan-2019-celebrates-the-50th-anniversary-of-the-apollo-moon-landing\/\" class=\"ek-link\">didn&#8217;t we go to the Moon<\/a>, don&#8217;t we fly through the air and haven&#8217;t we built a network for <span id=\"urn:enhancement-7ce1cb4c\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/information_exchange\">information exchange<\/span> which has forever changed our habits and lives? As far as the latter achievement is concerned, nowadays we have real time access to information about the <span id=\"urn:enhancement-9ba0858f\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/virus\">virus<\/span> and its spread: <strong>is it possible to use this information to fight the <span id=\"urn:enhancement-9993a639\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/epidemic\">epidemic<\/span><\/strong>?<\/p>\n\n\n\n<p class=\"eplus-7O1USH\">The will to understand and to participate in this &#8220;war against the <span id=\"urn:enhancement-4b54cce2\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/virus\">virus<\/span>&#8221; is a natural impulse in humans, and the reason why <span id=\"urn:local-annotation-938943\" class=\"textannotation disambiguated\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/computer_science\">computer scientists<\/span> and practitioners, who deal with <span id=\"urn:enhancement-9b39a751\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> every day, have provided a flood of dashboards, graphs and pronouncements about the <span id=\"urn:enhancement-dfa28c7a\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/epidemic\">epidemic<\/span> and its possible effects and evolution.<\/p>\n\n\n\n<p class=\"eplus-qkjfhX\">Of course, dealing with <span id=\"urn:enhancement-9df5b8a4\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/virus\">viruses<\/span> is a job for virologists &#8211; a computer scientist, and in particular a <span id=\"urn:enhancement-1a4ccf72\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> scientist, dealing with the study of coronavirus appears in some ways to be like a virologist dealing with the study of a cryptolocker. There is a risk of providing &#8216;blind&#8217; analyses which may fit the current <span id=\"urn:enhancement-972b8fef\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span>, but are meaningless from a biological point of view.<\/p>\n\n\n\n<p class=\"eplus-hSICof\">In this article, I will try to reflect on these risks, writing some trial code to be used to play with different models and to face the difficulties of dealing with real <span id=\"urn:enhancement-45c7c9a6\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading eplus-DLVwEs\" id=\"h-the-easiest-thing-getting-data\">The easiest thing: getting data<\/h2>\n\n\n\n<p class=\"eplus-5fHSzy\">In my opinion, one wonderful aspect of our times is <strong>the availability of <span id=\"urn:enhancement-8257f168\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> and tools<\/strong> with which to expand our understanding of the world, and this epidemic is no exception to that. There are plenty of official <span id=\"urn:enhancement-b6f31826\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/software_repository\">repositories<\/span> of recorded <span id=\"urn:enhancement-e1bd6181\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span>. To keep thing simple (this is not a <span id=\"urn:enhancement-a761c322\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/academic_publishing\">research paper<\/span>!) I will use a simple repository in which <span id=\"urn:enhancement-fe3c3c32\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/comma-separated_values\">CSV<\/span> <span id=\"urn:enhancement-c77ca094\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> are maintained by <em><span id=\"urn:enhancement-9974c7ff\" class=\"textannotation disambiguated wl-organization\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/the_new_york_times\">The New York Times<\/span><\/em>, based on reports from state and local health agencies (more information can be found at <a aria-label=\" (opens in a new tab)\" href=\"https:\/\/www.nytimes.com\/interactive\/2020\/us\/coronavirus-us-cases.html\" target=\"_blank\" rel=\"noreferrer noopener nofollow\" class=\"ek-link\">this link<\/a>).<\/p>\n\n\n\n<p class=\"eplus-aOpPc1\">These <span id=\"urn:enhancement-d8a3616d\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> provide, for each date from 21 January 2020 on, and for each US state, the number of cases and the number of deaths, each row of the CSV taking the following form (the <em>fips<\/em> field may be used to cross-reference these <span id=\"urn:enhancement-43d35d86\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> with other <span id=\"urn:enhancement-9e489523\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> for each location):<\/p>\n\n\n<pre class=\"wp-block-code eplus-FgtbBt\"><span><code class=\"hljs\">date,state,fips,cases,deaths\n2020-01-21,Washington,53,1,0<\/code><\/span><\/pre>\n\n\n<p class=\"eplus-8A7pCO\">Let us load these <span id=\"urn:enhancement-85b59e9d\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> by means of the following <span id=\"urn:enhancement-170ee3b4\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/python_programming_language\">Python<\/span> <span id=\"urn:enhancement-31ee0101\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/scripting_language\">script<\/span> and filter them to consider only New York state. We will use this <span id=\"urn:enhancement-e23ca906\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> to produce two numerical series <em>CASES<\/em> and <em>DEATHS<\/em>, and plot them.<\/p>\n\n\n<pre class=\"wp-block-code eplus-yr8Y0n\" 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\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>)\n\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\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\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\">5<\/span>))\naxes&#91;<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\">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>].legend()\naxes&#91;<span class=\"hljs-number\">1<\/span>].legend()<\/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<div class=\"wp-block-image eplus-eFVcgm\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"617\" height=\"303\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1.png\" alt=\"\" class=\"wp-image-4052\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1.png 617w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1-300x147.png 300w\" sizes=\"auto, (max-width: 617px) 100vw, 617px\" \/><\/figure><\/div>\n\n\n<p class=\"eplus-GPUrSp\">These two times series display a trend which, as far as the series of cases is concerned, starts increasing very rapidly from the 18th day on, showing that cases increased ten times in the ten days following that date.<\/p>\n\n\n\n<p class=\"eplus-vhGfwM\"><strong style=\"user-select: auto;\">How can we <span style=\"user-select: auto;\" id=\"urn:enhancement-2a9609fc\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> such curves?<\/strong> Let us try some simple models at first, starting with the most popular options. Following a quick bout of <span style=\"user-select: auto;\" id=\"urn:enhancement-6786be86\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/internet_research\">Internet research<\/span> it turns out that many people <span style=\"user-select: auto;\" id=\"urn:enhancement-916c62df\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> <span style=\"user-select: auto;\" id=\"urn:enhancement-4146274d\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/statistical_population\">population<\/span> increments using two kinds of epidemic model, the <strong style=\"user-select: auto;\"><span style=\"user-select: auto;\" id=\"urn:enhancement-ca1f6bcd\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/exponential_function\">exponential<\/span> <span style=\"user-select: auto;\" id=\"urn:enhancement-fc07c273\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span><\/strong> and the <strong style=\"user-select: auto;\">logistic <span style=\"user-select: auto;\" id=\"urn:enhancement-f296c19c\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span><\/strong>. We will continue this pattern.<\/p>\n\n\n\n<h2 class=\"wp-block-heading eplus-84w2rP\" id=\"h-parametric-epidemic-models-exponential-and-logistics\">Parametric epidemic models: exponential and logistics<\/h2>\n\n\n\n<h3 class=\"wp-block-heading eplus-FUOuxJ\" id=\"h-exponential-modelling\">Exponential modelling<\/h3>\n\n\n\n<p class=\"eplus-ZbZFla\">An <span id=\"urn:enhancement-568c74b7\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/exponential_function\">exponential<\/span> <span id=\"urn:enhancement-e5691d13\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> is, to people familiar with a minimum of maths, just the <span id=\"urn:enhancement-ab4ae55f\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/exponential_function\">exponential<\/span> function with a couple of parameters plugged in to allow calibration. Thus we imagine a rule which given a time <em>t <\/em>produces a value <em>C<\/em>(<em>t<\/em>) for the cases at time <em>t<\/em> and <em>D<\/em>(<em>t<\/em>) for the deaths at time <em>t<\/em>, both being mathematical functions of the form:<\/p>\n\n\n\n<p class=\"has-text-align-center eplus-tk0gDh\"><em>C(t) = c<sub>1<\/sub>exp(c<sub>2<\/sub>t)<\/em><br><em>D(t) = d<sub>1<\/sub>exp(d<sub>2<\/sub>t)<\/em><\/p>\n\n\n\n<p class=\"eplus-H6YfBV\">where <em>c<\/em><sub>1<\/sub>,<em>c<\/em><sub>2<\/sub> and <em>d<\/em><sub>1<\/sub>,<em>d<\/em><sub>2<\/sub> are &#8216;<span id=\"urn:enhancement-abf950bb\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> <span id=\"urn:enhancement-54feb5d2\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/parameter\">parameters<\/span>&#8216;. To <span id=\"urn:enhancement-127a7001\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/calibration\">calibrate<\/span> the curve for the appropriated <span id=\"urn:enhancement-cf06c8b3\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> series, we need to find out the value of the <span id=\"urn:enhancement-615a75c9\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/parameter\">parameters<\/span> which, substituted inside the functions, let them <span id=\"urn:enhancement-20e77825\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/approximation\">approximate<\/span> the real <span id=\"urn:enhancement-ed6f511\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> in the best possible way. Thus we have an <strong><span id=\"urn:enhancement-61683c9a\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/optimization_problem\">optimization problem<\/span><\/strong>.<\/p>\n\n\n\n<p class=\"eplus-so5882\">This is interesting since <strong>most artificial intelligence problems, and all machine <span id=\"urn:enhancement-99cec395\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/learning\">learning<\/span> problems are actually optimization problems!<\/strong> Thus, when <span id=\"urn:enhancement-dd4801da\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/calibration\">calibrating<\/span> a parametric <span id=\"urn:enhancement-6ed550a0\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> by <span id=\"urn:enhancement-2f7d736f\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/curve_fitting\">fitting<\/span> <span id=\"urn:enhancement-3fb2b384\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span>, <strong>we are already engaged in machine <span id=\"urn:enhancement-b7026faa\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/learning\">learning<\/span><\/strong> to some degree; namely, we are <span id=\"urn:enhancement-80ef0f2\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/learning\">learning<\/span> the optimal <span id=\"urn:enhancement-20ed631c\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/parameter\">parameters<\/span> to fit the <span id=\"urn:enhancement-a3f75ce\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span>. Instead of devising a method to <span id=\"urn:enhancement-b66ba9f2\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/calibration\">calibrate<\/span> parameters in a <span id=\"urn:enhancement-3b05f8de\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span>, we can use one that has already been programmed. This is simple in <span id=\"urn:enhancement-2b0e8d5\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/python_programming_language\">Python<\/span> and runs more or less as follows (the <span id=\"urn:enhancement-6212a2a2\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/calibration\">calibration<\/span> function just minimizes the quadratic error since we are using the <span id=\"urn:enhancement-536ba3dc\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/norm_mathematics\">Euclidean norm<\/span>):<\/p>\n\n\n<pre class=\"wp-block-code eplus-JAh5pJ\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">from scipy.optimize import fmin\n\nINTERVAL = np.arange(len(NY_DATA))    <span class=\"hljs-comment\"># t=0 means the first day; time increase is daily<\/span>\n\ndef exponential(t, params):\n    <span class=\"hljs-keyword\">return<\/span> params&#91;<span class=\"hljs-number\">0<\/span>]*np.exp(params&#91;<span class=\"hljs-number\">1<\/span>]*t)\n\ndef apply_model(model, init_cond, interval, data, disp =<span class=\"hljs-keyword\">True<\/span>, shadow=<span class=\"hljs-keyword\">False<\/span>, title=<span class=\"hljs-string\">\"\"<\/span>):\n    opt_params = fmin(lambda p: np.linalg.norm(model(interval, p) - data),\n                      init_cond, disp = <span class=\"hljs-keyword\">False<\/span>)\n    <span class=\"hljs-keyword\">if<\/span> disp:\n        y = model(interval, opt_params)\n        err = np.linalg.norm(y - data)\n        <span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"Optimal parameters:\"<\/span>, opt_params)\n        <span class=\"hljs-keyword\">print<\/span>(f<span class=\"hljs-string\">\"Model error = {err:.2f}\"<\/span>)\n        plt.figure(figsize=(<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">5<\/span>))\n        <span class=\"hljs-keyword\">if<\/span> shadow:\n            plt.fill_between(interval, &#91;<span class=\"hljs-number\">0<\/span> <span class=\"hljs-keyword\">if<\/span> x &lt; <span class=\"hljs-number\">0<\/span> <span class=\"hljs-keyword\">else<\/span> x <span class=\"hljs-keyword\">for<\/span> x in y - err], y+err, facecolor=<span class=\"hljs-string\">\"silver\"<\/span>)\n        plt.plot(interval, data, <span class=\"hljs-string\">\"r+\"<\/span>, label=<span class=\"hljs-string\">\"Cases: data\"<\/span>)\n        plt.plot(interval, y, <span class=\"hljs-string\">\"b\"<\/span>, label=f<span class=\"hljs-string\">\"Cases: model\"<\/span>)\n        plt.title(title)\n        plt.legend()\n    <span class=\"hljs-keyword\">return<\/span> opt_params\n\napply_model(exponential, (CASES&#91;<span class=\"hljs-number\">0<\/span>], <span class=\"hljs-number\">1<\/span>), INTERVAL, CASES, title=<span class=\"hljs-string\">\"Cases\"<\/span>)\napply_model(exponential, (DEATHS&#91;<span class=\"hljs-number\">0<\/span>], <span class=\"hljs-number\">1<\/span>), INTERVAL, DEATHS, title=<span class=\"hljs-string\">\"Deaths\"<\/span>)<\/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 class=\"eplus-7Uc1qn\">The output looks like this:<\/p>\n\n\n<pre class=\"wp-block-code eplus-CX48Qq\"><span><code class=\"hljs\">Optimal parameters: &#91;3.98032285e+03 9.36244642e-02]\nModel error = 77807.25\nOptimal parameters: &#91;7.91850070e-11 7.61280159e-01]\nModel error = 16721.72<\/code><\/span><\/pre>\n\n<div class=\"wp-block-image eplus-Ym0hAJ\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"617\" height=\"319\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/2.png\" alt=\"\" class=\"wp-image-4053\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/2.png 617w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/2-300x155.png 300w\" sizes=\"auto, (max-width: 617px) 100vw, 617px\" \/><\/figure><\/div>\n\n<div class=\"wp-block-image eplus-mrs6VQ\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"611\" height=\"319\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/3.png\" alt=\"\" class=\"wp-image-4054\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/3.png 611w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/3-300x157.png 300w\" sizes=\"auto, (max-width: 611px) 100vw, 611px\" \/><\/figure><\/div>\n\n\n<p class=\"eplus-HQCJys\">This result is bad (look at the <span id=\"urn:enhancement-1f08efb\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/errors_and_residuals_in_statistics\">errors<\/span> &#8211; the first thing to examine when <span id=\"urn:enhancement-3e6084f1\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/curve_fitting\">fitting<\/span> <span id=\"urn:enhancement-fcfb1a9\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span>). However, as we have already pointed out, these <span id=\"urn:enhancement-43e41578\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> seem to <span id=\"urn:enhancement-87e4109f\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/display_device\">display<\/span> an exponential behavior only from the 18th day or so onwards. If we cut both time series by dropping the initial values we get a better picture:<\/p>\n\n\n<pre class=\"wp-block-code eplus-MzBtAe\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">apply_model(exponential, (CASES&#91;<span class=\"hljs-number\">17<\/span>], <span class=\"hljs-number\">1<\/span>), INTERVAL&#91;<span class=\"hljs-number\">17<\/span>:], CASES&#91;<span class=\"hljs-number\">17<\/span>:], title=<span class=\"hljs-string\">\"Cases\"<\/span>)\napply_model(exponential, (DEATHS&#91;<span class=\"hljs-number\">17<\/span>], <span class=\"hljs-number\">1<\/span>), INTERVAL&#91;<span class=\"hljs-number\">17<\/span>:], DEATHS&#91;<span class=\"hljs-number\">17<\/span>:], title=<span class=\"hljs-string\">\"Deaths\"<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><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<p class=\"eplus-GyN4th\">And the results are:<\/p>\n\n\n<pre class=\"wp-block-code eplus-lwOc3d\"><span><code class=\"hljs\">Optimal parameters: &#91;4.94288955e+03 8.81173180e-02]\nModel error = 64453.74\nOptimal parameters: &#91;32.08823952  0.13596649]\nModel error = 2459.21<\/code><\/span><\/pre>\n\n<div class=\"wp-block-image eplus-3uRGrP\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"617\" height=\"319\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/4.png\" alt=\"\" class=\"wp-image-4055\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/4.png 617w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/4-300x155.png 300w\" sizes=\"auto, (max-width: 617px) 100vw, 617px\" \/><\/figure><\/div>\n\n<div class=\"wp-block-image eplus-aELVOE\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"611\" height=\"319\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/5.png\" alt=\"\" class=\"wp-image-4056\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/5.png 611w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/5-300x157.png 300w\" sizes=\"auto, (max-width: 611px) 100vw, 611px\" \/><\/figure><\/div>\n\n\n<p class=\"eplus-r9O77x\">These results seems to display a much better <span id=\"urn:enhancement-8eef18eb\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/curve_fitting\">fit<\/span>, but is that really the case? By plotting a single line we are, in some sense, cheating, since our model fits <span id=\"urn:enhancement-89847241\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> up to a point of error. It is better to plot this &#8216;error area&#8217; as a strip around the curves, which makes the (low) effectiveness of the <span id=\"urn:enhancement-5b92053c\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/epidemic\">epidemic<\/span> model clearer:<\/p>\n\n\n<pre class=\"wp-block-code eplus-sxmRes\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">apply_model(exponential, (CASES&#91;<span class=\"hljs-number\">17<\/span>], <span class=\"hljs-number\">1<\/span>), INTERVAL&#91;<span class=\"hljs-number\">17<\/span>:], CASES&#91;<span class=\"hljs-number\">17<\/span>:], title=<span class=\"hljs-string\">\"Cases\"<\/span>, shadow=<span class=\"hljs-keyword\">True<\/span>)\napply_model(exponential, (DEATHS&#91;<span class=\"hljs-number\">17<\/span>], <span class=\"hljs-number\">1<\/span>), INTERVAL&#91;<span class=\"hljs-number\">17<\/span>:], DEATHS&#91;<span class=\"hljs-number\">17<\/span>:], title=<span class=\"hljs-string\">\"Deaths\"<\/span>, shadow=<span class=\"hljs-keyword\">True<\/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<pre class=\"wp-block-code eplus-VxnQ6i\"><span><code class=\"hljs\">Optimal parameters: &#91;4.94288955e+03 8.81173180e-02]\nModel error = 64453.74\nOptimal parameters: &#91;32.08823952  0.13596649]\nModel error = 2459.21<\/code><\/span><\/pre>\n\n<div class=\"wp-block-image eplus-Ro8ExC\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"617\" height=\"319\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/6.png\" alt=\"\" class=\"wp-image-4057\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/6.png 617w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/6-300x155.png 300w\" sizes=\"auto, (max-width: 617px) 100vw, 617px\" \/><\/figure><\/div>\n\n<div class=\"wp-block-image eplus-tFtjZ5\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"611\" height=\"319\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/7.png\" alt=\"\" class=\"wp-image-4058\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/7.png 611w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/7-300x157.png 300w\" sizes=\"auto, (max-width: 611px) 100vw, 611px\" \/><\/figure><\/div>\n\n\n<p class=\"eplus-frQ6ad\">Now we can appreciate how coarse this modelling is!<\/p>\n\n\n\n<p class=\"eplus-NryGUt\">Even worse though, this &#8216;model&#8217; demonstrates a <span id=\"urn:enhancement-e5eb4773\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/trend_estimation\">trend<\/span> that makes no sense, since it <strong>keeps increasing exponentially forever<\/strong>. That would mean that both cases and deaths will continue to increase until they outnumber the total <span id=\"urn:enhancement-f97879e1\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/statistical_population\">population<\/span> of Earth!<\/p>\n\n\n\n<p class=\"eplus-0WYzR8\">This &#8216;<span id=\"urn:enhancement-2dcf9868\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span>&#8216; is just a bad <span id=\"urn:enhancement-fcb08bcc\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/curve_fitting\">fit<\/span> for some points on a curve and not a meaningful <span id=\"urn:enhancement-fe589aa0\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">predictive<\/span> <span id=\"urn:enhancement-2c4ecc14\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span>. To see this more clearly, let us imagine splitting our <span id=\"urn:enhancement-89ce975a\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> into a &#8216;<span id=\"urn:enhancement-52a45b83\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/training_set\">training set<\/span>&#8216; of 80% of all the <span id=\"urn:enhancement-ca2eec22\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> used to <span id=\"urn:enhancement-f51ca47c\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/calibration\">calibrate<\/span> the <span id=\"urn:enhancement-f8aa8f75\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/epidemic\">epidemic<\/span> <span id=\"urn:enhancement-9769eba5\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span>, and a &#8216;<span id=\"urn:enhancement-b84460fd\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/test_assessment\">testing<\/span> set&#8217; formed of the remaining 20%, which we will use to test <span id=\"urn:enhancement-d47dc047\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/performance\">performance<\/span>.<\/p>\n\n\n<pre class=\"wp-block-code eplus-wLm65J\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">i0 = (len(INTERVAL) * <span class=\"hljs-number\">4<\/span>) <span class=\"hljs-comment\">\/\/ 5<\/span>\nopt_param = apply_model(exponential, (CASES&#91;<span class=\"hljs-number\">17<\/span>], <span class=\"hljs-number\">1<\/span>), INTERVAL&#91;<span class=\"hljs-number\">17<\/span>:i0], CASES&#91;<span class=\"hljs-number\">17<\/span>:i0], disp=<span class=\"hljs-keyword\">False<\/span>)\ny = exponential(INTERVAL&#91;<span class=\"hljs-number\">18<\/span>:], opt_param)\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"Model error =\"<\/span>, np.linalg.norm(y - CASES&#91;<span class=\"hljs-number\">18<\/span>:]))\n\nplt.figure(figsize=(<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">5<\/span>))\nplt.plot(INTERVAL&#91;<span class=\"hljs-number\">18<\/span>:i0], CASES&#91;<span class=\"hljs-number\">18<\/span>:i0], <span class=\"hljs-string\">\"r+\"<\/span>, label=<span class=\"hljs-string\">\"Cases: training data\"<\/span>)\nplt.plot(INTERVAL&#91;i0:], CASES&#91;i0:], <span class=\"hljs-string\">\"y+\"<\/span>, label=<span class=\"hljs-string\">\"Cases: testing data\"<\/span>)\nplt.plot(INTERVAL&#91;<span class=\"hljs-number\">18<\/span>:], y, <span class=\"hljs-string\">\"b\"<\/span>, label=<span class=\"hljs-string\">\"Cases: model\"<\/span>)\nplt.legend()\n\nopt_param = apply_model(exponential, (DEATHS&#91;<span class=\"hljs-number\">17<\/span>], <span class=\"hljs-number\">1<\/span>), INTERVAL&#91;<span class=\"hljs-number\">17<\/span>:i0], DEATHS&#91;<span class=\"hljs-number\">17<\/span>:i0], disp=<span class=\"hljs-keyword\">False<\/span>)\ny = exponential(INTERVAL&#91;<span class=\"hljs-number\">18<\/span>:], opt_param)\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"Model error =\"<\/span>, np.linalg.norm(y - DEATHS&#91;<span class=\"hljs-number\">18<\/span>:]))\n\nplt.figure(figsize=(<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">5<\/span>))\nplt.plot(INTERVAL&#91;<span class=\"hljs-number\">18<\/span>:i0], DEATHS&#91;<span class=\"hljs-number\">18<\/span>:i0], <span class=\"hljs-string\">\"r+\"<\/span>, label=<span class=\"hljs-string\">\"Deaths: training data\"<\/span>)\nplt.plot(INTERVAL&#91;i0:], DEATHS&#91;i0:], <span class=\"hljs-string\">\"y+\"<\/span>, label=<span class=\"hljs-string\">\"Deaths: testing data\"<\/span>)\nplt.plot(INTERVAL&#91;<span class=\"hljs-number\">18<\/span>:], y, <span class=\"hljs-string\">\"b\"<\/span>, label=<span class=\"hljs-string\">\"Deaths: model\"<\/span>)\nplt.legend()<\/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<p class=\"eplus-PaIKUn\"> The result is the following:<\/p>\n\n\n<pre class=\"wp-block-code eplus-sQqwde\"><span><code class=\"hljs\">Model error = 352059.91670035594\nModel error = 26296.154926583255<\/code><\/span><\/pre>\n\n<div class=\"wp-block-image eplus-C648nT\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"617\" height=\"303\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/8.png\" alt=\"\" class=\"wp-image-4059\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/8.png 617w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/8-300x147.png 300w\" sizes=\"auto, (max-width: 617px) 100vw, 617px\" \/><\/figure><\/div>\n\n<div class=\"wp-block-image eplus-8Fg3B9\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"611\" height=\"307\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/9.png\" alt=\"\" class=\"wp-image-4060\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/9.png 611w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/9-300x151.png 300w\" sizes=\"auto, (max-width: 611px) 100vw, 611px\" \/><\/figure><\/div>\n\n\n<p class=\"eplus-17olxp\">Therefore, <strong>this <span id=\"urn:enhancement-b128c7bf\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> fits <span id=\"urn:enhancement-e1ddd111\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> (badly) but fails totally at making <span id=\"urn:enhancement-e130cd56\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">predictions<\/span><\/strong>, as far the cases curve is concerned. On the other hand, <span id=\"urn:enhancement-fe9d8dde\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/test_assessment\">testing<\/span> <span id=\"urn:enhancement-6224430\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> more or less <span id=\"urn:enhancement-34641ecf\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/curve_fitting\">fit<\/span> this <span id=\"urn:enhancement-bb2524d1\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/exponential_growth\">exponential curve<\/span>. However, it doesn&#8217;t need a <span id=\"urn:enhancement-a1892490\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/nobel_memorial_prize_in_economic_sciences\">Nobel prize winner<\/span> to understand that there is an upper boundary to the number of people in a population, and that the approach toward such a boundary is not exponential.<\/p>\n\n\n\n<p class=\"eplus-dCqL4l\">Let us explore that further with some maths, which is always needed at some point when dealing with models. We should use calculus, but let&#8217;s keep things simple &#8211; after all we are interested in points <em>C0, C1<\/em>,&#8230; along a curve, not the entire curve <em>C<\/em>(<em>t<\/em>). To recover the <span id=\"urn:enhancement-17132fb2\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/exponential_growth\">exponential curve<\/span> we observe that, in order to produce a time series of exponential type, the next point in the curve is the current point <em>Cn<\/em> plus an increment proportional to <em>Cn<\/em>. The equation that expresses this is<\/p>\n\n\n\n<p class=\"has-text-align-center eplus-7Q1SSZ\"><em>Cn+1 \u2212 Cn = c<sub>2<\/sub>Cn<\/em><\/p>\n\n\n\n<p class=\"eplus-V4JpmS\">We can use this definition to compute points on the curve <em>C<\/em>: when using exponential models, this is unnecessary (we know the function!), but it generally applies to other models, for example the <strong><span id=\"urn:local-annotation-202670\" class=\"textannotation disambiguated\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/logistic_regression_model\">logistic model<\/span><\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading eplus-uhuqRK\" id=\"h-logistic-modelling\">Logistic modelling<\/h3>\n\n\n\n<p class=\"eplus-Aa9pQy\">According to this model, growth in a part of a population follows the law:<\/p>\n\n\n\n<p class=\"has-text-align-center eplus-psNqUh\"><em>Cn+1 \u2013 Cn = c<sub>2<\/sub>Cn(N\u2212Cn)\/N<\/em><\/p>\n\n\n\n<p class=\"eplus-hceo3h\">with <em>N<\/em> being the total population. In this way <em>Cn<\/em> will not diverge as in the exponential series, but at a maximum will hit the <em>N<\/em> value (in which case the whole population is dead&#8230;). We can try to use this model to fit our data: more precisely we will model cases using the logistic model and deaths using the exponential model.<\/p>\n\n\n<pre class=\"wp-block-code eplus-aemQjG\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">N = <span class=\"hljs-number\">1e5<\/span>\n\ndef logistic(t, params):\n    <span class=\"hljs-keyword\">return<\/span> params&#91;<span class=\"hljs-number\">0<\/span>] \/(<span class=\"hljs-number\">1<\/span>+np.exp(-params&#91;<span class=\"hljs-number\">1<\/span>]*(t-params&#91;<span class=\"hljs-number\">2<\/span>])))\n\napply_model(logistic, (<span class=\"hljs-number\">2<\/span>*CASES&#91;<span class=\"hljs-number\">-1<\/span>], <span class=\"hljs-number\">1<\/span>, (INTERVAL&#91;<span class=\"hljs-number\">-1<\/span>]-INTERVAL&#91;<span class=\"hljs-number\">17<\/span>])\/<span class=\"hljs-number\">2<\/span>), INTERVAL&#91;<span class=\"hljs-number\">17<\/span>:], CASES&#91;<span class=\"hljs-number\">17<\/span>:], title=<span class=\"hljs-string\">\"Cases\"<\/span>, shadow=<span class=\"hljs-keyword\">True<\/span>)\napply_model(logistic, (<span class=\"hljs-number\">2<\/span>*DEATHS&#91;<span class=\"hljs-number\">-1<\/span>], <span class=\"hljs-number\">1<\/span>, (INTERVAL&#91;<span class=\"hljs-number\">-1<\/span>]-INTERVAL&#91;<span class=\"hljs-number\">17<\/span>])\/<span class=\"hljs-number\">2<\/span>), INTERVAL&#91;<span class=\"hljs-number\">17<\/span>:], DEATHS&#91;<span class=\"hljs-number\">17<\/span>:], title=<span class=\"hljs-string\">\"Deaths\"<\/span>, shadow=<span class=\"hljs-keyword\">True<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><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 class=\"eplus-WUrrt6\">Here are the results:<\/p>\n\n\n<pre class=\"wp-block-code eplus-Agfpyw\"><span><code class=\"hljs\">Optimal parameters: &#91;2.29810781e+05 1.83183796e-01 3.41548660e+01]\nModel error = 18468.12\nOptimal parameters: &#91;1.31533912e+04 2.41333621e-01 3.82790444e+01]\nModel error = 457.69<\/code><\/span><\/pre>\n\n<div class=\"wp-block-image eplus-1WHs7n\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"617\" height=\"319\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/10.png\" alt=\"\" class=\"wp-image-4061\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/10.png 617w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/10-300x155.png 300w\" sizes=\"auto, (max-width: 617px) 100vw, 617px\" \/><\/figure><\/div>\n\n<div class=\"wp-block-image eplus-HjrsVG\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"611\" height=\"319\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/11.png\" alt=\"\" class=\"wp-image-4062\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/11.png 611w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/11-300x157.png 300w\" sizes=\"auto, (max-width: 611px) 100vw, 611px\" \/><\/figure><\/div>\n\n\n<p class=\"eplus-WOz5ae\">This model seems to fit the curve of cases better, even if errors are still high for cases, as the grey strips show. The curve of deaths seems to be accurately modeled in this way. Moreover, we have to guess the total population number, which is a kind of &#8220;hyper-parameter&#8221; for this model. Let us split the dataset into two parts as before, with the first 80% of values used as a training set and the remaining values as a testing set.<\/p>\n\n\n<pre class=\"wp-block-code eplus-ZRp8dA\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">i0 = (len(INTERVAL) * <span class=\"hljs-number\">4<\/span>) <span class=\"hljs-comment\">\/\/ 5<\/span>\nopt_param = apply_model(logistic, (<span class=\"hljs-number\">2<\/span>*CASES&#91;<span class=\"hljs-number\">-1<\/span>], <span class=\"hljs-number\">1<\/span>, (INTERVAL&#91;<span class=\"hljs-number\">-1<\/span>]-INTERVAL&#91;<span class=\"hljs-number\">17<\/span>])\/<span class=\"hljs-number\">2<\/span>), INTERVAL&#91;<span class=\"hljs-number\">17<\/span>:i0], CASES&#91;<span class=\"hljs-number\">17<\/span>:i0], disp=<span class=\"hljs-keyword\">False<\/span>)\ny = logistic(INTERVAL&#91;<span class=\"hljs-number\">18<\/span>:], opt_param)\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"Model error =\"<\/span>, np.linalg.norm(y - CASES&#91;<span class=\"hljs-number\">18<\/span>:]))\n\nplt.figure(figsize=(<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">5<\/span>))\nplt.plot(INTERVAL&#91;<span class=\"hljs-number\">18<\/span>:i0], CASES&#91;<span class=\"hljs-number\">18<\/span>:i0], <span class=\"hljs-string\">\"r+\"<\/span>, label=<span class=\"hljs-string\">\"Cases: training data\"<\/span>)\nplt.plot(INTERVAL&#91;i0:], CASES&#91;i0:], <span class=\"hljs-string\">\"y+\"<\/span>, label=<span class=\"hljs-string\">\"Cases: testing data\"<\/span>)\nplt.plot(INTERVAL&#91;<span class=\"hljs-number\">18<\/span>:], y, <span class=\"hljs-string\">\"b\"<\/span>, label=<span class=\"hljs-string\">\"Cases: model\"<\/span>)\nplt.legend()\n\nopt_param = apply_model(logistic, (<span class=\"hljs-number\">2<\/span>*DEATHS&#91;<span class=\"hljs-number\">-1<\/span>], <span class=\"hljs-number\">1<\/span>, (INTERVAL&#91;<span class=\"hljs-number\">-1<\/span>]-INTERVAL&#91;<span class=\"hljs-number\">17<\/span>])\/<span class=\"hljs-number\">2<\/span>), INTERVAL&#91;<span class=\"hljs-number\">17<\/span>:i0], DEATHS&#91;<span class=\"hljs-number\">17<\/span>:i0], disp=<span class=\"hljs-keyword\">False<\/span>)\ny = logistic(INTERVAL&#91;<span class=\"hljs-number\">18<\/span>:], opt_param)\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"Model error =\"<\/span>, np.linalg.norm(y - DEATHS&#91;<span class=\"hljs-number\">18<\/span>:]))\n\nplt.figure(figsize=(<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">5<\/span>))\nplt.plot(INTERVAL&#91;<span class=\"hljs-number\">18<\/span>:i0], DEATHS&#91;<span class=\"hljs-number\">18<\/span>:i0], <span class=\"hljs-string\">\"r+\"<\/span>, label=<span class=\"hljs-string\">\"Deaths: training data\"<\/span>)\nplt.plot(INTERVAL&#91;i0:], DEATHS&#91;i0:], <span class=\"hljs-string\">\"y+\"<\/span>, label=<span class=\"hljs-string\">\"Deaths: testing data\"<\/span>)\nplt.plot(INTERVAL&#91;<span class=\"hljs-number\">18<\/span>:], y, <span class=\"hljs-string\">\"b\"<\/span>, label=<span class=\"hljs-string\">\"Deaths: model\"<\/span>)\nplt.legend()<\/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<p class=\"eplus-biTzer\">And here are the results:<\/p>\n\n\n<pre class=\"wp-block-code eplus-ueg9gw\"><span><code class=\"hljs\">Model error = 92466.50981544874\nModel error = 5404.289943307971<\/code><\/span><\/pre>\n\n<div class=\"wp-block-image eplus-IqSrqx\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"617\" height=\"303\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/12.png\" alt=\"\" class=\"wp-image-4063\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/12.png 617w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/12-300x147.png 300w\" sizes=\"auto, (max-width: 617px) 100vw, 617px\" \/><\/figure><\/div>\n\n<div class=\"wp-block-image eplus-e1uh3u\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"611\" height=\"303\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/13.png\" alt=\"\" class=\"wp-image-4064\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/13.png 611w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/13-300x149.png 300w\" sizes=\"auto, (max-width: 611px) 100vw, 611px\" \/><\/figure><\/div>\n\n\n<p class=\"eplus-mYQN4i\">Errors are still very high, but the trend of actual cases seems to be qualitatively like the model curve (although the modelling of the deaths curve is clearly wrong!).<\/p>\n\n\n\n<p class=\"eplus-LESuyJ\">In fact, notwithstanding what can be read on the Web, <strong>these models are too simple to have any predictive value<\/strong> &#8211; people using them to model epidemic spreads are largely wasting their time.<\/p>\n\n\n\n<p class=\"eplus-AYBtpW\">To get more accurate models, one has to modify the increment appropriately for different curves. For example, the following two increment equations are inspired by the so-called <strong><span id=\"urn:local-annotation-391205\" class=\"textannotation disambiguated\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/sir_model\">SIR model<\/span><\/strong> (which is the simplest model used in epidemiology):<\/p>\n\n\n\n<p class=\"has-text-align-center eplus-XZ7O6p\"><em>Cn+1 = Cn+c<sub>2<\/sub>Cn(N \u2013 Cn \u2212 Dn)\/N \u2212 d2Cn<\/em><\/p>\n\n\n\n<p class=\"has-text-align-center eplus-glyAkt\"><em>Dn+1 = Dn + d<sub>2<\/sub>Cn&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/em><\/p>\n\n\n\n<p class=\"eplus-uxZYds\">In this way we take deaths into account and remove them from cases. The population is split into three parts: infected (I), dead (D) and all the rest (R), and the equations are not independent but related.<\/p>\n\n\n\n<p class=\"eplus-y2s7RG\">In a true SIR model we should model infected (I), dead(D) or healed people (R, for retired), and people susceptible to be infected (S), but these data are missing from our dataset (and are in any case usually very difficult to measure). The idea of SIR is that while the virus spreads, population S decreases, while both I and R increases: I attains a maximum and starts decreasing, while R keeps increasing.<\/p>\n\n\n\n<p class=\"eplus-kYPDGz\">There are more sophisticated epidemic models such as <strong>SEIR<\/strong>, <strong>MSEIR<\/strong>, etc. which divide the population into different parts and model the growth of the population in each part: these are the standard deterministic models of epidemiology. Nonetheless, the results of a simulation across 100 days of our new model follow.<\/p>\n\n\n<pre class=\"wp-block-code eplus-PL5RRD\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">import matplotlib.pyplot <span class=\"hljs-keyword\">as<\/span> plt\nimport numpy <span class=\"hljs-keyword\">as<\/span> np\nfrom scipy.optimize import fmin\n\ninterval = range(len(NY_DATA))\n\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\nN = <span class=\"hljs-number\">0.5e6<\/span>\n\ndef IDR(t, c1, c2, d1, d2):\n    <span class=\"hljs-keyword\">if<\/span> not isinstance(t, float) <span class=\"hljs-keyword\">and<\/span> not isinstance(t, int):\n        <span class=\"hljs-keyword\">return<\/span> np.<span class=\"hljs-keyword\">array<\/span>(&#91;IDR(i, c1, c2, d1, d2) <span class=\"hljs-keyword\">for<\/span> i in t])\n    <span class=\"hljs-keyword\">if<\/span> t == <span class=\"hljs-number\">0<\/span>:\n        <span class=\"hljs-keyword\">return<\/span> np.<span class=\"hljs-keyword\">array<\/span>(&#91;c1, d1])\n    ft_1 = IDR(t<span class=\"hljs-number\">-1<\/span>, c1, c2, d1, d2)\n    ct_1 = ft_1&#91;<span class=\"hljs-number\">0<\/span>]\n    dt_1 = ft_1&#91;<span class=\"hljs-number\">1<\/span>]\n    <span class=\"hljs-keyword\">return<\/span> np.<span class=\"hljs-keyword\">array<\/span>(&#91;ct_1 + c2*ct_1*(N - ct_1 - dt_1)\/N - d2*ct_1, dt_1+d2*ct_1])\n\ndef calibration(interval, C, D):\n    CD = np.<span class=\"hljs-keyword\">array<\/span>(&#91;&#91;C&#91;i], D&#91;i]] <span class=\"hljs-keyword\">for<\/span> i in range(len(C))])\n    <span class=\"hljs-keyword\">return<\/span> fmin(lambda params: np.linalg.norm(IDR(interval, params&#91;<span class=\"hljs-number\">0<\/span>], params&#91;<span class=\"hljs-number\">1<\/span>], params&#91;<span class=\"hljs-number\">2<\/span>], params&#91;<span class=\"hljs-number\">3<\/span>]) - CD), (C&#91;<span class=\"hljs-number\">0<\/span>],<span class=\"hljs-number\">1<\/span>,D&#91;<span class=\"hljs-number\">0<\/span>],<span class=\"hljs-number\">1<\/span>), disp = <span class=\"hljs-keyword\">False<\/span>)\n\nbig_interval = range(<span class=\"hljs-number\">100<\/span>)\nc1, c2, d1, d2 = calibration(interval, CASES, DEATHS)\nfit = IDR(big_interval, c1, c2, d1, d2)\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\">5<\/span>), sharey=<span class=\"hljs-string\">'all'<\/span>)\naxes&#91;<span class=\"hljs-number\">0<\/span>].plot(interval, CASES, <span class=\"hljs-string\">\"r+\"<\/span>, label=<span class=\"hljs-string\">\"Cases: data\"<\/span>)\naxes&#91;<span class=\"hljs-number\">0<\/span>].plot(big_interval, fit&#91;:,<span class=\"hljs-number\">0<\/span>], <span class=\"hljs-string\">\"b\"<\/span>, label=f<span class=\"hljs-string\">\"Cases: C(t)\"<\/span>)\naxes&#91;<span class=\"hljs-number\">0<\/span>].legend()\naxes&#91;<span class=\"hljs-number\">1<\/span>].plot(interval, DEATHS, <span class=\"hljs-string\">\"r+\"<\/span>, label=<span class=\"hljs-string\">\"Deaths: data\"<\/span>)\naxes&#91;<span class=\"hljs-number\">1<\/span>].plot(big_interval, fit&#91;:,<span class=\"hljs-number\">1<\/span>], <span class=\"hljs-string\">\"b\"<\/span>, label=f<span class=\"hljs-string\">\"Deaths: D(t)\"<\/span>)\naxes&#91;<span class=\"hljs-number\">1<\/span>].legend()\n\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"Error for D(t) =\"<\/span>, np.linalg.norm(fit&#91;:len(interval),<span class=\"hljs-number\">0<\/span>] - CASES))\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"Error for D(t) =\"<\/span>, np.linalg.norm(fit&#91;:len(interval),<span class=\"hljs-number\">1<\/span>] - DEATHS))<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><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 class=\"eplus-KcnLlQ\">The output is:<\/p>\n\n\n<pre class=\"wp-block-code eplus-C0slQj\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-built_in\">Error<\/span> <span class=\"hljs-keyword\">for<\/span> D(t) = <span class=\"hljs-number\">55277.27002540128<\/span>\n<span class=\"hljs-built_in\">Error<\/span> <span class=\"hljs-keyword\">for<\/span> D(t) = <span class=\"hljs-number\">6128.543579522949<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><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<div class=\"wp-block-image eplus-gn6EDo\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"618\" height=\"303\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/14.png\" alt=\"\" class=\"wp-image-4065\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/14.png 618w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/14-300x147.png 300w\" sizes=\"auto, (max-width: 618px) 100vw, 618px\" \/><\/figure><\/div>\n\n\n<p class=\"eplus-Dq9mOo\">Let us split the data set in two series as before, using the first half as a training set and the second half as a testing set.<\/p>\n\n\n<pre class=\"wp-block-code eplus-WMi1Bu\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">fig, 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\">5<\/span>))\n\ntraining_interval = interval&#91;:len(interval)*<span class=\"hljs-number\">4<\/span><span class=\"hljs-comment\">\/\/5]<\/span>\ntesting_first = len(training_interval)\n\n<span class=\"hljs-comment\"># Calibrate parameters for modelling the cases<\/span>\ntraining_cases = CASES&#91;:len(interval)*<span class=\"hljs-number\">4<\/span><span class=\"hljs-comment\">\/\/5]<\/span>\ntraining_deaths = DEATHS&#91;:len(interval)*<span class=\"hljs-number\">4<\/span><span class=\"hljs-comment\">\/\/5]<\/span>\nc1, c2, d1, d2 = calibration(training_interval, training_cases, training_deaths)\nfit = IDR(interval, c1, c2, d1, d2)\naxes&#91;<span class=\"hljs-number\">0<\/span>].plot(training_interval, training_cases, <span class=\"hljs-string\">\"r+\"<\/span>, label=<span class=\"hljs-string\">\"Cases: training data\"<\/span>)\naxes&#91;<span class=\"hljs-number\">0<\/span>].plot(interval&#91;testing_first:], CASES&#91;testing_first:], <span class=\"hljs-string\">\"y+\"<\/span>, label=<span class=\"hljs-string\">\"Cases: testing data\"<\/span>)\naxes&#91;<span class=\"hljs-number\">0<\/span>].plot(interval, fit&#91;:,<span class=\"hljs-number\">0<\/span>], <span class=\"hljs-string\">\"b\"<\/span>, label=<span class=\"hljs-string\">\"Cases: model C(t)\"<\/span>)\naxes&#91;<span class=\"hljs-number\">0<\/span>].legend()\n\n<span class=\"hljs-comment\"># Calibrate parameters for modelling the cases<\/span>\naxes&#91;<span class=\"hljs-number\">1<\/span>].plot(training_interval, training_deaths, <span class=\"hljs-string\">\"r+\"<\/span>, label=<span class=\"hljs-string\">\"Deaths: training data\"<\/span>)\naxes&#91;<span class=\"hljs-number\">1<\/span>].plot(interval&#91;testing_first:], DEATHS&#91;testing_first:], <span class=\"hljs-string\">\"y+\"<\/span>, label=<span class=\"hljs-string\">\"Deaths: testing data\"<\/span>)\naxes&#91;<span class=\"hljs-number\">1<\/span>].plot(interval, fit&#91;:,<span class=\"hljs-number\">1<\/span>], <span class=\"hljs-string\">\"b\"<\/span>, label=<span class=\"hljs-string\">\"Deaths: model D(t)\"<\/span>)\naxes&#91;<span class=\"hljs-number\">1<\/span>].legend()\n\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"Error for C(t) =\"<\/span>, np.linalg.norm(fit&#91;:,<span class=\"hljs-number\">0<\/span>] - CASES))\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"Error for D(t) =\"<\/span>, np.linalg.norm(fit&#91;:,<span class=\"hljs-number\">1<\/span>] - DEATHS))<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><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 class=\"eplus-CCaUi8\">Again, the result is definitely not satisfactory&#8230;<\/p>\n\n\n<pre class=\"wp-block-code eplus-yzBlk5\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-built_in\">Error<\/span> <span class=\"hljs-keyword\">for<\/span> C(t) = <span class=\"hljs-number\">184506.22085618484<\/span>\n<span class=\"hljs-built_in\">Error<\/span> <span class=\"hljs-keyword\">for<\/span> D(t) = <span class=\"hljs-number\">2511.425471089619<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><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<div class=\"wp-block-image eplus-5QBhFX\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"617\" height=\"303\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/15.png\" alt=\"\" class=\"wp-image-4051\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/15.png 617w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/15-300x147.png 300w\" sizes=\"auto, (max-width: 617px) 100vw, 617px\" \/><\/figure><\/div>\n\n\n<p class=\"eplus-KgerXR\">As we see, the logistic model overestimates the increase of the cases curve, but more or less predicts the trend of the deaths curve.<\/p>\n\n\n\n<h2 class=\"wp-block-heading eplus-GbMtqd\" id=\"h-remarks-on-epidemic-model-parameters-learning\">Remarks on epidemic model parameters learning<\/h2>\n\n\n\n<p class=\"eplus-uNxYdG\">We didn&#8217;t succeed in finding a model to predict our data, but we learned some useful lessons:<\/p>\n\n\n\n<ol class=\"eplus-zm87FV wp-block-list\">\n<li>Simple models <strong>may fit<\/strong> available data but are <strong>not reliable ways to predict<\/strong> anything<\/li>\n\n\n\n<li>Models are often chosen according to the available data: we did this and we failed. Honestly, New York Times data are not suitable for any interesting analysis, and we would be better to look for more complete data, i.e., including the number of healed people, etc.<\/li>\n\n\n\n<li>To train a &#8220;parametric model&#8221; is easy and is a <strong>simple form of <span id=\"urn:local-annotation-459961\" class=\"textannotation disambiguated\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/machine_learning\">machine learning<\/span><\/strong>: the difference with more advanced techniques is that here we pretend that the model follows a <strong>deterministic rule<\/strong> (the function we used to fit it: exponential, logistic, our toy model or a more realistic function as SIR, SEIR, etc.)<\/li>\n\n\n\n<li>Models that are not randomly chosen but are instead built <strong>relying upon epidemiological knowledge<\/strong> should be privileged, but finding the data needed to feed them may be challenging<\/li>\n<\/ol>\n\n\n\n<p class=\"eplus-UWCR3P\">Actual machine learning models do not pretend to shape <em><span class=\"eplus-icon\">a priori <\/span><\/em>data inside a deterministic curve: instead, they create a black-box model which, when given input simply provides output. <strong>Neural networks<\/strong> are like that and we will touch on some points about these in a <a href=\"https:\/\/www.codemotion.com\/magazine\/dev-hub\/machine-learning-dev\/epidemic-intelligence-part-2-data-models-and-machine-learning-in-the-age-of-coronavirus\/\" class=\"ek-link\">subsequent article<\/a> about how to apply them to model our data.<\/p>\n\n\n","protected":false},"excerpt":{"rendered":"<p>The current global emergency due to the spread of the coronavirus in several countries shows how fragile our society&#8217;s equilibrium is when faced with &#8216;interior&#8217; threats such as an epidemic. Treatments to relieve symptoms and a vaccine will eventually be found, but in the meantime humankind seems to be helpless against the virus. The only&#8230; <a class=\"more-link\" href=\"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-data-models-and-machine-learning-in-the-age-of-coronavirus\/\">Read more<\/a><\/p>\n","protected":false},"author":5,"featured_media":4066,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_editorskit_title_hidden":false,"_editorskit_reading_time":12,"_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,68],"collections":[],"class_list":{"0":"post-4050","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-python","12":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v26.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Epidemic Models: AI in the age of Coronavirus - Codemotion Magazine<\/title>\n<meta name=\"description\" content=\"In this article, we demonstrate how to implement basic epidemic models to reflect on the risks of computer scientists dealing with viruses and epidemic data.\" \/>\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-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 1: data, models and machine learning in the age of Coronavirus\" \/>\n<meta property=\"og:description\" content=\"In this article, we demonstrate how to implement basic epidemic models to reflect on the risks of computer scientists dealing with viruses and epidemic data.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-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-04-18T14:13:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-30T13:33:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\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=\"15 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-data-models-and-machine-learning-in-the-age-of-coronavirus\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-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 1: data, models and machine learning in the age of Coronavirus\",\"datePublished\":\"2020-04-18T14:13:00+00:00\",\"dateModified\":\"2023-05-30T13:33:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-data-models-and-machine-learning-in-the-age-of-coronavirus\/\"},\"wordCount\":2015,\"publisher\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-data-models-and-machine-learning-in-the-age-of-coronavirus\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_.jpg\",\"keywords\":[\"Big Data\",\"Coronavirus\",\"Data Analysis\",\"Python\"],\"articleSection\":[\"Machine Learning\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-data-models-and-machine-learning-in-the-age-of-coronavirus\/\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-data-models-and-machine-learning-in-the-age-of-coronavirus\/\",\"name\":\"Epidemic Models: AI 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-data-models-and-machine-learning-in-the-age-of-coronavirus\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-data-models-and-machine-learning-in-the-age-of-coronavirus\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_.jpg\",\"datePublished\":\"2020-04-18T14:13:00+00:00\",\"dateModified\":\"2023-05-30T13:33:35+00:00\",\"description\":\"In this article, we demonstrate how to implement basic epidemic models to reflect on the risks of computer scientists dealing with viruses and epidemic data.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-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-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-data-models-and-machine-learning-in-the-age-of-coronavirus\/#primaryimage\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_.jpg\",\"contentUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_.jpg\",\"width\":1200,\"height\":720,\"caption\":\"coronavirus data\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-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 1: 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:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/image\/\",\"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":"Epidemic Models: AI in the age of Coronavirus - Codemotion Magazine","description":"In this article, we demonstrate how to implement basic epidemic models to reflect on the risks of computer scientists dealing with viruses and epidemic data.","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-data-models-and-machine-learning-in-the-age-of-coronavirus\/","og_locale":"en_US","og_type":"article","og_title":"Epidemic Intelligence, part 1: data, models and machine learning in the age of Coronavirus","og_description":"In this article, we demonstrate how to implement basic epidemic models to reflect on the risks of computer scientists dealing with viruses and epidemic data.","og_url":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-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-04-18T14:13:00+00:00","article_modified_time":"2023-05-30T13:33:35+00:00","og_image":[{"width":1200,"height":720,"url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_.jpg","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":"15 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-data-models-and-machine-learning-in-the-age-of-coronavirus\/#article","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-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 1: data, models and machine learning in the age of Coronavirus","datePublished":"2020-04-18T14:13:00+00:00","dateModified":"2023-05-30T13:33:35+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-data-models-and-machine-learning-in-the-age-of-coronavirus\/"},"wordCount":2015,"publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-data-models-and-machine-learning-in-the-age-of-coronavirus\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_.jpg","keywords":["Big Data","Coronavirus","Data Analysis","Python"],"articleSection":["Machine Learning"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-data-models-and-machine-learning-in-the-age-of-coronavirus\/","url":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-data-models-and-machine-learning-in-the-age-of-coronavirus\/","name":"Epidemic Models: AI 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-data-models-and-machine-learning-in-the-age-of-coronavirus\/#primaryimage"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-data-models-and-machine-learning-in-the-age-of-coronavirus\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_.jpg","datePublished":"2020-04-18T14:13:00+00:00","dateModified":"2023-05-30T13:33:35+00:00","description":"In this article, we demonstrate how to implement basic epidemic models to reflect on the risks of computer scientists dealing with viruses and epidemic data.","breadcrumb":{"@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-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-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-data-models-and-machine-learning-in-the-age-of-coronavirus\/#primaryimage","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_.jpg","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_.jpg","width":1200,"height":720,"caption":"coronavirus data"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/epidemic-intelligence-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 1: 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:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/image\/","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\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_-600x400.jpg","featured_image_src_square":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_-600x600.jpg","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\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_.jpg",1200,720,false],"thumbnail":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_-150x150.jpg",150,150,true],"medium":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_-300x180.jpg",300,180,true],"medium_large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_-768x461.jpg",768,461,true],"large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_-1024x614.jpg",1024,614,true],"1536x1536":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_.jpg",1200,720,false],"2048x2048":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_.jpg",1200,720,false],"small-home-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_.jpg",100,60,false],"sidebar-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_-180x128.jpg",180,128,true],"genesis-singular-images":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_-896x504.jpg",896,504,true],"archive-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_-400x225.jpg",400,225,true],"gb-block-post-grid-landscape":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_-600x400.jpg",600,400,true],"gb-block-post-grid-square":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/1585083010251.jpg-coronavirus___la_metodologia_data_driven_per_capire_come_va_davvero_le_cose_-600x600.jpg",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":"The current global emergency due to the spread of the coronavirus in several countries shows how fragile our society&#8217;s equilibrium is when faced with &#8216;interior&#8217; threats such as an epidemic. Treatments to relieve symptoms and a vaccine will eventually be found, but in the meantime humankind seems to be helpless against the virus. The only&#8230;&hellip;","lang":"en","_links":{"self":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/4050","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=4050"}],"version-history":[{"count":15,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/4050\/revisions"}],"predecessor-version":[{"id":21033,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/4050\/revisions\/21033"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media\/4066"}],"wp:attachment":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media?parent=4050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/categories?post=4050"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/tags?post=4050"},{"taxonomy":"collections","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/collections?post=4050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}