<?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 Kalpan Mukherjee on Medium]]></title>
        <description><![CDATA[Stories by Kalpan Mukherjee on Medium]]></description>
        <link>https://medium.com/@mukherjeekalpan?source=rss-81a8d186b626------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*RENRmk0lcoJQTUWAODCXXQ.jpeg</url>
            <title>Stories by Kalpan Mukherjee on Medium</title>
            <link>https://medium.com/@mukherjeekalpan?source=rss-81a8d186b626------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 15 May 2026 18:36:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mukherjeekalpan/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[Deep dive into C++ STLs — vectors]]></title>
            <link>https://medium.com/@mukherjeekalpan/deep-dive-into-c-stls-vectors-a16d2cdcc1dc?source=rss-81a8d186b626------2</link>
            <guid isPermaLink="false">https://medium.com/p/a16d2cdcc1dc</guid>
            <category><![CDATA[stl]]></category>
            <category><![CDATA[c]]></category>
            <category><![CDATA[competitive-programming]]></category>
            <category><![CDATA[vector]]></category>
            <dc:creator><![CDATA[Kalpan Mukherjee]]></dc:creator>
            <pubDate>Sat, 01 Aug 2020 22:32:33 GMT</pubDate>
            <atom:updated>2020-08-01T22:32:33.974Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deep dive into C++ STLs — vectors</h3><p>Hey! Continuing on with the C++ STLs series, this time we are going to be taking a look at <strong>vectors.</strong></p><p>If a newbie, you should think of vectors as a replacement for arrays. Any place where you would generally use an array can be swapped out by a vector. Vectors are most efficient if you are continuously adding and deleting elements.</p><blockquote>The main difference between the two being that vectors, unlike arrays, are dynamic i.e. they can keep expanding as more data needs to be stored.</blockquote><blockquote>However, it must be noted that vectors consume more memory than arrays.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Kn7ooswQuX8HZxVj6AYIg.png" /></figure><h3>Show me the code💻</h3><p><strong>Iterators</strong></p><p>These point to an address in the vector, generally the beginning or end</p><pre><em>syntax: vector-name.begin();<br>        vector-name.end();</em></pre><pre>vInt.begin();<br>vChar.end();</pre><p><strong>Declaring a vector</strong></p><pre><em>syntax: vector&lt;data-type&gt; vector-name;</em></pre><pre>vector&lt;int&gt; vInt;<br>vector&lt;char&gt; vChar;</pre><p><strong>Declaring a vector with number of elements</strong></p><pre><em>syntax: vector&lt;data-type&gt; vector-name(number_of_elements);</em></pre><pre>vector&lt;int&gt; vInt(10);<br>vector&lt;char&gt; vChar(20);</pre><p>By default, Integer vectors declared along with number of elements will be initialized with <strong>‘0’</strong> in each field, and Char vectors with <strong>‘’(empty char)</strong>.</p><p><strong>Declaring with number of elements and default value</strong></p><pre><em>syntax: vector&lt;data-type&gt; vector-name(#elements, default_value);</em></pre><pre>vector&lt;int&gt; vInt(10, -1);<br>vector&lt;char&gt; vChar(20, &#39;a&#39;);</pre><p><strong>Declaring with initial values</strong></p><pre><em>syntax: vector&lt;data-type&gt; vector-name = {e1, e2, e3, e4....};</em></pre><pre>vector&lt;int&gt; vInt = {1, 2, 3, 4};<br>vector&lt;char&gt; vChar = {&#39;a&#39;, &#39;b&#39;, &#39;c&#39;};</pre><p><strong>Declaring a 2-D vector</strong></p><pre><em>syntax: vector&lt;vector&lt;data-type&gt;&gt; vector-name;</em></pre><pre>vector&lt;vector&lt;int&gt;&gt; vInt;<br>vector&lt;vector&lt;char&gt;&gt; vChar;</pre><p><strong>Initialize vector with another vector</strong></p><pre>vector&lt;int&gt; num = {1,2,3,4,5,6};<br>    <br>vector&lt;int&gt; arr(num.begin(), num.end());</pre><p><strong>Assigning one vector to another (after declaration)</strong></p><pre>vector&lt;int&gt; arr1, arr2;<br>arr1 = {num.begin(), num.end()};</pre><pre>arr2 = vector&lt;int&gt;{num.begin(), num.end()};</pre><p><strong>Initialize 2-D vector with 1-D vector</strong></p><pre><em>syntax: vector&lt;vector&lt;data-type&gt;&gt; vector-name(number of rows, 1-D vector);</em></pre><pre>vector&lt;int&gt; num = {1,2,3,4};<br>vector&lt;vector&lt;int&gt;&gt; vInt1(2, num);<br>vector&lt;vector&lt;int&gt;&gt; vInt2(2, {num.begin(), num.end()});<br>vector&lt;vector&lt;int&gt;&gt; vInt3(2, vector&lt;int&gt;(5,0));</pre><p><strong>Inserting element to the end of the vector</strong></p><pre><em>syntax: vector-name.push_back(element);</em></pre><pre>vInt.push_back(11);<br>vChar.push_back(&#39;X&#39;);</pre><p><strong>Inserting element at a specific position using iterators</strong></p><pre>num.insert(num.begin(), 2);<br>num.insert(num.end(), 2);</pre><p><strong>Delete an element from the end of the vector</strong></p><pre><em>syntax: vector-name.pop_back();</em></pre><pre>vInt.pop_back();<br>vChar.pop_back();</pre><p><strong>Delete all the elements in the vector</strong></p><pre><em>syntax: vector-name.clear();</em></pre><pre>vInt.clear();<br>vChar.clear();</pre><p><strong>Sorting a vector</strong></p><pre>sort(v.begin(), v.end());<br>sort(v.begin(), v.end(), greater&lt;<strong>int</strong>&gt;());</pre><p>Passing a <em>comparator</em> like greater&lt;int&gt; will override the default comparator and sort the vector in descending order.</p><p><strong>Accessing elements with []</strong></p><p>Usage of the [] square brackets operator is the same as in an array</p><pre><em>syntax: vector-name[index];</em></pre><pre>vInt[3];<br>vChat[2];</pre><p><strong>Iterating through vector using iterators</strong></p><pre>for(auto it = num.begin(); it!=num.end(); it++)<br>       cout&lt;&lt;*it&lt;&lt;&quot; &quot;;</pre><p><strong>Front() &amp; Back()</strong></p><pre>vInt.front();<br>vChar.end();</pre><p>These two functions return the first and the last element of the vector respectively.</p><p><strong>Swap elements of two vectors</strong></p><pre>vector&lt;int&gt; a{1,2,3};<br>vector&lt;int&gt; b{4,5,6);</pre><pre>a.swap(b);</pre><h4>C++11 specific</h4><p><strong>cbegin() &amp; cend();</strong></p><pre>vector-name.cbegin();<br>vector-name.cend();</pre><p>These are mostly similar to begin() &amp; end() with the only difference being that these iterators cannot be used to modify and element. They have Read-Only access.</p><p>These are most of the commonly used operations of vectors. As you can see there are quite a few things that can be done with them. So go ahead and try these out yourself!</p><p>Thanks for reading this article. Leave a <strong>clap👏 </strong>if you learnt something.</p><p>You can connect with me on through my <a href="https://kalpan.codes//">Website</a> or <a href="https://www.linkedin.com/in/kalpanmukherjee/">LinkedIn</a>. Cheers!🎉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a16d2cdcc1dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[C++ STLs — unordered_map]]></title>
            <link>https://medium.com/@mukherjeekalpan/c-stls-unordered-map-3aaa653ccf78?source=rss-81a8d186b626------2</link>
            <guid isPermaLink="false">https://medium.com/p/3aaa653ccf78</guid>
            <category><![CDATA[unordered-map]]></category>
            <category><![CDATA[stl]]></category>
            <category><![CDATA[time-complexity]]></category>
            <category><![CDATA[c]]></category>
            <category><![CDATA[competitive-programming]]></category>
            <dc:creator><![CDATA[Kalpan Mukherjee]]></dc:creator>
            <pubDate>Sat, 01 Aug 2020 15:28:28 GMT</pubDate>
            <atom:updated>2020-08-01T18:09:10.441Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deep dive into C++ STLs — unordered_map</h3><p>Hey! Welcome to the first chapter in the C++ STLs series. Here we will explore in depth about different STLs provided by C++</p><p>But first, <strong><em>What is are STLs? </em>😯</strong></p><p><strong>STL</strong> stands for Standard Template Library. It is a set of template classes that have been provided to us for easy integration of standard data structures and algorithms like linked-lists, stacks, arrays, sorting, searching etc. Read more about them <a href="https://en.wikipedia.org/wiki/Standard_Template_Library">here</a>.</p><p>In this article we are going to tackle the one data-structure that has proved immensely useful for me over the years of competitive coding — <strong>unordered_map.</strong></p><p>It can be visualized as a list in which each element in-turn contains two sub-elements — <em>key</em> and <em>value. </em>Internally it uses something called a <strong>hash-function</strong> which takes in your <em>key</em> value, churns it through complex equations and computes a <em>hash-value</em>. This <em>hash-value</em> is used to internally store the <em>value</em> provided by the user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RCntWRL8U5okbdnoPIc-9w.png" /><figcaption>Credits: Wikipedia</figcaption></figure><p>It is because of this <em>hash-value </em>that locating individual items later in the data-structure’s life-cycle becomes much faster.</p><blockquote>This is why the average cost of <strong>search, delete </strong>and <strong>insert</strong> is <strong>O(1).</strong></blockquote><p>NOTE: The worst case for searching an element go up-to O(n) depending on the Hash-function used and the probability of collisions but it is very unlikely to happen with modern compilers.</p><h3>Show me the code 💻</h3><p><strong>Declaring an unordered_map</strong></p><pre><em>syntax: unordered_map&lt;key-datatype, value-datatype&gt; umap-name;</em></pre><pre>unordered_map&lt;int, int&gt; intToInt;</pre><pre>unordered_map&lt;char, int&gt; charToInt;</pre><p><strong>Inserting elements</strong></p><pre><em>syntax: umap-name[key] = value;<br>        umap-name.insert(make_pair(key, value));</em></pre><pre>intToInt[420] = 69;<br>charToInt[&#39;a&#39;] = 2;<br>intToInt.insert(make_pair(1,1));<br>charToInt.insert(make_pair(&#39;a&#39;,2));</pre><p>If the <em>value</em> data-type is Integer, then the default value will be set to ‘0’ which can let us do interesting things like</p><pre>int nums[] = {2, 3, 4, 5, 2, 3};<br>    <br>for(auto num: nums){<br>    intToInt[num]++;<br>}</pre><p>The code snippet above will let us count the number of occurrences of each element using the increment operator without having to initialize the unordered_map first.</p><p><strong>Accessing all elements of umap</strong></p><pre>for(auto it: umap){<br>    cout&lt;&lt;umap.first&lt;&lt;&quot; &quot;&lt;&lt;umap.second&lt;&lt;&quot;\n&quot;;<br>}</pre><pre>for(auto p = umap.begin(); p!=umap.end(); p++){<br>    cout&lt;&lt;p-&gt;first&lt;&lt;&quot; &quot;&lt;&lt;p-&gt;second&lt;&lt;&quot;\n&quot;;<br>}</pre><p>It must be obvious but <em>umap.first &amp; p-&gt;first </em>lets you access the first element or the <em>key</em> and <em>umap.second &amp; p-&gt;second</em> lets you access the second element or the <em>value</em>.</p><p><strong>Finding a key exists in unordered_map</strong></p><pre>if(umap.find(key)!=umap.end())<br>    cout&lt;&lt;key&lt;&lt;&quot; was found\n&quot;;<br>else<br>    cout&lt;&lt;key&lt;&lt;&quot; was not found\n&quot;;</pre><p>umap.find(<em>key</em>) returns an iterator to the position of the key in the unordered_map if it exists, or umap.end() if it does not exist.</p><p><strong>Find key and access corresponding value</strong></p><pre>auto it = umap.find(key);</pre><pre>if(it!=umap.end()){<br>    cout&lt;&lt;&quot;key is: &quot;&lt;&lt;it-&gt;first&lt;&lt;&quot; value is: &quot;&lt;&lt;it-&gt;second&lt;&lt;endl;<br>}</pre><p><strong>Erase element from unordered_map</strong></p><pre>umap.erase(key);</pre><pre>umap.erase(iterator);</pre><pre>umap.erase(iterator_begin, iterator_end);</pre><p>These are most of the commonly used operations of unorderd_map. So go ahead and try these out yourself!</p><p>Thanks for reading this article. Leave a <strong>clap👏 </strong>if you learnt something.</p><p>You can connect with me on through my <a href="https://kalpan.codes/\">Website</a> or <a href="https://www.linkedin.com/in/kalpanmukherjee/">LinkedIn</a>. Cheers!🎉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3aaa653ccf78" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Auto start apps and fix them to workspaces on startup — Ubuntu]]></title>
            <link>https://medium.com/@mukherjeekalpan/auto-start-apps-and-fix-them-to-workspaces-on-startup-ubuntu-a1124f1af7f3?source=rss-81a8d186b626------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1124f1af7f3</guid>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[workspace]]></category>
            <category><![CDATA[automatic]]></category>
            <category><![CDATA[startup]]></category>
            <dc:creator><![CDATA[Kalpan Mukherjee]]></dc:creator>
            <pubDate>Wed, 08 Apr 2020 13:58:21 GMT</pubDate>
            <atom:updated>2020-04-08T14:02:58.914Z</atom:updated>
            <content:encoded><![CDATA[<h3>Auto start apps and fix them to workspaces on startup — Ubuntu</h3><h4>Make your Ubuntu workflow even smoother and flex on them Windows fanbois</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LD0u5w846EMeFm8_kYXjHw.png" /></figure><p>In this article I will quickly go through how to set custom applications to open on startup and also fix them to their predefined workspaces without the touch of a button.</p><p>First you need to select the applications you will typically use every time you boot into your Ubuntu machine. For this example I have selected <strong>Firefox Web Browser, VS Code, Spotify </strong>and <strong>Hyper</strong>(a terminal alternative that I highly recommend you check out for its looks).</p><p>So first off you need to select the <strong><em>Super Key, </em></strong>this will most likely be the <strong>Windows Key</strong> on your machine. This will bring up the <strong>Search Bar</strong>, here you need to search for “<strong><em>Startup Applications”</em></strong><em> </em>and select the icon that shows up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_4Dv0gZXhK8O6QjgeFDKAQ.png" /><figcaption>Search for ‘Startup Applications’</figcaption></figure><p>In the window that shows up, select <strong>Add.</strong></p><p>You can leave the <strong>Name </strong>and <strong>Comment</strong> empty as they don’t affect its working. In the <strong>Command section </strong>you need to enter the name of the application, here are the ones I found for the apps I used -</p><p>Firefox(<strong>firefox</strong>), Spotify(<strong>spotify</strong>), Hyper(<strong>hyper</strong>), VS Code(<strong>code</strong>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*SagobSgDIvr7GgkEYHqq_Q.png" /><figcaption>Add command to open the application on startup</figcaption></figure><p>You can get more information about finding the command for your application of choice <a href="https://askubuntu.com/questions/126268/how-to-find-out-the-terminal-command-of-an-application">here</a>.</p><p>Right now your selected applications will open on Startup but will all crowd on the default workspace. To have them automatically stick to separate workspaces every time they startup, we need to install a tool called <strong><em>Auto Move Windows.</em></strong></p><p><strong>Ubuntu 16.04 </strong>— This tool comes as a part of <strong><em>gnome-tweak-tool</em></strong>. To install it just run the following command on your terminal</p><pre>sudo apt-get install gnome-tweak-tool</pre><p><strong>Ubuntu 18.04</strong> — The tool is no longer included with <strong><em>gnome-tweak-tool</em></strong>. Instead go to <strong>Ubuntu Software</strong> and search for <strong>“Auto Move Windows”.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*5nx9Z1EM1a5P1uv1zl74NA.png" /><figcaption>Search for “Auto Move Windows” on Ubuntu Software</figcaption></figure><p>Next press the <strong>Super Key</strong> again and search for <strong>“Tweaks”</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Px8iX8MOEbDnHbxz8CdLFg.png" /><figcaption>Search for “Tweaks”</figcaption></figure><p>Go to <strong>Extensions</strong> and Turn On “Auto Move Windows”. Click on the <strong>Settings Icon </strong>that appears next to the Turn On button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*sPbckYPybzl1Fw6V_CH88Q.png" /><figcaption>Turn on “Auto Move Windows” and click on the settings icon</figcaption></figure><p>Here you can select <strong>Add Rule</strong> and search for an application and press the ‘+’ or ‘-’ symbols to select the default workspace for that app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*mN90VvyMyeC358xwR84lpw.png" /><figcaption>Search for application and select workspace</figcaption></figure><p>After you’re done your list should looks something like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*XUjKbFy-opN1dMtaKoCkww.png" /><figcaption>After selecting all the applications and workspaces</figcaption></figure><p><strong>That’s it for this article folks! Thanks for reading and do comment if you felt this was useful for you. Any pointers on things I have inadvertently gone wrong with is appreciated!</strong></p><p><a href="https://askubuntu.com/questions/89946/open-application-in-specific-workspace">Here’s</a> the original Ask Ubuntu post for fixing workspaces.Connect with me on <a href="https://www.linkedin.com/in/kalpanmukherjee/">Linkedin</a> or check out my <a href="https://kalpan.codes">website</a>.</p><p><a href="https://kalpan.codes">Kalpan Mukherjee</a></p><h3>Don’t forget to give me your 👏 !</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*2lvCls4yjxVMfZSR" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1124f1af7f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Predicting Electricity Outage with Keras and Python]]></title>
            <link>https://medium.com/data-science/predicting-electricity-outage-with-keras-and-python-fbd1b299a24e?source=rss-81a8d186b626------2</link>
            <guid isPermaLink="false">https://medium.com/p/fbd1b299a24e</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[bangalore]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[electricity]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Kalpan Mukherjee]]></dc:creator>
            <pubDate>Mon, 16 Mar 2020 20:18:15 GMT</pubDate>
            <atom:updated>2020-03-26T15:04:47.580Z</atom:updated>
            <content:encoded><![CDATA[<h4>Know when, where and for how long there can be a electricity outage in your city</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*ffB1cdb0ZTDVq0v2giccnQ.jpeg" /></figure><p>In this article we shall explore the process of me and my team developing a web application to predict the probability of an electricity outage in Bangalore. Results can be reproduced in any city as long as sufficient data can be collected.</p><h3>PART 1 : Putting together the data</h3><p>We found publicly available unscheduled power outage data from <a href="https://www.bescom.org/upo/public.php">BESCOM’s website</a>. Though not an elegant solution, due to the website loading all the 50,000+ rows all at once, a simple <strong>Ctrl+A, Ctrl+C </strong>and <strong>Ctrl+V </strong>into an excel sheet saves us from writing an elaborate scrapping code.</p><figure><img alt="An excel sheet showing the data “copied” from BESCOM’s website" src="https://cdn-images-1.medium.com/max/1024/1*RFBIZdiEHR6qlMSEuNE3Mg.jpeg" /><figcaption>Excel Sheet showing the data “copied” from BESCOM’s website</figcaption></figure><p>Loading this into our python code is fairly straight forward. Our file is saved as <strong>BESCOM-electricity-data-outrage.xlsx.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf4afbdfc59a04eca3409ca059a4993f/href">https://medium.com/media/cf4afbdfc59a04eca3409ca059a4993f/href</a></iframe><pre>   Sl. No.    ...     Updated By<br>0      1.0    ...         Sushma<br>1      2.0    ...         Sushma<br>2      3.0    ...         Sushma<br>3      4.0    ...         SUSHMA<br>4      5.0    ...      Devaraj R</pre><pre>[5 rows x 12 columns]</pre><p>To see all the individual columns, we use</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5bb20e766ddd9d0fa67d1b538124c489/href">https://medium.com/media/5bb20e766ddd9d0fa67d1b538124c489/href</a></iframe><pre>array([&#39;Sl. No.&#39;, &#39;Circle&#39;, &#39;Division&#39;, &#39;Subdivision&#39;, &#39;Substation&#39;,<br>       &#39;From&#39;, &#39;To&#39;, &#39;LC Duration&#39;, &#39;Feeders&#39;, &#39;Areas Affected&#39;,<br>       &#39;Reason For LC&#39;, &#39;Updated By&#39;], dtype=object)</pre><p>As most of these attributes do not add a lot of information to our understanding, to make our task simpler and easier to visualize, we will only keep the columns <strong>Sl. No., Division, From </strong>and <strong>LC Duration.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91166f844ca2f924494e15bd66a2fb9b/href">https://medium.com/media/91166f844ca2f924494e15bd66a2fb9b/href</a></iframe><pre>           Division                From     LC Duration<br>0          HSR Division 2019-11-06 21:07:00  0 days 1 hours<br>1          HSR Division 2019-11-06 16:00:00  0 days 2 hours<br>2  Koramangala Division 2019-11-06 14:00:00  0 days 2 hours<br>3          HSR Division 2019-11-06 14:29:00  0 days 1 hours<br>4           Indiranagar 2019-11-06 13:00:00  0 days 2 hours</pre><p>Next we need to add data about whether a particular day was a holiday or not. The intuition being that there is an increased electricity consumption on a holiday thus a higher chance of an outage. For this we first find the earliest and oldest date which is contained in our dataset.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b1c3e81465f85067bafda437de30740/href">https://medium.com/media/6b1c3e81465f85067bafda437de30740/href</a></iframe><pre>Timestamp(&#39;2019-11-06 21:07:00&#39;)<br>Timestamp(&#39;2014-05-05 02:40:00&#39;)</pre><p>Now we find all the public holidays within this range and add them to a separate excel sheet <strong>holidayData.xlsx.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/117/1*fLemMzUclF1SIYLgcv6R8Q.jpeg" /><figcaption>List of all holidays</figcaption></figure><p>The next step is to map these holidays into our existing dataset. For this we create another column called <strong>Holiday</strong> in our dataset and assign all the rows to zeros. Going through the dates we update the column to ‘1’ is the date appears in holidayData.xlsx.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5828fc91da84ff63fafcc496731ef95/href">https://medium.com/media/d5828fc91da84ff63fafcc496731ef95/href</a></iframe><pre>Holiday  Division   From  LC Duration   Date                                   <br>    0.0     16136  16179        16179  16179<br>    1.0      1116   1117         1117   1117</pre><p>Next we will map the population of the the various <strong>Divisions </strong>with higher population divisions having a theoretically higher chance of suffering from power outage.</p><p>First we find the list of unique <strong>Divisions</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9b8c4a5d8834f627e5f698d11a2ef8a/href">https://medium.com/media/b9b8c4a5d8834f627e5f698d11a2ef8a/href</a></iframe><pre>array([&#39;HSR Division&#39;, &#39;Koramangala Division&#39;, &#39;Indiranagar&#39;,<br>       &#39;Shivajinagar&#39;, &#39;Hebbal&#39;, &#39;Whitefield&#39;, &#39;Malleshwaram&#39;,<br>       &#39;Rajaji Nagara Division&#39;, &#39;Jayanagar&#39;, &#39;Jalahalli&#39;,<br>       &#39;Kengeri Division&#39;, &#39;R R NAGAR&#39;, &#39;Vidhanasoudha&#39;,<br>       &#39;Peenya Division&#39;, nan], dtype=object)</pre><p>We now find the estimated population for each of these regions. This task will have varied accuracy depending on if this data is publicly available. In our case the last census was done in 2011 so we have to extrapolate the population to reflect the current total population of Bangalore. As there are only 14 regions, instead of adding this data into another excel file, we will enter the values in a dictionary. Then we create another column in the dataset called <strong>Population </strong>and assign it the same values as <strong>Division</strong>. We then use the <strong>replace</strong> function in python to replace the <em>keys</em> in Population with the <em>values </em>in <strong>div_pop_dict.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ab6c5dbe1b097d7862524fa433bf426/href">https://medium.com/media/6ab6c5dbe1b097d7862524fa433bf426/href</a></iframe><pre>0    105265.0<br>1    105265.0<br>2     63987.0<br>3    105265.0<br>4     58830.0<br>Name: Population, dtype: float64</pre><p>Going on ahead, we have found the daily minimum and maximum temperature between the date range we mentioned before. This data is stored in <strong>weather_data_max_min.xlsx. </strong>We will load the dataset and change the <em>datetime</em> values into <em>dates.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2a91d00602cd0069cc0f318c66e05cd/href">https://medium.com/media/e2a91d00602cd0069cc0f318c66e05cd/href</a></iframe><pre>         Date  Max Temp  Min Temp<br>0  2014-01-01      18.7      14.8<br>1  2014-01-02      27.3      15.4<br>2  2014-01-03      27.7      13.1<br>3  2014-01-04      29.5      12.0<br>4  2014-01-05      29.6      14.1</pre><p>Now we follow the same process as with the population dataset i.e. creating a dictionary with dates and temperature values and replacing outage dates with min/max temperatures.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/08d3177a94bb108af49d4dd8414baab4/href">https://medium.com/media/08d3177a94bb108af49d4dd8414baab4/href</a></iframe><pre>  Max Temp Min Temp<br>0     34.3     15.3<br>1     34.3     15.3<br>2     34.3     15.3<br>3     34.3     15.3<br>4     34.3     15.3</pre><p>These are all the features that we will be working with for this example.</p><p>We need to, now, create labels for classification. Right now we have details for the combination of features that produce and <strong>outage</strong>. However we need to feed data about which conditions <strong>do not cause outage</strong> into the model for it to properly understand the distinction and formulate rules accordingly.</p><p>How we are going to approach this particular problem is by selecting each row where we have the <em>date and time </em>of when and where an outage occurs, and labeling that as <strong>‘1’ for outage. </strong>For all the other time durations, the label for the exact same combination of features except <strong>time</strong> is labelled as <strong>‘0’ for not outage. </strong>To further illustrate this point we shall take an example:</p><p>Say the following row is selected:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*mXRfUbkgHHYH4F12pDMgGQ.jpeg" /></figure><p>Then it is labelled as <strong>‘1’ for outage</strong> as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wV5GZka_dHW2fO234Om67A.jpeg" /></figure><p>Notice the time when this particular outage has occurred is roughly between <strong>2100–2200 hours</strong>. Hence we can conclude that there might have been no outage in the time duration between <strong>0000–2100 and 2200–0000. </strong>Hence we can reproduce the row with these time durations and label them as <strong>‘0’ for not outage. </strong>Obtaining:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/99/1*dHDWdpTPinF7QBen_GZSMw.jpeg" /></figure><p>As the final step before training, we need to <strong>one-hot encode </strong>the<strong><em> Divisions</em></strong> value. What this means is, the Divisions(Indiranagar, Koramangala, HSR Layout…) as such mean nothing to a computer. So we form separate columns for each of these Divisions which can have 0/1 for each row. For example, say a row is formed for the <em>Division of Indirangar, </em>a value of 0 in a row would mean that this particular row does not have Indiranagar as its Division and as value of 1 would indicate that it is. This lets the computer understand the data in its own terms and form better patterns. For an even in-depth understanding of One-Hot Encoding you can <a href="https://hackernoon.com/what-is-one-hot-encoding-why-and-when-do-you-have-to-use-it-e3c6186d008f">read this article.</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77a5310982d1879b7212b83f3dbf5c04/href">https://medium.com/media/77a5310982d1879b7212b83f3dbf5c04/href</a></iframe><p>This gives us the following columns where we can notice that in each row, only 1 column has the value ‘1’ denoting the division.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bXsbRnunwhTbLopVcvTygQ.jpeg" /><figcaption>One Hot Encoded Divisions</figcaption></figure><h3>PART 2 : Training the data</h3><p>Before training the data, we need to <em>scale it. </em>What this means is that different features have different ranges of values and a<a href="http://BecomingHuman.ai"> Neural Network</a> generally works best is the value given as an input to it is in the range of <strong>-1 to +1 or 0 to 1. </strong>Hence we scale the individual features on their own scale to bring down all the values between a given range while keeping their intrinsic differences.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7f9c2fb2e8115538f6ec6ee63c2990f/href">https://medium.com/media/e7f9c2fb2e8115538f6ec6ee63c2990f/href</a></iframe><p>This fits the scaler to the data by finding the mean and standard deviation of the columns and then transforming the columns. When another dataset needs to be scaled to be given into the <a href="http://BecomingHuman.ai">Neural Network</a> for prediction, we should <strong>not fit </strong>the scaler again but just transform it and feed into the Neural Net.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uUDcFqYzQPnMoLEsMeWElg.jpeg" /><figcaption>Scaled data</figcaption></figure><p>Next up, we need to <strong>split</strong> the dataset into a training and testing set. The training set is used to <strong>train</strong> the model and the testing set is <strong>evaluate the accuracy of the model</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38df1cef0c27c23a89918b80b3049fee/href">https://medium.com/media/38df1cef0c27c23a89918b80b3049fee/href</a></iframe><p>Now its time for us to define the Neural Network model. We have chosen a sequential model with 3 hidden layers for our job.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7663acf61a13bb3e5c28881d7a0b47d/href">https://medium.com/media/c7663acf61a13bb3e5c28881d7a0b47d/href</a></iframe><p>After defining the model, our hard work is done and now it is time to watch our model train in satisfaction:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6648dbed864e8398f5eb4a4dd40c549b/href">https://medium.com/media/6648dbed864e8398f5eb4a4dd40c549b/href</a></iframe><pre>Epoch 1/20<br>81987/81987 [==============================] - 3s 35us/step - loss: 0.4935 - accuracy: 0.7443<br>Epoch 2/20<br>81987/81987 [==============================] - 3s 33us/step - loss: 0.4333 - accuracy: 0.7874<br>Epoch 3/20<br>81987/81987 [==============================] - 3s 33us/step - loss: 0.4259 - accuracy: 0.7900<br>Epoch 4/20<br>81987/81987 [==============================] - 3s 31us/step - loss: 0.4186 - accuracy: 0.7923<br>Epoch 5/20<br>81987/81987 [==============================] - 3s 32us/step - loss: 0.4147 - accuracy: 0.7949<br>Epoch 6/20<br>81987/81987 [==============================] - 3s 31us/step - loss: 0.4121 - accuracy: 0.7977<br>Epoch 7/20<br>81987/81987 [==============================] - 3s 32us/step - loss: 0.4097 - accuracy: 0.7983<br>Epoch 8/20<br>81987/81987 [==============================] - 3s 31us/step - loss: 0.4080 - accuracy: 0.7988<br>Epoch 9/20<br>81987/81987 [==============================] - 3s 32us/step - loss: 0.4058 - accuracy: 0.8007<br>Epoch 10/20<br>81987/81987 [==============================] - 3s 31us/step - loss: 0.4041 - accuracy: 0.8015<br>Epoch 11/20<br>81987/81987 [==============================] - 3s 31us/step - loss: 0.4039 - accuracy: 0.8020<br>Epoch 12/20<br>81987/81987 [==============================] - 3s 32us/step - loss: 0.4020 - accuracy: 0.8024<br>Epoch 13/20<br>81987/81987 [==============================] - 3s 32us/step - loss: 0.4004 - accuracy: 0.8043<br>Epoch 14/20<br>81987/81987 [==============================] - 3s 31us/step - loss: 0.3989 - accuracy: 0.8046<br>Epoch 15/20<br>81987/81987 [==============================] - 3s 32us/step - loss: 0.3984 - accuracy: 0.8056<br>Epoch 16/20<br>81987/81987 [==============================] - 3s 31us/step - loss: 0.3974 - accuracy: 0.8057<br>Epoch 17/20<br>81987/81987 [==============================] - 3s 31us/step - loss: 0.3964 - accuracy: 0.8062<br>Epoch 18/20<br>81987/81987 [==============================] - 3s 31us/step - loss: 0.3952 - accuracy: 0.8067<br>Epoch 19/20<br>81987/81987 [==============================] - 3s 32us/step - loss: 0.3944 - accuracy: 0.8075<br>Epoch 20/20<br>81987/81987 [==============================] - 3s 31us/step - loss: 0.3934 - accuracy: 0.8080</pre><p>Testing the trained model:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ddadf17ee9dfb364f00fb2a442b81aa/href">https://medium.com/media/0ddadf17ee9dfb364f00fb2a442b81aa/href</a></iframe><pre>20497/20497 [==============================] - 1s 34us/step<br>Out[80]: [0.38760558974482917, 0.7936800527572632]</pre><p>We have achieved a training accuracy of around 80% and testing accuracy of around 79%. This can be bettered by tweaking the <a href="http://BecomingHuman.ai">Neural Network</a> Architecture.</p><p><strong>That’s it for this article folks! Thanks for reading and do comment if you felt this was useful for you. This is also my first Medium article, so any pointers on things I have inadvertently gone wrong with is appreciated!</strong></p><p>You can find the complete project on <a href="https://github.com/sabm0hmayahai/Electro-Maps">GitHub</a>. Connect with me on <a href="https://www.linkedin.com/in/kalpanmukherjee/">Linkedin</a> or check out my <a href="http://kalpan.codes">website.</a></p><p><a href="https://kalpan.codes">Kalpan Mukherjee</a></p><h3>Don’t forget to give me your 👏 !</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*2lvCls4yjxVMfZSR" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fbd1b299a24e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/predicting-electricity-outage-with-keras-and-python-fbd1b299a24e">Predicting Electricity Outage with Keras and Python</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>