<?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 Victor E. Irekponor on Medium]]></title>
        <description><![CDATA[Stories by Victor E. Irekponor on Medium]]></description>
        <link>https://medium.com/@IrekponorVictor?source=rss-1cb85047a359------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*4HBSw2dp5ESUklC33sMDAQ.jpeg</url>
            <title>Stories by Victor E. Irekponor on Medium</title>
            <link>https://medium.com/@IrekponorVictor?source=rss-1cb85047a359------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 20:21:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@IrekponorVictor/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[Year 2022 in two Paragraphs!]]></title>
            <link>https://medium.com/@IrekponorVictor/year-2022-in-two-paragraphs-1d77545946cd?source=rss-1cb85047a359------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d77545946cd</guid>
            <category><![CDATA[year-in-review]]></category>
            <dc:creator><![CDATA[Victor E. Irekponor]]></dc:creator>
            <pubDate>Sun, 01 Jan 2023 03:47:51 GMT</pubDate>
            <atom:updated>2023-06-14T04:42:01.461Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/290/1*7T5teJKpD5D1jLMvGGLuJQ.jpeg" /></figure><p>The last time I wrote a piece for my Medium blog was in 2020 — 2 years, 7 months, and 3 days ago. I paused because I took on more responsibilities in my previous job as a machine learning software engineer, and I couldn’t seem to get my rhythm back. A lot happened personally: I graduated college, published a paper in a top Q1 journal, got a full-time position (for eight months), mastered some new skills, traveled to other states in Nigeria, frequented the gym more, got into grad school, moved to the U.S., had my first “first-author” paper rejected 5 times and counting, completed the first semester of my Ph.D. (unscathed), etc. I think this is more of a year 2020–2022 in review.</p><p>Above all, I am grateful to the almighty God for how much he has come through for my undeserving self in really tight moments. I hope to post more research-focused and informal articles like this in the coming year, 2023, at least quarterly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d77545946cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mathematical Prerequisites For Understanding Autoencoders and Variational Autoencoders (VAEs)]]></title>
            <link>https://medium.com/analytics-vidhya/mathematical-prerequisites-for-understanding-autoencoders-and-variational-autoencoders-vaes-8f854025390e?source=rss-1cb85047a359------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f854025390e</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[unsupervised-learning]]></category>
            <category><![CDATA[mathematics]]></category>
            <dc:creator><![CDATA[Victor E. Irekponor]]></dc:creator>
            <pubDate>Thu, 28 May 2020 10:32:16 GMT</pubDate>
            <atom:updated>2020-05-28T14:42:26.765Z</atom:updated>
            <content:encoded><![CDATA[<h3>Mathematical Prerequisites For Understanding Autoencoders and Variational Autoencoders (VAEs): Beginner Friendly, Intermediate Exciting, and Expert Refreshing.</h3><p>A few days ago, my brother walks in my room and sees me writing code and studying a math tutorial, with a puzzled expression he asks, Are you studying maths now or building AI models, which? With a smile, I reply and say, AI is Maths!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-hbU2nTW7wJjIyGe" /><figcaption>Photo by <a href="https://unsplash.com/@franckinjapan?utm_source=medium&amp;utm_medium=referral">Franck V.</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Well not totally maths per se, but to be really grounded one needs to have a very good grasp of the mathematical underpinnings as AI isn’t just about training ConvNets or Transformer models with Pytorch, Tensorflow or Keras. As a matter of fact, to read, understand and replicate a research paper requires at least a fair understanding of some mathematical concepts including but not limited to Linear Algebra, Calculus, Probability theory, and Statistics.</p><p>AI is free for everyone, so whether you come from a CS, Maths, or Engineering background or not doesn’t matter much, in fact, it doesn’t count at all because the internet now is a plethora of information especially with the advent of MOOCs, you can pretty much learn all these basics on your own and be better at it. I know that for a fact because in the last 5 years being an undergrad studying Urban Planning, the most complex maths I did was population mean, skewness, kurtosis, and moments. That was in my first year! I am about rounding up now and I’ve never taken a course that required maths one bit. My last serious maths was in high school, every other thing I know now was self-taught, I just picked it up along the way.</p><p>I know a lot of guys are in these shoes, you want to dive deep into AI but you feel you don’t have the right background so you stay put or go into web development. If you fall into this category, nothing should limit you!!!</p><p>In this post, we are going to cover some of the basic mathematics required to understand Autoencoders, Variational Autoencoders (VAEs), and Vector Quantised Variational Autoencoders (VQ-VAEs). Specifically, we would be looking at:</p><ol><li>A review of Auto Encoders</li><li>Basics of Probability</li><li>Expectation maximization</li><li>Kulback Leibler Divergence and its significance</li></ol><p>An Autoencoder is essentially a neural network that is designed to learn an identity function in an unsupervised way such that it can compress and reconstruct an original input, and by doing that it discovers a more efficient and compressed representation of the original input data. It is worthy of note that the idea was originated in the <a href="https://en.wikipedia.org/wiki/Autoencoder">1980s </a>and later promoted in a seminal paper by <a href="https://pdfs.semanticscholar.org/c50d/ca78e97e335d362d6b991ae0e1448914e9a3.pdf">Hinton and Salakhutdinov, 2006</a>.</p><p>Autoencoders are widely used for image compression and reconstruction. Image reconstruction basically means that the Autoencoder network tries to generate whatever image we pass into it at the input stage. We would soon come to the understanding of how this works as we progress.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_K4yRm8ILDZ02vPq.png" /><figcaption>Illustration of the Autoencoder architecture. Source<a href="https://lilianweng.github.io/lil-log/2018/08/12/from-autoencoder-to-beta-vae.html#td-vae">: Lilianweng’s blog</a></figcaption></figure><p>The image above portrays a typical autoencoder network architecture and to understand how this works intuitively, we should first learn that the autoencoder network consists of:</p><p><em>Leaving out the input and output(reconstructed input)</em></p><ol><li>The Encoder block, denoted by Gφ</li><li>The Bottleneck, denoted by, z</li><li>The Decoder block denoted by, Fθ</li></ol><p>The Encoder block takes in an input vector of images and passes it to the bottleneck as a compressed vector ‘z’, then the decoder block tries to reconstruct that input image from the compressed representation. For better understanding, say we have an input image of size (28 x 28), by convention, this image has to be flattened before feeding it into a neural network. A flattened representation of this image would be (784, ), and this is passed into the encoder (the first block). The output of the encoder is then fed to the bottleneck or latent space which should be a reduced version, for instance, if the amount nodes in the latent space is 8, or 16, or even any number, it simply means we have succeeded in compressing an image of size 784 to just 8 nodes, or 16 nodes or any number at all. The decoder network then tries to recreate the original (28 x 28) input image from the compressed state in the bottleneck. That’s how it works.</p><p>As soon as the image is reconstructed, you compare the reconstructed image with the original image, compute the difference, and calculate the loss which can then be minimized.</p><p>The Loss is calculated by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*18u4JC9BqTDjf4rXOsfxzA.png" /><figcaption>Autoencoder Loss Function</figcaption></figure><p>Don’t get alarmed at the loss function, I’ll break it down.</p><p>As seen above, the loss function depends on ‘theta’ and ‘phi’ which are the parameters that define the encoder and the decoder. As explained earlier and from the autoencoder image above, the encoder is represented by Gφ, while the decoder is represented by Fθ and they simply mean the weights and bias of the neural network.</p><p>So in the equation, we are summing up the difference between the original image, x`, and the reconstructed image Fθ(gφ(x`)).</p><p>This mathematical representation also shows the flow of data from the encoder to the decoder (i.e input to output)</p><h3><strong>Variational Autoencoder</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ndg6glTk5l_ouLON.png" /><figcaption>Illustration of the VAE model. Source: <a href="https://lilianweng.github.io/lil-log/2018/08/12/from-autoencoder-to-beta-vae.html#td-vae">Lilianweng’s blog</a></figcaption></figure><p>The basic idea behind the VAE proposed by<a href="https://arxiv.org/abs/1312.6114"> Kingma et al in 2013</a> is that instead of mapping an input to a fixed vector, the input is mapped to a distribution. the Autoencoder and the variational autoencoder are similar in many ways, as a matter of fact, the only fundamental difference between an autoencoder and a variational autoencoder is that the bottleneck of the VAE is continuous and replaced by two separate vectors; one representing the means of the distribution, and the other representing the standard deviations of the distribution.</p><p>The loss function of the VAE is defined by two terms, the reconstruction loss and the regularizer which is essentially a KL divergence between the encoder’s distribution and the latent space.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*1SRJjMDV1FMYO9oC0HQGGA.png" /><figcaption>VAE Loss Function, basically the reconstruction loss + KL divergence</figcaption></figure><p>Moving forward, understanding the deeper mathematical underpinnings of the autoencoder and the VAE network such as their loss functions requires a fair understanding of some concepts such as Expectation maximization, Conditional probabilities, Maximum likelihood estimation, and Kulback Leibler divergence, which is the crux of this article.</p><p>The first prerequisite for understanding VAE is Probability Theory, and I will not go into too much detail but will be explaining as much as is needed to understand these concepts.</p><p>You would be coming across the following terms more often:</p><p>P(x): This defines the probability of a random variable X</p><p>P(x|y): As known as conditional probability and it provides the probability of a random variable x, provided y has occurred. It is read as P of x given y.</p><p>this probability concept can also be written as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*Yf6tx0o19qibRK1fKa2ATQ.png" /></figure><p>The representation above comes from Baye’s theorem, where;</p><p>P(y|x) is the posterior probability</p><p>p(y) is the prior probability</p><p>p(x|y) / p(x) is the likelihood ratio</p><p>We need to also understand the theorem of total probability which goes thus;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*Aghk_SWQwyaOliX5H_gWIQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*GlI4K9zw5F6uKdd7khirzw.png" /></figure><p>An exclusive event also known as disjoint means that there is no overlap between them, and that is why their intersection is equal to zero. We’ll be seeing more of these as we get to the more complicated stuff, so its best to get it out of the way now.</p><h4><strong>Expectation of a Random variable X i.e E(X)</strong></h4><p>The expected value of a random variable is a weighted average of all the possible values of X that it can take, where each value is being weighted according to the probability of that event and it is defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*WTixH1R9GN4E7sAlZQByTw.png" /></figure><p>This might be getting a little too involved, but you should just know that this concept is similar to the mathematical average. For better intuition, you should <a href="https://www.youtube.com/watch?v=j__Kredt7vY">check this out</a></p><p>Let us look at some simple examples:</p><p><strong>Q1.</strong> When a die is tossed once, what is the probability of getting a three?</p><p><strong>Answer:</strong> You guessed right! given the sample space = {1,2,3,4,5,6}</p><p>P(x) = P(3) = 1/6.</p><p><strong>Q2.</strong> In tossing a fair die, what is the probability that 3 has occurred conditioned on the toss being odd?</p><p><strong>Answer:</strong> This is a conditional probability i.e P(x|y ), and what we are after is the probability of getting an x=3, giving that y=odd. that is, P(3|y being odd).</p><p>Since the condition is that the toss is “odd”, then definitely the sample space has to reduce from 6 to 3, because there are just 3 odd numbers if you count from 1–6. Therefore, {1,2,3,4,5,6} ==&gt; {1,3,5}. Hence, the probability of having a 3 in this reduced sample space is 1/3, where 3 is the total number of samples we have in the reduced sample space. This is about the simplest example I could get explaining conditional probabilities.</p><p>If we observe correctly, in the first example, the probability of having a 3 i.e P(3) was 1/6, but in the second, the probability became 1/3. what does that show?</p><p>Again, you guessed right! It shows that the probability of getting a 3 increased when it is conditioned by Y, which is “odd samples”. Therefore it is important to know that p(x) and p(x|y) can have different interpretations. And that is the concept of conditional probability, as the probability of “x” can be affected a lot by “y” as seen in the examples.</p><h3><strong>KL Divergence</strong></h3><p>Kulback-Leibler Divergence (D_KL for short) is a measure of how one probability distribution is different from the other. For the discrete probability distribution P and Q, the KL divergence between and P and Q is defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*3CHUM11FqvEm2o6nJ0ZSpA.png" /></figure><p><strong>For example:</strong></p><p>Suppose we have two probability distributions, P &amp; Q. and we want to find the difference between the two probabilities, we can simply apply the KL divergence as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*e2AgsIoUlKYgf7EFLQfHaA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*CW-UzYVOHHvuoWrOIfIMsA.jpeg" /></figure><p>Medium doesn’t actually support mathematical symbols, that is why the equations have to be solved elsewhere then I paste it here as an image. To explain the calculation above, we have a distribution Q with a uniform probability of 1/3 which is <strong>≈ </strong>0.333, and a distribution P with a probability of 0.36 when the random variable x is equal to 0, 0.48 when the random variable x is equal to 1, and 0.16 when the random variable x is equal to 2.</p><p>The difference between these two distributions can be calculated using the KL divergence, so what we do is substitute the values in the KL divergence equation like we have above and solve for the answer which is 0.09673 nats.</p><p>“nats” is simply the unit of information obtained by using the natural logarithm (ln(x)).</p><p>Understanding the KL divergence is integral to grasping the VAE loss function because it plays a key role — acting as a regulariser term. And that is why I went the extra mile to illustrate it graphically and mathematically.</p><p>Now that we have gone over some of the mathematical prerequisites that would come in handy moving forward, you should take a look at<a href="https://medium.com/retina-ai-health-inc/variational-inference-derivation-of-the-variational-autoencoder-vae-loss-function-a-true-story-3543a3dc67ee"><strong> this expository article</strong> </a>on deriving the VAE loss function entirely from scratch by <a href="https://medium.com/u/f3b4e4defa62">Dr. Stephen Odaibo</a>.</p><p>Maths is Fun!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f854025390e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/mathematical-prerequisites-for-understanding-autoencoders-and-variational-autoencoders-vaes-8f854025390e">Mathematical Prerequisites For Understanding Autoencoders and Variational Autoencoders (VAEs)</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Converting The Layers of a DWG File in AutoCAD to an ESRI Shapefile using GeoPackages in QGIS 3.x]]></title>
            <link>https://medium.com/@IrekponorVictor/converting-the-layers-of-a-dwg-file-in-autocad-to-an-esri-shapefile-using-geopackages-in-qgis-3-x-da5fd0ff3621?source=rss-1cb85047a359------2</link>
            <guid isPermaLink="false">https://medium.com/p/da5fd0ff3621</guid>
            <category><![CDATA[geopackage]]></category>
            <category><![CDATA[esri]]></category>
            <category><![CDATA[qgis3]]></category>
            <category><![CDATA[autocad-file]]></category>
            <category><![CDATA[gis]]></category>
            <dc:creator><![CDATA[Victor E. Irekponor]]></dc:creator>
            <pubDate>Tue, 26 May 2020 11:13:55 GMT</pubDate>
            <atom:updated>2020-05-27T16:51:12.257Z</atom:updated>
            <content:encoded><![CDATA[<p>I have noticed that there is not much easy to follow documentation for open source Geospatial analytic operations, the documentations that one may likely find are either outdated, do not work for one’s use-case, or too technical to follow along.</p><p>As a result of that, I have taken it upon myself to put out as many tutorials as possible for any GIS inclined project I work on and of course, it would also be beneficial to me in the long run as I can always come back here to make references in future peradventure I forget any of these concepts, so this is going to be a series. I would also try to adopt a very intuitive and simplistic approach in this tutorial and of course I am always available on my social media handles <a href="https://twitter.com/IrekponorVictor">Twitter</a>,<a href="https://www.linkedin.com/in/victor-e-irekponor-a926a1154/"> LinkedIn</a>, <a href="https://web.facebook.com/victor.irekponor/">Facebook</a>, and <a href="https://www.instagram.com/victor_irekponor/">Instagram </a>so feel free to connect and shoot your questions.</p><p>TL;DR</p><p>Say you have an AutoCAD drawing (of .dwg file extension), this could be a layout plan or a just a simple drawing that has a number of layers that you want to export to a GIS application and convert it to an ESRI shapefile for more advanced processing. How would you go about that? Well, keep reading!</p><blockquote><em>Want to read this story later? Save it in </em><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=blog&amp;utm_campaign=noteworthy&amp;utm_content=eid7"><em>Journal</em></a><em>.</em></blockquote><p>For this tutorial, we would be using the QGIS software, simply because it is opensource, has a relatively gentle learning curve, and also very easy to install on either Windows, Ubuntu, or Mac operating systems (from experience).</p><blockquote>I would be assuming you already have a version of AutoCAD installed on your PC, because how would you access a <strong>*.dwg </strong>file in the first place without the CAD software. For non-computer/tech-savvy readers, the asterisk means the filename — it could be any file name.</blockquote><p>But if you do not have QGIS already set up, <a href="https://www.youtube.com/watch?v=TQ4mto1KB1A">this tutorial here</a> pretty much does a very good job of helping you set that up quickly. Let us take a short break while you go and do that.</p><p>Now that you are back and should already have QGIS installed on your windows, Mac or Linux powered machine. Get set to run through the following steps.</p><p>First, open up the<strong> </strong>*<strong>.dwg</strong> file in AutoCAD and convert it into a <strong>*.dxf</strong> file. A <strong>DXF</strong> is a format created by Autodesk to facilitate the translation of CAD data from other programs to AutoCAD or vice versa, this matches our use case since we are trying to transfer data from AutoCAD to QGIS software. To do this simple conversion, we navigate to <strong>file</strong>&gt;&gt;&gt;<strong>Save As</strong>, then type in the file-name and select the right extension you want from the drop-down menu which is .dxf as shown in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e6wX3mM3jMHNw4xa7WXdjg.jpeg" /><figcaption>The image above shows the viewport of AutoCAD version 2017 and a dialogue box to save the drawing file to a new file having the dxf file extension.</figcaption></figure><p>Now as that is done and out of the way. Open up the QGIS software, and as soon as it is loaded, you should see an empty canvas, similar to the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ufF9J8W3HbS1EG_zZUtdjQ.png" /><figcaption>What an empty QGIS canvas looks like as soon as it is launched. Until you create a new project</figcaption></figure><p>Then you navigate to <strong>Project</strong>&gt;&gt;&gt;<strong>Import/Export</strong>&gt;&gt;&gt;<strong>Import Layers from DWG/DXF </strong>as shown in the image screenshot below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UgHqmny0ejgZBhrc5QcNWg.png" /><figcaption>The Image above shows graphically how to navigate to import layers from the AutoCAD file to GIS from the project menu.</figcaption></figure><p>As soon as you click on that, a dialogue box should appear similar to what you see below for importing the drawing into an OGC GeoPackage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5eKuacXBOQJxONHoAdlFDQ.png" /><figcaption>The image above shows a QGIS dialogue box where you have to initialize an empty gpkg file that would contain the layers from the AutoCAD DXF file amongst others.</figcaption></figure><p>If you do not already know what a GeoPackage is, here are good resources explaining what they are. <a href="https://www.geopackage.org/"><strong>[1]</strong></a>, <a href="https://www.gis-blog.com/geopackage-vs-shapefile/"><strong>[2]</strong></a>,<a href="https://www.youtube.com/watch?v=SWW-iZCK48c"><strong>[ 3]</strong></a><strong>.</strong></p><p>The GeoPackage is the GIS file format of the future, and the future is now. As you may have noticed QGIS 3.x switched from shapefiles to GeoPackage as default in most cases. Thus, rendering gets really fast. Loading, panning, and zooming feel way quicker with GeoPackage than with Shapefiles.</p><p>Per the most recent image above, in the <strong>Target Package </strong>box, you are to initialize an empty GeoPackage (.gpkg) layer where you would store all the separate layers from your DXF file, so left-click on the small box icon to the right of <strong>Target Package</strong>, just before <strong>Load Layers</strong>, and navigate to the specific directory where you want your .gpkg file to be saved and add a file name to it.</p><p>Next, you need to make sure the coordinate reference system is correct, but if it isn’t then it is your prerogative to do the needful.</p><p>As soon as that is done and out of the way, you go ahead to import the source drawing whose layers you want to store in a geoPackage, If you have been following, you would note that this drawing should be of type DXF file format. So just click on <strong>Import</strong>,<strong> </strong>grab the initial <strong>*.dwg</strong> file you converted to <strong>*.dxf</strong> in the first step and click on <strong>OK </strong>to start importing your layers. It should take a while depending on the file size and your compute power.</p><p>As soon as that is done importing, you should have something similar to the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vW6gGY8SCDkwiRcF11BAiQ.jpeg" /><figcaption>Image showing what the dialogue box looks like after the layers have been imported from the *dxf file and now stored in a gpkg file format.</figcaption></figure><p>You can now decide to tick or untick all the layers you want to keep or discard, give them a group name, and then click <strong>OK </strong>to signify that you are done.</p><p>Wooohooo!!!</p><p>You just successfully imported your DWG file to QGIS as a geoPackage layer which can now be viewable in the canvas. See the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aSCfztkDDJRBrEmP2OVNGQ.jpeg" /><figcaption>The image above shows a QGIS canvas with the newly imported vector file from AutoCAD as well as its individual layers, this drawing can now be subjected to further analysis.</figcaption></figure><p>Now that we have the AutoCAD drawing in QGIS as individual geoPackage layers it is worthy to note that they can still be further converted to ESRI shapefiles if you want by simply<strong> right-clicking on the layer</strong>&gt;&gt;&gt;<strong>Export</strong>&gt;&gt;&gt;<strong>Save Feature As </strong>as shown in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RPzYmFtAKqff9BYand5mmg.png" /><figcaption>Navigation steps to export the gpkg layers to ESRI shapefile formats.</figcaption></figure><p>Left-click on <strong>Save Feature As</strong> and another dialogue box should pop-up where you can select the ESRI shapefile format from the list of file formats, specify a file name, and click on <strong>OK</strong>. See the image below for more reference to this step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hvQnZR7mZTq6hArSoX27Cw.png" /><figcaption>CAVEAT! The file name should be an explicit path to the file, in order to do that, left-click on the small box icon to the right of the file name text-box and navigate to your working directory where you can then specify the shapefile name.</figcaption></figure><p>So that, my friend, is how you convert an AutoCAD drawing to an editable ESRI shapefile vector for further analysis in QGIS.</p><p>Mind you there are other ways this could be done on ArcGIS using ArcPy, and with GDAL’s ogr2ogr. But I found this method to be more straightforward. Plus it worked very well for me.</p><p>In subsequent editions of this series, I would actually be exploring other options for converting layers from a DWG file to an editable ESRI shapefile vector format. More likely with an automating tool like Python because what if I had a 1000 or even a 100 layers to export to an ESRI shapefile format. A batch-wise operation would make life easier in such cases.</p><p>However, One other thing to note is that though the layers have been converted to a shapefile, they still need to be georeferenced. With Raster data georeferencing is quite straightforward. But with Vector data like shapefiles, there are a number of ways one might go around that including rasterizing the vector, or doing Affine transformations with known Ground Control Points (GCPs) using GDAL’s ogr2ogr, or pyQGIS, ArcPy, Fiona, basically any of the open-source frameworks suited for this purpose.</p><p>The next post would primarily be on GeoReferencing a vector GIS shapefile using Ground Control Points (GCPs) and Affine Transformations.</p><p>Let me know if you have any questions in the comment section, or a more effective way to go about this task. I would be happy to take your questions and also learn.</p><p>Also, all the DWG, DXF, SHP, and GPKG files and images used in the post have been uploaded to my GitHub repository <a href="https://github.com/marquisvictor/Geospatial-Series-DWG-to-Shapefile">here</a>, It is open-source now. So feel free to access it and play with it!!</p><figure><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=blog&amp;utm_campaign=noteworthy&amp;utm_content=eid8"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ArLSH4tuI2v4pF0giI3-OQ.png" /></a></figure><p>📝 Save this story in <a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=tech&amp;utm_content=guest_post_read_later_text">Journal</a>.</p><p>👩‍💻 Wake up every Sunday morning to the week’s most noteworthy stories in Tech waiting in your inbox. <a href="https://usejournal.com/newsletter/noteworthy-in-tech/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=tech&amp;utm_content=guest_post_text">Read the Noteworthy in Tech newsletter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da5fd0ff3621" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Twitter Data Mining: Mining Twitter Data without API keys.]]></title>
            <link>https://medium.com/analytics-vidhya/twitter-data-mining-mining-twitter-data-without-api-keys-a2a2bd3f11c?source=rss-1cb85047a359------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2a2bd3f11c</guid>
            <category><![CDATA[data-mining]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[twitter]]></category>
            <category><![CDATA[sentiment-analysis]]></category>
            <dc:creator><![CDATA[Victor E. Irekponor]]></dc:creator>
            <pubDate>Fri, 15 Nov 2019 18:31:43 GMT</pubDate>
            <atom:updated>2020-10-12T23:48:16.804Z</atom:updated>
            <content:encoded><![CDATA[<h3>Mining Twitter Data without API keys</h3><h4>Getting Twitter Big Data for Analysis with a Single Line of Command.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*OAqL1Yatoe0KxNXSYTffAw.png" /><figcaption>Social Media platforms: Huge mine of textual big data</figcaption></figure><p>Data is the new oil, it is everywhere. Over the last decade, more than 90 percent of Big Data has been generated by people living in urban areas. With the advent of internet-of-things (IoT ) and the increased use of the internet, social media has become an integral part of people’s daily lives. Millions of unstructured data are being sent to the cloud every second providing free and unbiased information practically on any discourse. Every second, an average of around 6000 tweets are tweeted on Twitter which corresponds to over 350,000 tweets sent per minute, 500 million tweets per day and around 200 billion tweets per year. See stats <a href="https://www.internetlivestats.com/twitter-statistics/">here</a>.</p><p>Imagine getting this data on your personal computer without having to write any bulky code. Just a bunch of commands from the command line or terminal.</p><p>I was opportuned to be in a team working on a project recently that was centered on Community Resilience and Studentification, and I needed to download and carry out some analysis on <strong>Old/Backdated</strong> Twitter data from about <strong>10 years</strong>, naively I went about the very standard approach which was first creating a developer account with twitter, and then using Tweepy to query Twitter’s RESTful API in order to download the user tweets with some other meta-data such as retweets, likes, favorites, date and time, username, et cetera.</p><p>I was soon to discover that going down that road would not be very helpful to my task which <strong>was </strong><em>to</em><strong> </strong><em>download twitter data on a specific discourse over the last 10 years, w</em>hich would then be fed into several pipelines I had built for analysis. And that was because of Twitter’s rate limits and time constraints; using twitter’s API you can not mine tweets older than seven days, similarly, for a single search query, twitter only gives 100 results of the current week. <strong>Not very helpful to me I must say.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*V5UK6NIBA2uB9grMFPzD5A.png" /><figcaption>Thank you Calculator, but the answer is <strong>not very helpul.</strong> :-)</figcaption></figure><p>So I went into my default research mode. I had a problem to be solved which was to get old tweets programmatically, then I found out about the GetOldTweets-python tool originally developed by <a href="https://github.com/Jefferson-Henrique/GetOldTweets-python"><strong>Jefferson Henrique</strong></a> in Python version 2.x, and later modified by <a href="https://github.com/Mottl/GetOldTweets3"><strong>Dmitri Mottl</strong></a> in Python version 3.x. Probing deeper I saw that it was essentially a tool that queries twitter search engines via the browser using python libraries such as pyquery, urllib, requests, and Lxml. Interesting! And very helpful for my task.</p><p>The algorithm works by querying twitter search very fast through the browser, looking for the search keywords, usernames, or hashtags you specified in the command, until the end of your search duration. Basically, when you enter on Twitter, a scroll loader starts, if you scroll down you start to get more and more tweets, all through calls to a JSON provider. It can search for the deepest and oldest tweets.</p><p>At that stage in my research, I had found just what I was looking for. Essentially in Software development and Engineering, you don’t try to re-invent the wheels. So I jumped on it but found it difficult to write a working implementation for my own use case. I wasn’t getting the results I needed. Also, I figured a lot of people are in my shoes, or would also one day be in my shoes, so why not contribute to open source and make things a lot easier for even folks that don’t have strong python/programming background.</p><p>And that led to my own improvement fork, which is the crux of this article.</p><p>So we are just getting started.</p><p>TL;DR</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*weenkO-G405x_MjszXUj1Q.png" /></figure><blockquote>This improvement fork of the code ensures that downloading millions of backdated/old tweets that could be used for your analysis becomes relatively easier and stressless either on your Windows, Ubuntu, or Mac OS powered machine, and from command line. Basically a one-liner command. Just by following the simple steps which I have priorly enumerated on my <a href="https://github.com/marquisvictor/Optimized-Modified-GetOldTweets3-OMGOT"><strong>Github</strong></a> but would show here for practicality sake.</blockquote><p><strong>Requirements.</strong></p><p>The first prerequisite would be to have any python3.x version installed on your local machine, and you should have already set the environment variable path, so you can interactively fire up python from your Command Prompt or Terminal without getting any error. The easiest way to do that on Windows is to run the python installer again and tick the box saying “Add Python to environment variables” under the advanced option. <a href="https://stackoverflow.com/posts/54934172/edit">This answer on stackoverflow</a> shows it more clearly. And on terminal, if you’re using the Ubuntu distribution (which I think is more popular among programmers that prefer the Linux OS), just run sudo apt-get install python3.6 on your terminal and you should be able to fire up python3 from terminal after installation by just typing “python”.</p><p>After doing that, the next major requirement would be to install pyQuery and Lxml for handling requests and xml/html document types. This could easily be done by just running on Terminal or Command Prompt; pip install pyquery and pip install lxml</p><p>Now once you’ve completed all these prerequisites, Head down to my <a href="https://github.com/marquisvictor/Modified-GetOldTweets3/blob/master/README.md"><strong>Github here</strong></a>, to fork and/or clone the improvement fork of Mottl’s python3 version, which is also an improvement fork of the original package written by Jefferson Henrique.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*BQhEUTf2bSjvyy40KWGFcQ.gif" /><figcaption>I’d like to have some Nigerian Jollof and Turkey, please :-)</figcaption></figure><p>There’s a README file which contains the implementations and some basic examples attached to my repo, but I’ll be giving a short hands-on tutorial on downloading old/backdated twitter data.</p><p>Now once you have cloned or downloaded the repo to your local machine, you can start downloading your old/backdated twitter data for any kind of analysis by the following the steps below:</p><ol><li>Clone or download the repo to your local machine.</li><li>Unzip it.</li><li>Navigate to the unzipped Optimized-Modified-GetOldTweets3-OMGOT-master folder</li><li>cd again to the GetOldTweets3–0.0.10 folder inside unzipped Optimized-Modified-GetOldTweets3-OMGOT-master folder, and fire up a command prompt or terminal right there.</li><li>There you go, you can start playing around with your dataset now.</li></ol><p>Run the commands from the GitHub readme to start downloading your twitter data which would then be saved on your computer as an output.csv file. But you can specify a name to save your downloaded dataset by passing a “name”.csv to the “ — output” argument. For instance: --output dataset.csv saves the downloaded file as dataset.csv in your working directory.</p><p>Now, getting our hands dirtier with more examples. Lets say we need to download tweets by a specific User.</p><p>We simply do step 1–4 stated above, and type in the following command culled from the Github repo</p><pre>python GetOldTweets3.py --username &quot;mo4president&quot;  --maxtweets 50 --output dataset.csv</pre><p>The above command would query twitter’s search engine and download all the tweets made by @mo4president, you can also use the --maxtweets parameter to specify the amount of tweets you need, and --output parameter to specify the output name. Leaving out the --maxtweets argument basically downloads all of the tweets by the user. But here we specified 50, meaning we would only get 50 rows of tweet info.</p><p>Also if you need to download tweets with respect to a particular keyword e.g “<strong>rent</strong>” over a period of time from like say 2014 till date and within a geographic geolocation, which is about 5 years worth of old tweets, you use this command also culled from my github repo, after executing step 1–4 as stated above.</p><pre>python GetOldTweets3.py --querysearch &quot;rent&quot; --near &quot;6.52, 3.37&quot; --within 40km --maxtweets 350 --output rent.csv --since 2014-01-01 --until 2019-08-31</pre><p>So this command above would fetch us all the tweets that contains the word or hashtag “<strong>rent</strong>”, within a 40km radius of the latitudinal and longitudinal coordinates of Lagos state <em>(because that’s what we specified)</em> from 2014 till date, and would store the results in a rent.csv file that would be saved in our current working directory . The maxtweets argument here would return 350 tweets because that is what was specified.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*XUWCT46w4AnovrqGPIfs7Q.png" /><figcaption>essentially a one-liner command to start downloading tweets</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*JLZInVS0rldePTBB7uEKeg.png" /><figcaption>The output in csv format</figcaption></figure><p>Running this same process I was able to gather enough big data on a variety of discourse represented by keywords and analysed them accordingly to see trends relating to community resilience and studentification amongst other analysis over a 10 year period.</p><p>As shown above, after downloading the twitter big data in its raw unstructured state, you’ll need to do a bit of dataframe manipulation with pandas library in python to drop some columns and probably do some basic exploratory data analysis.</p><p>It is worthy to note that this modified tool now automatically takes care of all the tweet text cleaning and the removal of unwanted characters.</p><p>Then you might want to pass the tweet texts into a sentiment analysis pipeline built around <a href="https://github.com/cjhutto/vaderSentiment">vader</a> or <a href="https://textblob.readthedocs.io/en/dev/">textblob</a> for further analysis, or do a document-topic-word modeling using <a href="https://pypi.org/project/gensim/">Gensim’s library in python </a>and the Latent Dirichlet Allocation model. But all these different analysis depends on your proficiency and the direction of your project as a Data Scientist or Researcher.</p><p>In the next couple of posts, I will be looking at pretty much all the analysis that could be carried out with the tweet texts to derive better insights, and also how to handle noise in your dataset. But for now, I hope you find this article helpful in gathering your twitter “big” data.</p><p>Code Contributors:</p><p><a href="https://www.linkedin.com/in/victor-e-irekponor/"><strong>Irekponor</strong></a><strong> </strong><a href="https://github.com/marquisvictor"><strong>Victor</strong></a>, University of Lagos, Nigeria.</p><p><a href="https://www.linkedin.com/in/aminu-israel-248ab3177/?originalSubdomain=ng"><strong>Aminu</strong></a><strong> </strong><a href="https://github.com/AminuIsrael"><strong>Israel</strong></a>, Lagos State University, Nigeria.</p><p><a href="https://www.linkedin.com/in/olahfemi/?originalSubdomain=ng"><strong>Olah</strong></a><strong> </strong><a href="https://github.com/olahfemi"><strong>Femi</strong></a>, University of Lagos, Nigeria.</p><h3>UPDATE<strong>:</strong> 13–10–2020.</h3><p>This tool (optimizedGetOldTweets) is currently broken because twitter made an upgrade to their API endpoints from V1.1 to V1.2, and as a result of that, some of the endpoints used in this tool became deprecated <a href="https://blog.twitter.com/developer/en_us/topics/tips/2020/understanding-the-new-tweet-payload.html">Here are some more details on their new API</a>. Things moved pretty fast, I’ve been able to fix this yet. But for the time being, if you’re here, <a href="https://github.com/marquisvictor/Optimized-Modified-GetOldTweets3-OMGOT/blob/master/README.md#update-12-10-20">check out this </a>addition I made to the Github readme.</p><p>I believe it would go a long way in helping you in your twitter data mining escapades. 😊.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2a2bd3f11c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/twitter-data-mining-mining-twitter-data-without-api-keys-a2a2bd3f11c">Twitter Data Mining: Mining Twitter Data without API keys.</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Top Three Learnings in Omdena’s AI Challenge To Solve the Chicago Gun Violence Problem]]></title>
            <link>https://medium.com/omdena/my-top-three-learnings-in-omdenas-ai-challenge-to-solve-the-chicago-gun-violence-problem-e8bbcd083bb5?source=rss-1cb85047a359------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8bbcd083bb5</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai4good]]></category>
            <category><![CDATA[twitter-data-mining]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Victor E. Irekponor]]></dc:creator>
            <pubDate>Fri, 18 Oct 2019 14:59:03 GMT</pubDate>
            <atom:updated>2019-10-18T15:01:24.935Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AzUtJ-3icXp59V3Y" /><figcaption>Photo by <a href="https://unsplash.com/@grohsfabian?utm_source=medium&amp;utm_medium=referral">Fabian Grohs</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Thinking about joining an Omdena AI challenge? My advise will help you to get the most out of a challenge.</h4><p>My journey with Omdena started when I came across their social media pages on <a href="https://www.facebook.com/OmdenaAI/">Facebook </a>and <a href="https://www.linkedin.com/company/omdena">LinkedIn</a>. I was wowed because I am very passionate about AI for Good. In the following, I share my top three learnings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*QEUvYYbGGRwFX6Go_t0aMA.jpeg" /><figcaption>Victor: <a href="https://www.linkedin.com/in/victor-e-irekponor/">LinkedIn</a></figcaption></figure><h4>#1 You work with highly-skilled and motivated individuals</h4><p>I was really excited to find out how much Omdena had contributed to global good by harnessing Artificial Intelligence, bringing skilled, intelligent and highly motivated individuals together to solve a specific problem ranging from environmental problems such as detecting forest fire outbreaks to avoid disastrous deforestation to social problems such as analyzing social media to prevent violent acts.</p><p><strong>You also get exposed to several projects that fall in line with what you love doing.</strong></p><p>I applied to be a collaborator to join the Chicago Gun Violence Challenge in partnership with Voice4Impact, because I already had experience working with twitter data and its API’s. I took it as an opportunity to improve my skills and also contribute to global good with AI.</p><blockquote>The overall methodology was to collect geolocated tweets specifically from Chicago area related to Gang violence, specifically Gun-related violence, and then train a classifier model that can proactively flag down threatening tweets. Voice4Impact helped to get the datasets.</blockquote><p>Prior to starting the challenge, I had already gathered extensive experience in the Data Science field, particularly in Natural Language Processing <a href="https://www.dataversity.net/future-nlp-data-science/"><em>(which is a sub-branch of Data Science),</em></a><em> </em>working with and analyzing Twitter textual data as a <a href="https://www.linkedin.com/in/victor-e-irekponor-a926a1154/">Research Assistant</a> in the Community Resilience Lab, the Department of Building and Real Estate. Hong Kong Polytechnic University, Hong Kong.</p><p>I had also optimized and modified an open-source tool while actively working on some projects in the research lab for<a href="https://github.com/marquisvictor/Optimized-Modified-GetOldTweets3-OMGOT"> mining geolocated old/backdated tweets from Twitter, with minimal programming knowledge required.</a></p><h4>#2 You learn skills in the most effective and fun way</h4><p>I worked remotely on this challenge with a team of over 30 Machine Learning Engineers, Data Wranglers, and Data Scientists from a variety of backgrounds and nationalities skilled in different fields. So it was quite fun while we also learned from each other. Also, Omdena has a policy of not issuing out tasks directly to individual collaborators. As a collaborator, you are expected to be motivated and actively involved in the challenges, and you share your progress with the team in the various channels concerned with what you’re doing. That way you are able to learn and improve on your skills while in a community. We also had weekly calls where each task leader briefs the team about what has been done in the past week, and what would be done in the coming week in order to achieve the goal.</p><p>I was the first task manager for the sentiment analysis team, where we used a python library — <a href="https://github.com/cjhutto/vaderSentiment">Valence Aware Dictionary and Sentiment Reasoner (VADER) </a>to first get the sentiment polarities of each individual tweet, and with that, we were able to get a preliminary understanding of the overall sentiments in the datasets. That gave us a prior knowledge moving forward in our ultimate task to build a classification model which was then taken over by <a href="https://medium.com/u/ffc7d3f76e33">Yang Gao</a> who managed the team till the end of the challenge. <a href="https://medium.com/omdena/sentiment-analysis-to-detect-threatening-tweets-in-a-collaborative-team-b6ee11ffe179"><strong><em>She shares her wonderful experience here</em></strong></a><strong><em>.</em></strong></p><h4>#3 You learn faster through collaboration than alone</h4><p>Being a part of <a href="https://omdena.com/our-projects/#slider1">Omdena</a> has been quite rewarding for me in particular, because I&#39;ve had the opportunity to connect with great minds from diverse backgrounds on a personal level. I have also learned so much from my team members over the past few weeks. There’s this thing about being active on a project, working with teammates and working on your own. You tend to achieve and learn more collaborating with other people, than working solo.</p><p>And Omdena provides just the right environment!!</p><h4>Want to become an Omdena Collaborator and join one of our tough AI for Good challenges, <a href="https://omdena.com/our-projects/">apply here</a>.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*84sELjqU4RYqQphI.png" /></figure><p>If you want to receive updates on our AI Challenges, get expert interviews, and practical tips to boost your AI skills, <a href="http://eepurl.com/gto7Xn?source=post_page---------------------------">subscribe</a> to our monthly newsletter.</p><p>We are also on <a href="https://www.linkedin.com/company/14052175?source=post_page---------------------------">LinkedIn</a>, <a href="https://www.instagram.com/omdenaglobal/">Instagram</a>, <a href="https://web.facebook.com/OmdenaAI/?source=post_page---------------------------">Facebook</a>, and <a href="https://twitter.com/OmdenaAI?source=post_page---------------------------">Twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8bbcd083bb5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/omdena/my-top-three-learnings-in-omdenas-ai-challenge-to-solve-the-chicago-gun-violence-problem-e8bbcd083bb5">My Top Three Learnings in Omdena’s AI Challenge To Solve the Chicago Gun Violence Problem</a> was originally published in <a href="https://medium.com/omdena">Omdena</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SHOMOLU LOCAL GOVERNMENT AREA: AN IN-DEPTH EXPLORATORY DATA ANALYSIS USING PYTHON (Pandas &…]]></title>
            <link>https://medium.com/@IrekponorVictor/shomolu-local-government-area-an-in-depth-exploratory-data-analysis-using-python-pandas-7946c034e831?source=rss-1cb85047a359------2</link>
            <guid isPermaLink="false">https://medium.com/p/7946c034e831</guid>
            <category><![CDATA[nigeria]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[exploratory-data-analysis]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[urban-planning]]></category>
            <dc:creator><![CDATA[Victor E. Irekponor]]></dc:creator>
            <pubDate>Wed, 27 Feb 2019 14:52:42 GMT</pubDate>
            <atom:updated>2020-06-04T15:12:24.163Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>SHOMOLU LOCAL GOVERNMENT AREA: an in-depth Exploratory Data Analysis using Python programming language,(Pandas and Seaborn Libraries)</strong></h3><h4><strong>TABLE OF CONTENTS</strong></h4><p>1. THE STUDY AREA (SHOMOLU LGA)</p><p>2. METHODOLOGY</p><p>3. EXPLORATORY DATA ANALYSIS</p><p>4. CONCLUSION</p><h3><strong>1.0 THE STUDY AREA</strong></h3><p>Shomolu, also spelled “Somolu” town, is a residential suburb located in the north of Lagos state in southwestern parts of Nigeria. The town is plagued by problems of overcrowding, poor housing, and inadequate sanitation. Its local activities include work in leather, handicrafts, and printing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/1*ouu77ck_VyUgyi2A7tyr3w.png" /><figcaption><strong>Map of Lagos state showing Shomolu LGA.</strong></figcaption></figure><p>The population of the LGA according to the 2006 census is 402,673 persons. However, Shomolu local government area was formerly known as Mushin East local government. The present Somolu Local Government comprises areas like Community Road, Akoka, areas east of Ikorodu road up to Anthony Oke side interchange, including Somolu, Bashua, Bariga, some parts of Akoka, Igari, Obanikoro, Pedro village, Abule Okuta, Seriki village, Apelehin, Ilaje.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*Kh1Hm1IGUDfglh2aS6ZrnA.png" /><figcaption><strong>source: Wikipedia</strong></figcaption></figure><p>Shomolu Local Government is essentially inhabited by the Yorubas’, prominent among them are the Ijebus’, Egbas’, Aworis’, and Ilajes’. Other Yoruba ethnic groups such as Oyo, Osun, and Ekiti are represented in the area. However, other ethnic groups from the East and Northern parts of the country are equally large in number in the Local Government Area.</p><p>While the community in time past has been embroiled in violence and disorder (one which could equally be attributed to the failure of the society to provide viable alternatives), a new and different mentality is feeding a much more proactive and positive temperament. To the people of Shomolu, the canal which runs from Shomolu to Folagoro, Akoka, etc. is a symbolic divider. It is popularly known as “middle belt” by the indigenes as it serves as neutral ground and often a space of demarcation between the two most important factions of the community’s gangs.</p><p>Shomolu is the biggest printing hub in Nigeria and is complemented with other commercial activities such as the trade of foodstuffs, utilities, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/290/0*KtIYaBw4p3xeH7FG" /><figcaption><strong>A printer in Shomolu LGA</strong></figcaption></figure><p>Residents in the study area practice Christianity, Islam and few percentages are traditional religious worshipers.</p><p>The educational system in Shomolu cannot be termed poor as<strong> </strong>Lagos state government operates state schools and the education system is the 6–3–3–4, which is practiced throughout the whole country. The levels are primary, junior secondary school, senior secondary school, and university. Some of the schools in Shomolu include; Binta Girls High School, CMS Grammar School, Igbobi College</p><p>There are not too many landmarks in Shomolu since its evolution, some of the few includes;</p><p>· <strong>CMS Grammar School, Lagos</strong></p><p>The CMS Grammar school in the Bariga district of Lagos is the oldest secondary school in Nigeria, founded on the 6th of June 1859 by the Church Missionary Society. For decades it was the main source of African Clergymen and administrators in the Lagos colony.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/0*9T62gyfTlrjG7SRS.png" /><figcaption><strong>CMS Grammar School, Shomolu Lagos.</strong></figcaption></figure><p>· <strong>Yaba College</strong></p><p>Yaba Higher College was founded in 1932 in Yaba, now a suburb of Lagos in Nigeria to provide tertiary education to Africans, mostly in vocational subjects and teaching. The College staff were transferred to start the University of Ibadan in 1948 and the college premises were used for the new Yaba College of Technology.</p><h3><strong>2.0 METHODOLOGY</strong></h3><p>The dataset used in this Exploratory analysis was primarily collected by Students of the<strong> Department of Urban and Regional Planning set of 2015/2016 academic year, University of Lagos,</strong> while in the process of preparing a master plan for Shomolu LGA in march 2018.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*gfyD6JyAvIZQbS9y94K7jA.jpeg" /><figcaption><strong>Taking a Selfie with Team members on the Field.</strong></figcaption></figure><p>The dataset stems from a set of 181 questionnaires administered to the residents of Shomolu LGA in March of 2018. <a href="https://www.researchgate.net/publication/265276754_Sampling_from_Small_Populations"><strong>Evan Morris formula</strong></a> was used in calculating the sample size. Which was gotten to be approximately <strong>181 </strong>out of a total of 631,857 persons as of March 2018.<a href="https://explorable.com/simple-random-sampling"><strong> A random sampling technique</strong></a> was used to administer the questionnaires across the local government area.</p><p>The <a href="https://www.python.org/"><strong>python programming language</strong></a> was the major tool used in the exploratory analysis of the dataset acquired. Other tools used includes:</p><p><a href="https://pandas.pydata.org/"><strong>Pandas</strong></a><strong>:</strong> A python data analysis library that is used primarily for data manipulation and analysis. In particular, it offers data structures and operations for manipulating numerical/categorical tables and time series.</p><p><a href="https://jupyter.org/"><strong>Jupyter notebook</strong>:</a> A jupyter notebook is an interactive python notebook that allows you to run your code in sequences as well as create and share documents that contain live code, equations, visualizations, and narrative texts. You can decide and specify which cell runs first in the notebook environment. JUPYTER is actually an acronym for 3 languages. Julia, Python, and R. it was built primarily for these three languages.</p><p><a href="https://seaborn.pydata.org/"><strong>Seaborn</strong>:</a> Python’s library for expert visualizations. This library handled virtually all of the visualizations in this exploratory analysis. Basically it provides a high-level interface for drawing attractive and informative statistical graphics.</p><p>Other options that could be used for this exploratory analysis are the<strong> </strong><a href="https://www.spss-tutorials.com/spss-what-is-it/"><strong>SPSS software</strong></a> or the <strong>Microsoft Excel package</strong> but were discarded because it’s more strenuous to work with <a href="https://www.spss-tutorials.com/spss-what-is-it/"><strong>SPSS </strong></a>having to deal with creating a codebook first, then encoding the questionnaire data in a spreadsheet and finally decoding it for visualizations, and its visualizations are very poor, unlike the python’s data visualization libraries.</p><p>While the Microsoft Excel Package is fair with its visualizations, it gets slow when loaded with huge datasets.</p><h3><strong>3.0 EXPLORATORY DATA ANALYSIS</strong></h3><p>The dataset stems from a set of 181 questionnaires administered to the residents of Shomolu LGA in March of 2018. Evan Morris formula was used in calculating the sample size, which was gotten to be <strong>181. A random</strong> sampling technique was also used to administer the questionnaires.</p><p>the codes and dataset to this article can be found on my GitHub <a href="https://github.com/marquisvictor"><strong>here</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*5fq7F0jly8n3UScLA7NL-w.png" /><figcaption>Evan Morris Formula for calculating sampling size</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*Hyww_t1HY9SpgUANyI8vcQ.png" /><figcaption><strong>Evan Morris Formula for calculating sampling size</strong></figcaption></figure><p><strong>Let’s fire up our Jupyter notebook, Load the dataset into a pandas DataFrame. and explore!!!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*kCFjw22H6NUZNB1eRqcqJA.png" /><figcaption><strong>Shomolu questionnaire Dataset</strong></figcaption></figure><p>The image above just shows us how our data looks like in a DataFrame. For a deeper understanding of the dataset in terms of <strong>rows</strong>, <strong>columns</strong>, <strong>Data types</strong>, <strong>missing columns, </strong>etc. we call the pandas’ <strong>info()</strong> method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*2N-kO-APE3Xvful2Uwk9Gg.png" /><figcaption><strong>The result after calling the info() method</strong></figcaption></figure><p>The image above expressly informs us that the dataset set comprises of <strong>181 rows</strong> and <strong>60 columns</strong>. with a handful of missing rows/data points in all 60 columns. Yeah, we also get to see the data types of all the columns in the dataset.</p><p>For simplicity, the dataset would be stratified into the following broad indicators and would be explored accordingly. These indicators include:</p><p><strong>1. Socio-Economic Characteristics</strong></p><p>2. Land Use Characteristics</p><p>3. Infrastructures and Facilities</p><p>4. Source of Attraction to the study area</p><p>5. Education</p><p>6. Health</p><p>7. Security</p><p>8. Social Vices</p><p>9. Tax</p><p>10. Housing condition</p><p>For an in-depth analysis, these indicators would be explored sequentially in a series of posts. Starting from the <strong>Socio-economic characteristics</strong> which would be discussed and visualized here, down to the average Housing conditions</p><h3><strong>Socio-economic characteristics</strong>:</h3><p>This looks at the socio-economic situation of people living in Shomolu LGA; <strong>Education</strong>, <strong>employment</strong> <strong>status</strong>, <strong>household income per month</strong>, <strong>occupation</strong>, <strong>mode of</strong> <strong>transportation, age,</strong> and <strong>sex distributions</strong> among others will be duly explored. Running a quick value count on these indicators we notice the following:</p><p><strong>=&gt; Occupation</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/1*3bZJWE2q1YWER_3CXD7emQ.png" /><figcaption>Percentage of<strong> occupation distribution</strong> in Shomolu LGA</figcaption></figure><p>The occupation distribution of residents in Shomolu LGA includes <strong>Traders</strong>, <strong>Artisans</strong>, <strong>civil servants</strong>, <strong>Industrial workers</strong>, and the <strong>retired</strong>. With a large majority as <strong>Traders</strong> (about 60%) followed by <strong>Artisans</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*e1XrxY1M5quJSCwVyq1qbA.png" /><figcaption>seaborn’s beautiful visualization of the<strong> occupation distribution in Shomou LGA</strong></figcaption></figure><p><strong>=&gt; Rent per month and Tenancy type</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*xThcByKG6_raUrzpqc3lAA.png" /><figcaption>Percentage of <strong>Tenancy distribution</strong> in Shomolu LGA</figcaption></figure><p>From the above image, A large majority of the residents in Shomolu are <strong>Tenants </strong>living in <strong>rented </strong>apartments, about<strong> 84%</strong> apparently. Very few are <strong>landlords </strong>or people living in <strong>inherited apartments.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*CANqmdE1rKGXN_sOMLiubw.png" /><figcaption>Percentage of <strong>housing rents paid per month </strong>in shomolu LGA.</figcaption></figure><p>Deductions from the image above tell us</p><p>1. The <strong>rents paid per month in Shomolu LGA </strong>ranges from <strong>below #5,000 </strong>up until <strong>#30,000 and above.</strong></p><p>2. A large portion of the residents in Shomolu LGA pays between <strong>#5,000</strong> and <strong>#10,000</strong> as housing rent monthly.</p><p><strong>=&gt; Age and Sex:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*4Bxea8LcJ5LgT5m0x54Iwg.png" /><figcaption>percentage of <strong>Gender distribution</strong> in Shomolu LGA.</figcaption></figure><p>It is worthy to note that More males were sampled than females, very few of the respondents were <strong>over 50 years of age</strong>, and from the image below, the most common age range in Shomolu LGA is between <strong>30–40 years.</strong> Followed closely by the<strong> 21–30 age group</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*TeJsIHZUgTbbACOGtPgIkA.png" /><figcaption>percentage of <strong>Age distribution</strong> in Shomolu LGA.</figcaption></figure><p>It is sufficing to say that <strong>Shomolu LGA </strong>has more youths in population than the older folks.</p><p><strong>=&gt; Household Income Per Month:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*gUEs6TcQN0bMCLVDJqN1gA.png" /><figcaption>Categorical plot showing the distribution of <strong>household income per month in Shomolu LGA.</strong></figcaption></figure><p>The income generated by each household in the study area ranges from <strong>below #20,000</strong> to <strong>above #100,000.</strong> and<strong> </strong>In this distribution, it is worthy to note that there are two peaks, which are</p><ol><li>#20,000 and Below</li></ol><p>2. #20,000 - #40,000.</p><h4><strong>…With that being said</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*LA46LOxHPhN7D2l8lQkiDQ.png" /><figcaption><strong>percentage of Transportation Modes distribution in Shomolu LGA.</strong></figcaption></figure><p>it is also worthy to note from the analysis that the most frequent <strong>mode of transportation</strong> in Shomolu LGA is the <strong>public transportation mode, </strong>with about <strong>73% </strong>of the total distribution on its belt.</p><h4><strong>Now to some serious socio-economic exploratory analysis.</strong></h4><p><strong>Visualizing the Relationship between Marital Status and Age in Shomolu LGA</strong></p><p>utilizing Seaborn’s insightful <strong>countplot()</strong> and <strong>catplot()</strong> methods, the following are made evident:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*cy-bFRZ6lw7e_SLkqwiJ2g.png" /><figcaption><strong>Seaborn’s countplot</strong> showing the <strong>relationship </strong>between <strong>marital status</strong> and<strong> age</strong> in <strong>Shomolu LGA</strong></figcaption></figure><p>1. The marital status distribution in Shomolu LGA ranges from <strong>married</strong>, <strong>single</strong>, <strong>divorced, </strong>and <strong>Separated</strong>.</p><p>2. More people in Shomolu LGA are <strong>married </strong>than <strong>single</strong></p><p>3. Most married people in Shomolu are within the age range <strong>of 31–40 years</strong> closely followed by <strong>41–50 years’</strong> age range.</p><p>4. Nobody Under <strong>20 years</strong> of age in Shomolu LGA is <strong>married</strong>.</p><p>5. Very few people are either <strong>divorced </strong>or <strong>separated</strong>.</p><h4><strong>Really fascinating, isn’t it?</strong></h4><p>Adding another indicator <strong>Tenancy Type</strong> to the plot and visualizing it, we also discover the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*e4nDFrK0Q9F5KxobOfU89A.png" /><figcaption><strong>Seaborn’s catplot showing the relationship between Marital status, Age and Tenancy status</strong></figcaption></figure><p>1. A very large majority of the people living in Shomolu LGA are <strong>tenants</strong></p><p>2. Most landlords or owners of dwelling places in Shomolu LGA are <strong>married </strong>and are <strong>over 50 years of age.</strong></p><p>3. Less than <strong>5%</strong> of married couples in Shomoli LGA between the Ages of<strong> 31–40 years</strong> inherited the houses they live in.</p><h4>Say we want to see the relationship between <strong>Occupation</strong> and <strong>Household-income-per-month </strong>in shomolu LGA</h4><p><strong>Seaborn’s countplot() to the rescue.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*FeECEdIUyfU2lPlmY3L40Q.png" /></figure><ol><li>Firstly, we notice very glaringly that the <strong>Trading/commerce</strong> occupation type takes the highest count across all <strong>Household-Income-Categories</strong> in Shomolu LGA. which is in accordance with the earlier stated fact that <strong>majority of the residents of Shomolu LGA are traders or involved with commerce.</strong></li></ol><p>2. Another interesting deduction one can make from the visualization is that in the highest household income category<strong> i.e #100,000 and above,</strong> <strong>industrial workers</strong> and <strong>other occupations</strong> actually come to the limelight</p><p>3. And lastly, most of the <strong>Artisans </strong>in Shomolu earn between <strong>#20,000 </strong>and <strong>#40,000 </strong>monthly.</p><p>There are still loads of information to be mined from this visualization, but I would leave that to you.</p><h4><strong>Finally, checking the relationship between Gender and Occupation distribution in Shomolu LGA still using seaborn’s countplot()</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*9u2fW68EBTPevHcRzGaBlg.png" /></figure><p>From the beautiful visualization above, the following can be inferred:</p><p>1. There are more <strong>females </strong>involved in <strong>Trading/Commerce</strong> in Shomolu LGA than <strong>males</strong>.</p><p>2. There are more <strong>Males </strong>as <strong>civil servants</strong> than <strong>Females</strong></p><p>3. More Males are <strong>industrial workers.</strong></p><p>4. More Males are <strong>artisans </strong>in Shomolu LGA.</p><p>A lot more information could still also be mined from these plots though. but I would leave that to you.</p><h3><strong>4.0 CONCLUSION</strong></h3><p>And that’s all for an in-depth exploration of the <strong>socioeconomic characteristics of residents in Shomolu LGA. </strong>In the next series of posts, we would be diving right into an in-depth exploratory analysis of the other indicators. The next post would particularly be on <strong>Land use characteristics in Shomolu LGA.</strong></p><p>I really hope you were able to learn one or two things from this post, either on Shomolu LGA, Lagos Nigeria or on Exploratory Data Analysis in general. and if you have any questions or observations please feel free to ask in the comments. I always reply my comments!!</p><p>You can find the codes to this article as well as the dataset I used on my <a href="https://github.com/marquisvictor">Github</a> <a href="https://github.com/marquisvictor/Shomolu-EDA/blob/master/Shomolu_Exploratory_Analysis.ipynb"><strong>here</strong></a>, <a href="https://github.com/marquisvictor/Shomolu-EDA/blob/master/socioeconomics.csv"><strong>here</strong></a><strong> </strong>and <a href="https://github.com/marquisvictor/Shomolu-EDA/blob/master/Shomolu%20EDA.docx"><strong>here</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7946c034e831" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CREATING AN UNBIASED TEST-SET FOR YOUR MODEL USING STRATIFIED SAMPLING TECHNIQUE]]></title>
            <link>https://medium.com/@IrekponorVictor/creating-an-unbiased-test-set-for-your-model-using-stratified-sampling-technique-672b778022d5?source=rss-1cb85047a359------2</link>
            <guid isPermaLink="false">https://medium.com/p/672b778022d5</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[sklearn]]></category>
            <category><![CDATA[sampling]]></category>
            <dc:creator><![CDATA[Victor E. Irekponor]]></dc:creator>
            <pubDate>Sun, 10 Feb 2019 16:40:11 GMT</pubDate>
            <atom:updated>2019-11-14T12:14:12.937Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ICNsFpqm4dYUSuGD" /><figcaption>Photo by <a href="https://unsplash.com/@mbaumi?utm_source=medium&amp;utm_medium=referral">Mika Baumeister</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Most real world datasets do not come as train.csv and test.csv. (emphasis on training and testing sets) like we have on<strong> </strong><a href="https://www.kaggle.com/"><strong>kaggle,</strong></a> <a href="https://www.data.gov/"><strong>data.gov</strong></a>, <a href="https://archive.ics.uci.edu/ml/"><strong>uci</strong></a>, and other machine learning repositories. So let’s say you scraped your dataset from a web page, I bet you wouldn’t have a test-set, or your boss at work just throws you a dataset of about 15,000 rows, and asks you to build a predictive machine learning model with it, you definitely have to take out your test-set from the dataset in order to prevent generalization-error or over fitting in your model. The most common way is to call the sci-kits-learn train_test_split method which in a nutshell shuffles the dataset and selects at random a percentage of the dataset for testing and for training depending on your choice parameters.</p><p>So getting down to impressing your boss, a glance at the target column in the dataset tells you you’re up with a regression problem, you smile and say piece of cake.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*spvJVPAFecwoe1D_" /><figcaption>Photo by <a href="https://unsplash.com/@alexloup?utm_source=medium&amp;utm_medium=referral">Alex Loup</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3><strong>What next?</strong></h3><p>A thorough exploratory data analysis (EDA) plus feature engineering and the dataset is ready to be fed into a model, But then, you do not want to show all the answers to the model. So you reserve 40% of the dataset as your your test-set using the <strong>train_test_split</strong> method, and the remaining 60% as the training set. Then you choose your algorithm, fit it, predict and VOILA!! Your model is up and running. That’s how almost everybody else builds a model and yes, you are proud you built yet another model. I should congratulate you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rNFCEzLoEFenCKLX" /><figcaption>Photo by <a href="https://unsplash.com/@sarti46?utm_source=medium&amp;utm_medium=referral">Massimo Sartirana</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>But taking a deeper look at the model, the <strong>train_test_split </strong>method considered purely random sampling method. This is generally fine if your dataset is large enough (hundreds of thousands or even millions rows) but if it’s not, you run the risk of introducing a <strong>significant sampling bias</strong> and you do not really want that. Which is what drove me to prepare this awesome piece again.</p><p>A little deviation, I come from an Urban Planning background, and yes, we carry out lots of <strong>population and sample surveys</strong>. Asides building city wide comprehensive development masterplans, and making urban policies, carrying out population and sample surveys is also one of our trade marks as town planners. In fact, before any physical development planning project commences, we would need to know the population statistics and the demographic distribution of the study area so as to understand the impacts (positive and negative) that the project would have on the people and locality at large, hence the need for surveys. There are a number of survey sampling methods you can find <a href="https://explorable.com/methods-of-survey-sampling"><strong>here</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sMqSpExjdBwMPBA4" /><figcaption>Photo by <a href="https://unsplash.com/@charliedeets?utm_source=medium&amp;utm_medium=referral">Charlie Deets</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>So let’s say we are to carry out a <strong>hypothetical</strong> housing quality survey across Lagos state, Nigeria. And we looking at a total of 5000 houses (hypothetically). We don’t just go to one local government and select 5000 houses, heck NO! rather we ensure that the 5000 houses are a representative of the whole 20 local government areas Lagos state is comprised of. This is called stratified sampling. The population is divided into homogenous strata and the right number of instances is sampled from each stratum to guarantee that the test-set (which in this case is the 5000 houses) is a representative of the overall population. If we used random sampling, there would be a significant chance of having bias in the survey results. Wow, you don’t believe right? Watch and see!! (Actually keep reading)</p><p>Yawns, all these talk would be made more meaningful in code. So i was able to lay my hands on a californian housing dataset which is as good. Was too lazy to write a webscraping script to generate an indigenous dataset.</p><p>So here’s a <a href="https://github.com/marquisvictor/Creating-a-Bias-Free-Testset/blob/master/housing.csv"><strong>link</strong></a><strong> </strong>to the dataset and here’s another <a href="https://github.com/marquisvictor/Creating-a-Bias-Free-Testset/blob/master/Medium_Tutorial_Create_Testset.ipynb"><strong>link</strong> </a>to the jupyter notebook I prepared for this article</p><p>And like I said from earlier, it’s just a housing.csv dataset, no separate testset somewhere. And the goal of this project is not to build models but to <strong>create a bias free testset.</strong> now let’s get down to work.</p><p>first things first, we would be importing the required dependencies and loading the dataset to a pandas <strong>DataFrame.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*pRUjwfT16iIgrgsG1Qv16g.png" /><figcaption>Importing necessary dependencies</figcaption></figure><p>By convention to see if all that code works, and to have a peek at the dataset we would be calling the<strong> .head() </strong>method in pandas to see the first five rows.</p><p>A quick glance at the dataset and we can tell it’s a regression problem judging by the features and the target variable which is the median_house_value, even without being told one can almost guess it is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*xpONl_d9UUwFrJgtCea93g.png" /><figcaption>showing the first five rows of the dataset</figcaption></figure><p>Now to some few exploratory analysis. Lets see what we got here.</p><p>First things first, we want to know the number of columns or feature attributes the dataset comprises as well as the length which is the number of rows. To achieve this, we call the <strong>.info() </strong>method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*XR2bf3Pgfe1V82yZzKv7KQ.png" /></figure><p>from the image above, we can clearly see that the dataset contains a total 10 columns and 29640 rows. What else, we can also see that 9 of the columns in the dataset are numeric and the last one (ocean proximity) is categorical.</p><p>Well, there are a lot of juicy stuffs we could explore from this dataset but the goal of this article is not Exploratory data analysis. I just <strong>might</strong> prepare another article on exploratory data analysis and Feature engineering later, emphasis on might.</p><p>Now Let’s look at some correlations. Python’s<a href="https://seaborn.pydata.org/"><strong> seaborn </strong></a>library comes in very handy here. Uh well,I don’t know about you reading this, but speaking of visualisations, I actually prefer the seaborn library to <a href="https://matplotlib.org/"><strong>matplotlib</strong> </a>a hundred times over,</p><p>Seaborn’s <strong>heatmap</strong> to the rescue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*LGMD6IlADoFNCiN4q0H0Nw.png" /><figcaption>use annot=True to show correlation values.</figcaption></figure><p>This is why I love visualizations, there’s a ton of information we can mine from the heatmap above, a couple of strongly positively correlated features and a couple of negatively correlated features. Take a look at the small bright box right in the middle of the heatmap from total_rooms on the left ’y-axis’ till households and note how bright the box is as well as the highly positively correlated attributes, also note that median_income is the most correlated feature to the target which is median_house_value.</p><p>Now lets be more explicit with the correlations, and see the correlations of features with respect to the target variable. And by target variable, I mean what you are predicting in essence. which is the median house value</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*dI2HqmbV42x9tA2SjLOroA.png" /></figure><p>From the image above, we can see that the most correlated feature to the target variable is the median_income feature.</p><p>back to the aim of this article —<strong> creating a bias free test-set</strong></p><p>From the correlation plots and tables we made from earlier we can see that median_income is the most correlated feature to the target feature which is median_housing_value. Having a correlation score of <strong>.68</strong>, we can almost guess that’s it’s a very important feature and we might want to stratify the test set with respect to this feature making sure that the test-set is a representative of various categories of income in the whole dataset.</p><p><strong>So how do we go about that?</strong></p><p>It’s a no brainer, you just have to pay serious attention to what I’m going to be saying next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Rth36RUyPOojH7KG" /><figcaption>Photo by <a href="https://unsplash.com/@vincentvanzalinge?utm_source=medium&amp;utm_medium=referral">Vincent van Zalinge</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The first thing we want to do is create a new feature or column and call that <strong>median_income_category</strong>. Which would have ’n’ number categories of median income for the entire dataset. Could be 5, 4, or 3, infact any amount, depending on the distribution of the dataset. Then next we want to know actually how many categories we should stratify the median_income <strong>feature/variable</strong> into as we can’t go ahead and create just about any amount we feel like.</p><p>At this juncture I feel we should take a sneak peek at the median_income feature again. Lets at least take a look at the distribution. This can be done using seaborns <strong>distplot()</strong> method or pandas <strong>hist()</strong> function, but I am a seaborn fan boy, so I’ll go with seaborn.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*AC_utz6QoulQzQfKxM8m-Q.png" /></figure><p>From the image above, we can see that most median incomes are clustered between $20,000 and $50,000 with some outliers going far beyond $60,000 making the distribution skew to the right. Mind you, <strong>the median_income </strong>feature was scaled that’s why it looks that way, working with preprocessed features is common in machine learning. I should cover that if there’s gonna be an exploratory data analysis write up.</p><p>While we are still in the business of stratifying our dataset, remember the <strong>median_income_category</strong> I said we were going to create from earlier?? YES that’s right. Now lets get down to coding it out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*7ivhC_BbFa5ky-qxXHpzMA.png" /></figure><p>Explaining the code above, from the first line (ignore the comment), I devided the median income by 1.5 to limit the number of income categories, then I rounded up to the nearest whole number using the numpy ceil() method just to have discrete categories. Right now we’ve succeeded in creating the median_income_category.</p><p>Now lets view the output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/1*sfoyN9V2ffJsOvC-Ug2vAQ.png" /></figure><p>From the output above we can tell that we have 11 categories already with a large majority of income between $20,000 and $50,000 just as we said earlier. <strong>One other thing we don’t want is that we don’t want to have too many categories or strata else the estimate of the stratum importance may be biased</strong>. So we are just going to reduce that to about 5. Could be 4 if you want. Lets write code to do that for us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*g9hwJ_L3ckIQpAptuEL_aQ.png" /></figure><p>So what I did in essence was that I took all the categories of income greater than 5 and merged them into the 5 category.</p><p>And here’s the output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*eGiyVzDbZSRI9jRPVIXj6g.png" /></figure><p>Now that we have our income feature stratified, its time to do the sampling. This time not with <strong>train_test_split</strong> class but with the <strong>StratifiedShuffleSplit </strong>class in sklearn</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hvC7bPRgUCl1YvxEk-kFnQ.png" /></figure><p>And <strong>VOILA!! </strong>we have our stratified train and test set!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LFIHZD4i74SORV1M" /><figcaption>Photo by <a href="https://unsplash.com/@vimarovi?utm_source=medium&amp;utm_medium=referral">Victor Rodriguez</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Finally to the main stuff, lets compare this stratified sampling method (<strong>stratifiedshufflesplit</strong>) I&#39;ve been ranting about all day, and the random sampling method (<strong>train_test_split</strong>) with respect to the overall dataset. Lets see which has more bias.</p><p>We first have to create a new <strong>DataFrame </strong>that would contain the <strong>overall</strong>, <strong>random </strong>and <strong>stratified </strong>testset values of the dataset. the code below handles that for us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*ygP-fN-IkbumpHko6YYzjg.png" /></figure><p>From this table above we can see that, the test set generated using s<strong>tratified sampling method</strong> is quite similar in values to that of the<strong> overall dataset</strong> across all categories 1 to 5, unlike the test-set generated using the<strong> random sampling method</strong>, a bit skewed it is, if you ask me.</p><p>So mission accomplished!! we have been able to eliminate sampling bias from the test-set to the barest minimum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*08Y90wgS7DVV053e" /><figcaption>Photo by <a href="https://unsplash.com/@rawpixel?utm_source=medium&amp;utm_medium=referral">rawpixel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><em>We spent quite a lot of time on our test-set generation for a good reason, this is an often neglected area of most machine learning project. Many of this ideas would be useful later when we discuss cross-validation.</em></p><p>Disadvantages of using simple random sampling to estimate a larger population can be found <a href="https://www.investopedia.com/ask/answers/042815/what-are-disadvantages-using-simple-random-sample-approximate-larger-population.asp"><strong>here</strong></a>.</p><p><a href="https://www.oreilly.com/library/view/hands-on-machine-learning/9781492032632/">Hands-On Machine Learning with Scikit-Learn and TensorFlow: Concepts, Tools, and Techniques to Build Intelligent Systems” by Aurelien Geron. Part 1, Chapter 2.</a></p><p><strong>THANKS FOR READING!!</strong></p><figure><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_image"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f2IVAl0TbsfES9cFGYr40g.png" /></a></figure><p>📝 Read this story later in <a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_read_later_text">Journal</a>.</p><p>🗞 Wake up every Sunday morning to the week’s most noteworthy Tech stories, opinions, and news waiting in your inbox: <a href="https://usejournal.com/newsletter/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_text">Get the noteworthy newsletter &gt;</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=672b778022d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CLIMATE CHANGE AND FLOODING IN LAGOS - What Do You Know?]]></title>
            <link>https://medium.com/@IrekponorVictor/climate-change-and-flooding-in-lagos-what-do-you-know-501464d9db2?source=rss-1cb85047a359------2</link>
            <guid isPermaLink="false">https://medium.com/p/501464d9db2</guid>
            <category><![CDATA[climate-change]]></category>
            <category><![CDATA[sustainability]]></category>
            <category><![CDATA[urban-planning]]></category>
            <category><![CDATA[lagos]]></category>
            <category><![CDATA[flooding]]></category>
            <dc:creator><![CDATA[Victor E. Irekponor]]></dc:creator>
            <pubDate>Sun, 03 Feb 2019 20:50:58 GMT</pubDate>
            <atom:updated>2019-02-14T17:56:40.018Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>CLIMATE CHANGE AND FLOODING IN LAGOS- What do you know?</strong></p><p>As our faces are different so are our hearts different, it is to this end that Socrates says</p><p><em>“Man know thyself”.</em></p><p>Nigeria currently ranks 4th as the most climate vulnerable country followed by Haiti, Bangladesh, Senegal and Sudan. Philippines tops the list with Cambodia, Vietnam, at second and third respectively.</p><p><a href="https://www.vanguardngr.com/2018/10/nigeria-ranks-4th-among-most-climate-vulnerable-countries/">Nigeria currently ranks 4th</a>, with Lagos ranking 10th most vulnerable coastal city since 2014</p><p>The impact of climate change is no longer as distant as most people think it is. In fact, it is right in front our noses. It has arrived Nigeria with substantial evidence spread across the six geographic zones ranging from flooding, rising sea temperature levels, Erratic rainfalls, food insecurity, irregular hot and cool weathers among others.</p><p><a href="https://lagosstate.gov.ng/about-lagos/">Lagos state is the smallest state in our great country Nigeria</a>, yet it has the highest urban population which is 27.4% of the National estimate [UN-HABITAT]. In 2015, the UN-HABITAT and other international development agencies estimated Lagos to have about 24.6 million inhabitants with the current growth rate considering the fact that the population is growing 10 times faster than that of New York &amp; Los Angeles, and more than the population of 32 African Nations combined, the state population is expected to hit the 35 million mark by 2050.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*M8SDhx-ym8G3DMitc4RXmA.jpeg" /><figcaption>Segmented map showing the city of Lagos</figcaption></figure><p>Big question; with so many millions emerging within the Lagos metropolitan soon, <a href="https://www.vanguardngr.com/2018/12/huge-lagos-housing-deficit-firm-to-deliver-2000-housing-units-in-nine-months-in-three-lgas/">with a housing deficit of over 3 million houses</a>, how do we cope with the flood??</p><p>Lagos state government has responded to this challenge by drawing up model city plans over the last 10 years for a number of areas including, Badagry, Apapa, Lekki, Agege/Ifako-Ijaiye amongst others which seeks to transform the entire state to a sprawling garden city metropolis. Theoretically these plans have found ways to accommodate around 30 million residents within the state by 2030, sidelining the outstanding housing deficits which we won’t even begin to talk about.</p><p>This response is however complicated by climate change. In the sense that they may address the increasing volume of rain water brought about by the more intensive storms expected across the state, but it does not address the other impacts climate change is expected to bring to Lagos such as tidal surges, water logging of soil, rising sea levels, subsidence, erosion, salinity of the water table, and diseases that would spread in a saturated environment. <a href="https://guardian.ng/news/nimet-warns-of-climate-induced-diseases-in-2019/">Needless to say the Nigerian meteorological agency</a>, (NIMET) has already warned that there would be a high prevalence of climate induced diseases such as malaria, cerebrospinal meningitis, and respiratory diseases in many parts of Nigeria in 2019.</p><p>Most coastal cities are susceptible to inundation from rising sea levels. Erratic rainfalls etc and Lagos is not exempted.</p><p>In 2008, the OECD determined that 3.2 million Lagosians may be exposed to flooding from climate change as a result of rising sea levels, increasing storm intensities and land subsidence, making it the 15th most vulnerable city in the world in terms of all 136 million population of the world port cities. This figures worsened six years later in 2014 and Lagos became the 10th most vulnerable city in the world, and it’s still getting worse. I’m not trying to scare anybody. I’m just sharing my quick research outcome.</p><p>Thus the challenge should be how to accommodate these future millions as quickly as possible in formal developments and on dry land both of which are in undersupply in Lagos state.</p><p>Examining the total projected population for Badagry to the southwest stretch of the state, Apapa to the southernmost stretch and Lekki to the southeastern stretch of the state under their respective model city plans is about 11 million persons by 2032. With nowhere else to expand, it is exactly these swamps and lowlands in the southernmost parts of Lagos state that Lagos plans to accommodate the future million populations, which would place them directly in harm’s way judging from earlier statistics.</p><p>Hence if that is even going to be done, the first thing would be to provide a much more technologically advanced barricade around all low-lying areas that have been or are to be reclaimed. Setting high walls around the Lekki and Badagry coastlines, as well as barriers around the lagoon. It’s a really big project, I mean, if Lagos wants to house 11 million people in these low lying areas, then we are talking about a project similar in magnitude to the M<a href="https://www.water-technology.net/projects/mose-project/">OSE (Moses) project, under construction in the venetian lagoon, Italy</a>. The first environmental impact study was accepted in 1998 which was later improved on in 2002, construction work started in 2003 and up until date, the project has not been completed and has already cost the Italian government over 7 billion dollars. If Lagos was to do something similar, it would still be on top of the several billion-dollar worth of drainage work the government hopes to carry out during the full implementation of the model city plans. But judging by the current look of things, I am not sure any of that is even possible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/259/1*fQ-X7WxYAIiCyxsVjm2O-Q.jpeg" /><figcaption><a href="https://www.water-technology.net/projects/mose-project/">Project MOSE (moses), venice, Italy.</a></figcaption></figure><p>An alternative is to choose not to locate the vast majority of the 11m or more future Lagosians in these low lying areas and focus more on densifying urban areas, rather than attempt to squeeze so many millions on its narrow water logged coastlines.</p><p>Densification is a term used by urban planners, designers and theorists to describe the increasing density of people living in urban areas, and when we are talking about urban densification we mean a compact city with solid infrastructures and high rise buildings enough to accommodate as many people as possible. Advocates of densification argue that the denser a city is, the more sustainable it becomes, since dense cities use less energy per person than suburban or rural areas where people are spread over a wider distance and so people travel more often and further. Tokyo, home to over 13 million people is often used as an example of positive densification.</p><p><a href="https://au.linkedin.com/in/amy-leung-b45471a">Quoting Amy Leung</a>, the director general, East Asia Department at the Asian Development Bank (ADB), Urban densification, or increasing the number of dwelling units and mixed-use spaces per acre, is the key to tapping into the potential of cities to become part of the solution to climate change because it encourages efficiency and conservation. It is a critical aspect of making a city more sustainable and environmentally friendly. By being more organized and filling in vacant lots with shared spaces, cities can efficiently deliver water, electricity, and other municipal services to more people in a small amount of space using few resources and less energy. this might just be a working alternative to housing the future million populations in Lagos state.</p><p>Another solid alternative would be to look for land elsewhere, and that can only be gotten if we only could look NORTH. Unfortunately, most of the higher grounds are within the geographic boundary of our Northern neighbor Ogun state, the Lagos metropolitan could grow more securely and comfortably by shifting the bulk of that growth into outlining suburbs to the north and northeastern stretch of the state developing other suburban areas beyond them. If only we could forget the artificial differences and focus on the economic and regional benefits of conurbation: that is the two cities coming together resulting in growth pole centers for residential and economic development. We have examples in Sao Paulo, Brazil and in New Delhi, India. If you ask me, high, and strong land is quite better than risking future millions of lives on reclaimed land.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*P7jhP8UxY6Ahb98kgUkUIg.png" /><figcaption>Map of Lagos state, showing our Northern Neighbour, (Ogun state)</figcaption></figure><p>These are just ideas that came to me while I was reading and preparing this research article, they might not necessarily be standard by all means but then, it’s worth reconsidering. Climate change is not just an environmental problem, it is a developmental problem that is directly linked to and responsible for multiple crises plaguing the world today.</p><p>In conclusion, there is an urgent need for the Lagos state government to encourage researchers, who are interested to provide solutions and clear cut mitigation strategies to deal with environmental disasters resulting from climate change.</p><p>That is my two kobo, and thanks for reading!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=501464d9db2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>