<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vinayak Bhakta on Medium]]></title>
        <description><![CDATA[Stories by Vinayak Bhakta on Medium]]></description>
        <link>https://medium.com/@xmenplus?source=rss-8913d039811------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*W9lP4dCi2T6BZ03Qn7v9OA.png</url>
            <title>Stories by Vinayak Bhakta on Medium</title>
            <link>https://medium.com/@xmenplus?source=rss-8913d039811------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 02:42:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@xmenplus/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Covid-19 Outbreak Part 1 - Analyzing Seemingly Unrelated Feature Importance Using ML/AI.]]></title>
            <link>https://medium.com/@xmenplus/covid-19-outbreak-part-1-analyzing-seemingly-unrelated-feature-importance-using-ml-ai-943db7bda303?source=rss-8913d039811------2</link>
            <guid isPermaLink="false">https://medium.com/p/943db7bda303</guid>
            <category><![CDATA[coronavirus]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[feature-importance]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Vinayak Bhakta]]></dc:creator>
            <pubDate>Thu, 02 Apr 2020 11:40:48 GMT</pubDate>
            <atom:updated>2020-04-04T07:10:01.513Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VfjV6UPPDMk0T3yp" /><figcaption><em>Photo by </em><a href="https://unsplash.com/@fusion_medical_animation?utm_source=medium&amp;utm_medium=referral"><em>Fusion Medical Animation</em></a><em> on </em><a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral"><em>Unsplash</em></a></figcaption></figure><p>Coronavirus disease (COVID-19)<em> </em>is an infectious disease <em>caused by a newly discovered coronavirus. The onset of the virus happened in Nov 2019 in Wuhan, China but has from then spread from its epicenter to most of the countries around the world. The virus varies from its SARS predecessor having significantly higher rate of infection and fatality rate. Worldwide medical communities, pharma companies and even data scientists are </em>conscientiously working <em>to discover patterns related to the anatomy of the virus, methods of infections, reasons for the uneven spread/rate of infections and factors for high mortality rate.</em></p><p><em>Even though now many things are collectively agreed upon, the grossly uneven number of cases and deaths across the world brings into question if we truly understand the virus to the extend we should. Also the data science community is largely focusing on related features but leaving aspects which might have an impact but not that intuitive. For example does country specific factors such as GDP, unemployment rate, food consumption patterns, refugees, urban population, internet/mobile subscribers etc have any impact making a specific country more susceptible to fatality than others. While we know age is a factor but can there be hidden reasons which are not very intuitive but still have a correlation to the severity of the impact on specific countries.</em></p><p><em>I took a divergent view and built a model which attempts to discover and explore seemingly unrelated features &amp; assesses its importance to the number of Coronavirus Cases and Deaths across the globe.</em></p><p><em>In </em>Covid-19 Outbreak Part 1<em>, I will create a simple model to analyze which features are dominant and have a higher importance to the number of Coronavirus cases and deaths. The focus would be purely on importance and not on severity or reason of the relation. The intensity or the polarity will be construed in Part 2. Also the features would be purely based on country characteristics which gets assessed periodically by world bodies. Let jump directly to the model now.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1-hyF5y4FKQt4E4G" /><figcaption>Photo by <a href="https://unsplash.com/@max_duz?utm_source=medium&amp;utm_medium=referral">Max Duzij</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><em>I am using Python as my core language for this analysis and I will start by importing all the standard and specific libraries which are needed. The library list includes standard imports, stats imports and plot imports. I have also added regular expression and datetime library for specific data updates.</em></p><pre><em>#Standard Import<br>import pandas as pd<br>import numpy as np<br>from pandas import DataFrame, Series<br>from numpy.random import randn<br> <br>#Stats Import<br>from scipy import stats<br>import sklearn<br>from sklearn.datasets import load_boston</em></pre><pre><em>#Plots Import<br>import matplotlib as mpl<br>from matplotlib import pyplot as plt<br>import seaborn as sns<br>import plotly as pl<br>from plotly.offline import download_plotlyjs,init_notebook_mode,plot,iplot<br>init_notebook_mode(connected=True)<br>import cufflinks as cf<br>cf.go_offline()</em></pre><pre><em>#Other Imports<br>import re<br></em>import datetime</pre><p><em>First I will get the latest coronavirus cases data from the official European Centre for Disease Prevention and Control website.</em></p><p><a href="https://www.ecdc.europa.eu/">Homepage | European Centre for Disease Prevention and Control</a></p><p><em>We are using the read csv method which is available in Pandas library for reading the daily coronavirus cases and deaths. This csv contains the day by day count of Coronavirus cases and deaths for all countries around the world.</em></p><pre><em>url = &quot;https://opendata.ecdc.europa.eu/covid19/casedistribution/csv&quot;<br>Casesdf = pd.read_csv(url, encoding=&#39;ISO-8859-1&#39;)<br>Casesdf = Casesdf.rename(columns={&#39;countriesAndTerritories&#39;: &#39;Country&#39;})<br>Casesdf = Casesdf.drop(&#39;popData2018&#39;, axis=1)<br>Casesdf[&#39;dateRep&#39;] = pd.to_datetime(Casesdf[&#39;dateRep&#39;])</em></pre><pre><em>def replaceus(country):<br>      str = re.sub(r&#39;[\W_]&#39;,&#39; &#39;, country)<br>      return(str)</em></pre><pre><em>Casesdf[&#39;CountryNew&#39;] = Casesdf[&#39;Country&#39;].apply(replaceus)<br>Casesdf = Casesdf.drop(&#39;Country&#39;, axis=1)<br>Casesdf = Casesdf.rename(columns={&#39;CountryNew&#39;:&#39;Country&#39;})</em></pre><p><em>Next i research the UN data for statistics on countries with respect to to their surface area, population, sex ratio, GDP, economic indicators, employment figures, trade, food production index, age, education, mobile/internet usage, number species under threat, forest areas etc. I am only focusing on a total of 50 features which i found work assessing. I call this the World DataFrame.</em></p><p><a href="https://www.un.org/en/">United Nations | Peace, dignity and equality on a healthy planet</a></p><p><em>Next I also procure UN data on meat consumption by country by type (Mutton, Poultry, Pig, Beef, Total &amp; Others). I want to observe if meat consumption patterns of specific countries have an impact on the number of cases or deaths.</em></p><pre><em>url = &quot;</em><a href="https://github.com/vinayakbhakta9/Coronavirus/blob/master/Covid19CasesNew.xlsx?raw=true"><em>https://github.com/vinayakbhakta9/Coronavirus/blob/master/Covid19CasesNew.xlsx?raw=true</em></a><em>&quot;<br>Worlddf = pd.read_excel(url,sheet_name=&#39;World&#39;)<br>Worlddf.info()</em></pre><pre><em>url = &quot;</em><a href="https://github.com/vinayakbhakta9/Coronavirus/blob/master/WorldPoultry.xlsx?raw=true"><em>https://github.com/vinayakbhakta9/Coronavirus/blob/master/WorldPoultry.xlsx?raw=true</em></a><em>&quot;<br>Meetdf = pd.read_excel(url,sheet_name=&#39;Sheet1&#39;)<br>Meetdf.info()</em></pre><p><em>The next series of steps is basically to update the World Data Frame with case related attributes like Age (Duration), No of Cases and No of Deaths and also all attributes of meat consumption characteristics.</em></p><pre><em>#Calculating Age of the virus in the respective country and rank orders then picks rank 1<br>CasedfFil = Casesdf[Casesdf[&#39;cases&#39;]&gt;0]<br>Cdfgr1 = CasedfFil.groupby(&#39;Country&#39;)<br>CasedfFil[&#39;Rn&#39;] = Cdfgr1[&#39;dateRep&#39;].rank(method=&#39;min&#39;)<br>CasedfFil = CasedfFil[CasedfFil[&#39;Rn&#39;]==1]</em></pre><pre><em>#age calculation<br></em>def today_date():<br>    date=datetime.datetime.now().date()<br>    date=pd.to_datetime(date)<br>    return date</pre><pre>CasedfFil[&#39;Today&#39;] = today_date()<br><em>CasedfFil[&#39;Diff&#39;] = CasedfFil[&#39;Today&#39;] - CasedfFil[&#39;dateRep&#39;]</em></pre><pre><em>#joining with the world df<br>CasedfFil = CasedfFil[[&#39;Country&#39;, &#39;Diff&#39;]]<br>Worlddf = Worlddf.join(CasedfFil.set_index(&#39;Country&#39;), on=&#39;Country&#39;)<br>Worlddf[&#39;Age&#39;] = pd.to_numeric(Worlddf[&#39;Diff&#39;].dt.days, downcast=&#39;integer&#39;)<br>Worlddf = Worlddf.drop(&#39;Diff&#39;, axis=1)</em></pre><pre><em>#Adding Count of Cases and Count of deaths in Worlf df<br>Casedfcd = Casesdf.groupby([&#39;Country&#39;]).sum()<br>Casedfcd = Casedfcd.drop([&#39;day&#39;,&#39;month&#39;,&#39;year&#39;], axis=1)<br>Worlddf = Worlddf.join(Casedfcd, on=&#39;Country&#39;)</em></pre><pre><em>#joining with the meet df<br>Worlddf = Worlddf.join(Meetdf.set_index(&#39;Entity&#39;), on=&#39;Country&#39;)</em></pre><p><em>The final World DataFrame which now contains 59 attributes is used for this study. The source of data being reliable, the data can be considered clean and processed. The only two cleaning tasks to make the data useful for modeling are removal of nulls and purging the infinities which can be done as follows:-</em></p><pre><em>Worlddf.replace([np.inf, -np.inf], np.nan, inplace=True)<br>Worlddf.fillna(0, inplace=True)</em></pre><p><em>The next section is where I use the ML/AI technique. I am using random forest which is the most popular machine learning method, thanks to its relatively good accuracy, robustness and ease of use. I use mean decrease impurity method of feature selection where every node in the decision trees is a condition on a single feature, designed to split the data set into two so that similar response values end up in the same set. The measure based on which the (locally) optimal condition is chosen is called impurity.</em></p><p><em>I run the random forest model twice once with target variable as number of deaths to see which features have importance on mortality rate and then in the second run i keep the target variable as number of cases. The below code runs the model with target variable as number of deaths.</em></p><pre>from sklearn.ensemble import RandomForestRegressor<br>dfn=Worlddf.drop([‘Country’,’Region’,’cases’,’deaths’], axis=1)<br>lsd=Worlddf[‘deaths’]<br>lsd=pd.get_dummies(lsd)<br>model = RandomForestRegressor(random_state=1, max_depth=10)<br>dfn=pd.get_dummies(dfn)<br>model.fit(dfn,lsd)<br>features = dfn.columns<br>importances = model.feature_importances_<br>indices = np.argsort(importances)[-18:] # top 10 features<br>plt.title(‘Feature Importances by Deaths’)<br>plt.barh(range(len(indices)), importances[indices], color=’g’, align=’center’)<br>plt.yticks(range(len(indices)), [features[i] for i in indices])<br>plt.xlabel(‘Relative Importance’)<br>plt.show()<br>compdf = pd.DataFrame( {“Column”: dfn.columns, “importance”: importances}).sort_values(‘importance’, ascending=False)</pre><p><em>Based upon the above model, we get feature importance of the top 18 features relevant to the count of deaths.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*1-qoLhDiNvl5DiBYnyz6TA.png" /></figure><p>In the top 18 list, features such as <strong>No of Physicians per 1000 Patients, Life Expectancy Males</strong> are pretty intuitive<strong> </strong>and collectively understood<strong> </strong>but others which are seemingly unrelated are as follows. I have tried to link the feature to an assumed explanation as follows:-</p><p>• GDP — Economic activity may impact spread &amp; deaths<br> • Industry Percent Employed — Higher industrial emission exposure<br> • International Trade Exports- Easier spread between two countries<br> • Refugees — Poor living and health conditions might increase fatality <br> • Labor Force Male — Gender based infection probability<br> • International Trade Imports — Easier spread between countries<br> • No of Mobile Subscription — Well informed population/better facilities<br> • Urban Population Percent- Faster virus spread due to dense population.<br> • No of Internet Subscription — Well informed population/better facilities<br> • Poultry Consumption — High calorie diet/unhealthy breeding techniques<br> • Mutton Consumption — High calorie diet/unhealthy breeding techniques<br> • Labor Force Female — Gender based infection probability<br> • Unemployed Percent — Poor living and health conditions. <br> • %GDP Expenditure Education — Educated population means good controls<br> • No of Threatened Species — Better animal welfare policies<br> • International Trade Balance — Easier spread between countries</p><p><em>The below code runs the model with target variable as number of cases:-</em></p><pre>from sklearn.ensemble import RandomForestRegressor<br>dfn=Worlddf.drop([&#39;Country&#39;,&#39;Region&#39;,&#39;cases&#39;,&#39;deaths&#39;], axis=1)<br>lsd=Worlddf[&#39;cases&#39;]<br>lsd=pd.get_dummies(lsd)<br>model = RandomForestRegressor(random_state=1, max_depth=10)<br>dfn=pd.get_dummies(dfn)<br>model.fit(dfn,lsd)</pre><pre>features = dfn.columns<br>importances = model.feature_importances_<br>indices = np.argsort(importances)[-20:]  # top 20 features<br>plt.title(&#39;Feature Importances by Cases&#39;)<br>plt.barh(range(len(indices)), importances[indices], color=&#39;b&#39;, align=&#39;center&#39;)<br>plt.yticks(range(len(indices)), [features[i] for i in indices])<br>plt.xlabel(&#39;Relative Importance&#39;)<br>plt.show()</pre><pre>compcasedf = pd.DataFrame( {&quot;Column&quot;: dfn.columns, &quot;importance&quot;: importances}).sort_values(&#39;importance&#39;, ascending=False)</pre><p><em>Based upon the above model, we assess the top 18 features impacting the number of cases.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*zOFTdrhHsQr12R-27DBXmw.png" /></figure><p>In the top 18 list, features like <strong>Population Density, Age Greater than 60, Population Growth Rate </strong>are pretty intuitive<strong> </strong>and collectively understood<strong> </strong>but others which are seemingly unrelated are as follows. I have tried to link the feature to an assumed explanation as follows:-</p><p>• Economy from Agriculture — Healthy vegan diet/less industrial emission<br>• No of Threatened Species — Better animal welfare and policies<br>• No of Internet Subscription — Well informed population/better facilities<br>• Mutton Consumption — High calorie diets/unhealthy breeding techniques<br>• Servicing Percent Employed — Needs more travel leads to more exposure.<br>• No of Mobile Subscription — Well informed population/better facilities<br>• Poultry Consumption — High calorie diets/unhealthy breeding techniques<br>• %GDP Expenditure Education — Educated population means good controls<br>• Refugees — Poor living and health conditions might increase exposure.<br>• Unemployed Percent — Poor living and health conditions. <br>• GDP Growth Rate — Economic activity may impact spread<br>• Sex Ratio Male to 100 Female — Gender based infection probability<br>• Industry Percent Employed — Higher industrial emission exposure<br>• Agri Production Index — Healthy vegan diet/less industrial emission<br>• Beef Consumption — High calorie diets/unhealthy breeding techniques</p><p>Even though most features are logically intuitive but there are few startling observations which clearly stand out and forces us to delve deeper. The meat consumption pattern including poultry, goat and beef consumption is one such finding which has a relatively high importance in contributing to both the number of cases and deaths. Does it signify that the deteriorating quality of food due to unhygienic animal breeding techniques and the environment impact of modern day meat production has lead to decreased human immunity. Globalization has definitely improved exchange of goods and services and has lead to easy trade even between the farthest of countries but did that also lead to a quicker spread of the virus. The study also highlights how our world is changing with mobile and internet technologies. The relation of cases/deaths to mobile/internet subscription could mean easier access to information and an improved preparedness to respond to the outbreak. The study interestingly finds affinity between cases/deaths to refugees &amp; unemployment which mostly indicates that poor living and health conditions makes the population more susceptible. One interesting observation is also that government spending on education has an impact. Does it mean an educated society can handle such epidemics better than others or that the value of a democratic educated society makes it harder to implement movement constraints and thereby stopping the spread of the virus? Last but not the least the article highlights the topic of threatened species in a country which might allude to a nature’s twist to the outbreak.</p><p>Definitely lot more to learn from this model so feel free to explore. The complete code and data files are available in my GitHub Account:-</p><p><a href="https://github.com/vinayakbhakta9/Coronavirus">vinayakbhakta9/Coronavirus</a></p><p>Appreciate you taking the time to read this and do provide your valuable feedback which will help me do more such work in future. Thanks a lot.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=943db7bda303" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>