<?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 yashee joshi on Medium]]></title>
        <description><![CDATA[Stories by yashee joshi on Medium]]></description>
        <link>https://medium.com/@yasheejoshi?source=rss-f5d9a1531b4f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yj2D7a8Fe0tyuCyQd2JpJQ@2x.jpeg</url>
            <title>Stories by yashee joshi on Medium</title>
            <link>https://medium.com/@yasheejoshi?source=rss-f5d9a1531b4f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 05:55:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yasheejoshi/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[Computers Don’t Understand Calculus And Here’s How We Fix That]]></title>
            <link>https://yasheejoshi.medium.com/computers-dont-understand-calculus-and-here-s-how-we-fix-that-98aca08e7d70?source=rss-f5d9a1531b4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/98aca08e7d70</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[simulation]]></category>
            <category><![CDATA[calculus]]></category>
            <category><![CDATA[eulers-method]]></category>
            <dc:creator><![CDATA[yashee joshi]]></dc:creator>
            <pubDate>Sat, 14 Feb 2026 20:29:00 GMT</pubDate>
            <atom:updated>2026-02-14T20:29:00.052Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uucIlboqO4N2_Pa5" /><figcaption>Photo by <a href="https://unsplash.com/@wimarys?utm_source=medium&amp;utm_medium=referral">Wim Arys</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>It is by logic that we prove, but by intuition that we discover.<br> — Henri Poincaré</blockquote><p>In many areas of science, engineering, and data science, we model systems that are constantly evolving. A population grows. A virus spreads. A stock price fluctuates. A reinforcement learning agent updates its policy. These systems don’t jump from one state to another randomly. They change continuously over time.</p><p>Mathematically, we describe that evolution using <em>differential equations</em>. Instead of directly telling us the future value of a system, a differential equation tells us something more subtle and powerful: it tells us the <em>rate</em> at which the system is changing at each instant. In other words, it gives us a rule for motion rather than the motion itself.</p><p>A simple example looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/130/1*taJE5YfpyWI_cYVUWBzbow.png" /></figure><p>Its saying that the instantaneous rate of change of <em>x</em> is determined by some function <em>g(x)</em>. If you know the current state, you know the slope at that state.</p><p>But here’s the challenge.</p><p>Computers do not understand “<em>instantaneous</em>”. They cannot evaluate a limit as time approaches zero. They operate step by step, in finite increments. So if our mathematics describes smooth, continuous evolution, how do we translate that into something a machine can compute?</p><p>That translation is accomplished through <strong>Euler’s Method</strong>.</p><p><strong>From Instantaneous Rate to Finite Steps</strong></p><p>To understand Euler’s Method, recall how a derivative is defined:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/193/1*jOdulrSXF-p1nwD_EbI3Ag.png" /></figure><p>This definition captures the idea of perfect instantaneous change. The variable <em>h</em> shrinks toward zero, and we measure how much the function changes over an infinitesimally small interval.</p><p>In computation, however, we do not let <em>h</em> go to zero. Instead, we choose a small value and approximate:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/188/1*gnizBLPFQl0Ss0SD-PxCWg.png" /></figure><p>Now we substitute this approximation into the differential equation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/177/1*fcnkWwkh_PgRzkAV0bPKyA.png" /></figure><p>Rearranging gives the update rule:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/201/1*y1WNSQ-zrOLqNCTyAcRZPA.png" /></figure><p>What began as a continuous equation has now become a simple algorithm.</p><p>This is Euler’s Method.</p><p>It tells us how to move from the current state <em>x_t</em> to the next state <em>x_t+h. </em>We evaluate the slope using <em>g(x_t) </em>, multiply by a small step size <em>h, </em>and add that change to the current value. Then we repeat the process.</p><p>What began as a continuous equation has now become a simple algorithm.</p><p><strong>How its represented Geometrically</strong></p><p>Visually, imagine standing on a curve. At your current point, you know the slope, the direction the curve is heading. Euler’s Method says: use that slope to take a small straight-line step forward. Once you arrive at the new point, compute the slope again and repeat.</p><p>Each individual step is linear. The true path may be curved. But if the step size <em>h</em> is small enough, the sequence of straight segments closely approximates the smooth trajectory.</p><p>Continuous motion becomes a series of tiny linear moves.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*src__16D0fp3uYgPUiffmw.png" /><figcaption>For example, graph of Amount of drug in the body vs Time</figcaption></figure><p><strong>Why This Matters in Data Science</strong></p><p>This idea is foundational to simulation. Whenever we model population dynamics, epidemic spread, physical systems, or financial processes, we often start with differential equations. To simulate them, we discretize time into small intervals and update the system incrementally.</p><p>Even stochastic models that evolve in small time increments rely on the same principle. We approximate continuous randomness using many small forward steps. This process is called discretization.</p><ul><li>A differential equation provides a rule for instantaneous change.</li><li>A numerical method converts that rule into an executable procedure.</li></ul><p><strong>What’s the Catch</strong></p><p>Euler’s Method is simple and intuitive, but it introduces approximation error. If the step size <em>h </em>is too large, the error can grow quickly. If <em>h </em>is very small, the approximation improves but at the cost of additional computation.</p><p>More advanced techniques refine this idea and improve accuracy, but they all share the same foundation: replace infinitesimal change with small, finite steps.</p><p><strong>The Bigger Picture</strong></p><p>Calculus describes the world continuously.</p><p>Computation operates discretely.</p><p>Euler’s Method is the bridge between them.</p><p>It transforms a theoretical statement about instantaneous change into a step-by-step algorithm. And in doing so, it makes simulation possible one small <em>h </em>at a time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98aca08e7d70" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why does Linear Regression love Squared Errors?]]></title>
            <link>https://yasheejoshi.medium.com/why-does-linear-regression-love-squared-errors-a6dfff88bad2?source=rss-f5d9a1531b4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6dfff88bad2</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[loss-function]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[linear-regression]]></category>
            <dc:creator><![CDATA[yashee joshi]]></dc:creator>
            <pubDate>Wed, 04 Feb 2026 03:13:40 GMT</pubDate>
            <atom:updated>2026-02-04T03:13:40.662Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*756WCPR1O_o-WB7_" /><figcaption>Photo by <a href="https://unsplash.com/@ridham?utm_source=medium&amp;utm_medium=referral">Ridham Nagralawala</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote><em>“Statistics is the grammar of science.”~ Karl Pearson</em></blockquote><p>Linear regression is one of the most widely used foundational techniques in machine learning and statistics. It is a supervised learning technique that uses <em>gradient-based optimization</em>. The<strong> <em>gradient</em> </strong>of a function shows the fastest way to increase the function’s value, and the negative gradient shows the fastest way to decrease it. At its core, it tries to fit the best possible line through the data points to model the relationship between the input variables and the output variable (target). A best-fitting line has two components, <em>alpha</em> and<em> beta</em>. So if you get the best values for alpha (slope) and beta (intercept) you got yourself a deal!</p><p>But have you ever wondered why we use the squared error as the go-to metric in linear regression? Why not, say, absolute errors?</p><p>In this blog, let’s unpack the said choice of metric.</p><p>As we already know, residuals are the differences between actual values and the predicted values from a model. It measures how far the model is with its predictions. ​</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/206/1*qrpwvnAPC5nwmrIkWIbQ7g.png" /></figure><p>The total “badness” of a model is quantified by aggregating these residuals into a <strong>loss function</strong> which is what we aim to minimize.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*RNzJ_TZK9AYZKuKPv40N3Q.png" /></figure><p>Notice that here we are squaring the errors. Why? Here is why squaring wins :</p><h4><strong>1. Mathematical convenience:</strong></h4><p>Squaring the residuals make the loss function <strong><em>smooth </em></strong>and <strong><em>differentiable</em></strong>. Smooth meaning that loss function changes gradually without jumps or sharp corners, just like a sloping hill and not a staircase. And Differentiable meaning that we can take the derivative of the function at any point. This means that we can calculate the slope of the function anywhere on its curve. It matters because in linear regression, we use a g<em>radient descent</em> o<em>ptimization </em>to minimize the loss. This method relies on</p><p>a) which direction to move and</p><p>b) how much to move.</p><p>If the loss function is not differentiable, the gradient descent can’t work properly as then it doesn’t know how to compute the slope at those points.</p><p><strong>Differentiable loss</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/79/1*kB-8279yB3yZxRrlp1XRHA.png" /></figure><p>This is smooth and differentiable. Perfect for gradient-based optimization.</p><p><strong>Absolute Error loss</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/67/1*WI5yPRxETVQJ4v75iqPhKQ.png" /></figure><p>This has a <strong>corner</strong> at 0 (the point where the error changes sign), so it’s <strong>not differentiable</strong> at that point.</p><h4>2. <strong>Unique and Efficient Solution:</strong></h4><p>Minimizing squared errors guarantees a <strong>unique global minimum</strong> for convex problems like linear regression. Convex meaning it has a nice U-shaped curve (like a bowl). There’s <strong>only one minimum</strong>, so optimization is guaranteed to find the best possible solution. Minimizing the absolute errors would still give us a convex curve but may lack unique solution in some edge cases, meaning, multiple minima can exist. Also, it wouldn’t be differentiable at 0.</p><p><strong>Squared errors</strong> → Fast, unique, efficient for large datasets</p><p><strong>Absolute errors</strong> → More robust but harder to optimize and may not have single best solution</p><h4>3. Penalizing Large Errors More Heavily</h4><p>Squaring up the residuals amplifies large errors, which may prove to be beneficial as we want to discourage the model from making large mistakes. By doing so, we are making the linear regression sensitive to outliers which can be both, a strength and a limitation, depending on your application.</p><h4>4. Statistical Justification: The Gaussian Assumption</h4><p>Linear regression assumes that the errors follow a Gaussian (normal) distribution. Under this assumption, minimizing squared errors is equivalent to maximizing the likelihood of the observed data. This makes squared error loss a statistically sound and principled choice, not just a mathematical convenience.</p><p>So, to conclude, Linear regression “loves” squared errors because:</p><ul><li>They make the math work out beautifully.</li><li>They give us computational efficiency.</li><li>They align with probabilistic assumptions.</li><li>They emphasize large errors, which can be important in many real-world models.</li></ul><p>That said, squared errors aren’t the only choice — but they’re often the most convenient and statistically sound one, especially when you’re working with clean, well-behaved data.</p><h4>Food for Thought:</h4><p>Understanding why linear regression uses squared errors is not just a mathematical exercise — it’s a step toward becoming a more informed and versatile data scientist.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6dfff88bad2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Random Numbers to Real-World Waiting Times]]></title>
            <link>https://yasheejoshi.medium.com/from-random-numbers-to-real-world-waiting-times-32c7a5b32fb1?source=rss-f5d9a1531b4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/32c7a5b32fb1</guid>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[simulation]]></category>
            <category><![CDATA[probability]]></category>
            <category><![CDATA[queueing-theory]]></category>
            <category><![CDATA[simulation-modeling]]></category>
            <dc:creator><![CDATA[yashee joshi]]></dc:creator>
            <pubDate>Thu, 22 Jan 2026 03:47:02 GMT</pubDate>
            <atom:updated>2026-01-22T03:49:23.576Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Qth7sjpj0PAn8C-y" /><figcaption>Photo by <a href="https://unsplash.com/@museumsvictoria?utm_source=medium&amp;utm_medium=referral">Museums Victoria</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>“The most incomprehensible thing about the universe is that it is comprehensible” -Albert Einstein</blockquote><p>When computers simulate real-world systems such as call centers, hospitals, fast-food queues, or network traffic, they must deal with randomness. The challenge is that computers cannot directly generate realistic randomness that looks like how events happen in real life. Instead, they generate simple numbers that only appear random.<br>Understanding how those simple numbers turn into meaningful waiting times is the key idea behind simulation.</p><h4><strong>Where randomness comes from</strong></h4><p>The most basic type of randomness a computer can generate is a <em>uniform random number between 0 and 1.</em></p><p>Think of it like this:</p><pre>0 ─────────────────────────────── 1<br>                      ↑<br>                    U = 0.728</pre><p>A number like 0.728 is called a <em>pseudo-random number</em>. It is generated by an algorithm, not by physical randomness. By itself, it has no meaning. It is not time. It is not an event. It has no units. It is simply a random position on a probability scale.</p><p>Mathematically, we write this as:</p><pre>U ~ Uniform(0, 1)</pre><h4><strong>Why uniform randomness is not realistic</strong></h4><p>Uniform randomness treats all outcomes equally. If we used it directly to model waiting times, short waits and long waits would be equally likely. That is not how real systems behave.</p><p>In real life, waiting times tend to look like this:</p><ul><li>Most waits are short</li><li>Some waits are longer</li><li>Very long waits are rare but possible</li></ul><p>Uniform randomness cannot produce this pattern.</p><h4><strong>Real waiting times in a call center</strong></h4><p>Consider a call center where calls arrive randomly throughout the day.</p><ul><li>Customers do not coordinate their calls</li><li>Calls arrive independently</li><li>There is a stable average arrival rate</li></ul><p>In this situation, the time until the next call is well modeled by an exponential distribution.</p><p>This shape means short waits are common, longer waits happen occasionally, and there is no fixed maximum waiting time.</p><h4><strong>What “exponential” means</strong></h4><p>The exponential distribution models waiting time until the next event.</p><p>One of its defining equations is the survival probability:</p><pre>P(X &gt; x) = e^(−λx)</pre><p>This tells us the probability that we are still waiting after time x.</p><p>A key property of the exponential distribution is <em>memorylessness</em>. This means that how long you have already waited does not affect how much longer you might wait. Even if you have been waiting for several minutes, the chance of the next event happening soon remains the same.</p><h4>What lambda represents</h4><p>Lambda (λ) controls how fast events happen.</p><ul><li>Large λ means events happen frequently</li><li>Small λ means events are rare</li></ul><p>The average waiting time is:</p><p>Average waiting time = 1 / λ</p><p>For example, if λ = 3 calls per minute, the average waiting time between calls is about one third of a minute.</p><h4>Turning uniform randomness into waiting time</h4><p>Computers can generate uniform random numbers easily, but they cannot directly generate exponential waiting times. To solve this, we transform the uniform number using a mathematical rule.</p><p>The transformation is:</p><pre>X = −(1 / λ) ln(U)</pre><p>Conceptually, this transformation reshapes flat randomness into realistic waiting-time behavior.</p><pre>Uniform random number (U)<br>            ↓<br>Probability position<br>            ↓<br>Exponential waiting time (X)</pre><p>The logarithm compresses large probabilities and stretches small ones, creating many short waits and a few long waits.</p><h4>What a random variate is</h4><p>A <strong>random variate</strong> is simply one concrete outcome from a probability model.</p><ul><li>The distribution describes all possible outcomes</li><li>A random variate is one specific draw</li></ul><p>In the call center example, the random variate represents <em>one simulated waiting time until the next call arrives.</em></p><ul><li>It is not an average.</li><li>It is not a prediction.</li><li>It is just one possible outcome that is statistically realistic.</li></ul><h4>Why this step is necessary</h4><p>If we skipped the exponential transformation and used uniform numbers directly:</p><ul><li>Long waits would never appear</li><li>Variability would be unrealistic</li><li>The simulation would look random but behave incorrectly</li></ul><p>By transforming uniform randomness into exponential waiting times, simulations gain realism, correct variability, and meaningful results.</p><h4>The big picture</h4><p>Almost all simulations follow the same structure:</p><pre>Uniform randomness<br>        ↓<br>Mathematical transformation<br>        ↓<br>Realistic system behavior</pre><p>Uniform random numbers provide the raw randomness. Probability models such as the exponential distribution give that randomness structure and meaning.</p><h4><strong>Final takeaway</strong></h4><p>Computers generate uniform random numbers, but real-world waiting times are not uniform. By transforming uniform randomness into exponential random variates, simulations produce realistic waiting-time behavior, with frequent short waits, occasional long waits, and no memory of the past. This simple idea is what allows computer models to accurately represent how real systems operate.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32c7a5b32fb1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ten Step Guide for your first ML Regression project]]></title>
            <link>https://yasheejoshi.medium.com/ten-steps-guide-for-your-first-ml-regression-project-2d7ad8b73036?source=rss-f5d9a1531b4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d7ad8b73036</guid>
            <category><![CDATA[python-for-data-science]]></category>
            <category><![CDATA[regression-modeling]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[yashee joshi]]></dc:creator>
            <pubDate>Fri, 07 Jul 2023 01:53:46 GMT</pubDate>
            <atom:updated>2023-07-07T07:23:17.654Z</atom:updated>
            <content:encoded><![CDATA[<h4>Machine Learning</h4><h3>10 Steps Guide For Your First ML Regression Project</h3><h4>Mastering ML Regression with Ease</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hIpuluLKNdKD3K01" /><figcaption>Photo by <a href="https://unsplash.com/@bruno_nascimento?utm_source=medium&amp;utm_medium=referral">Bruno Nascimento</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>“How to begin the journey? You need only to take the first step. When? There is always now.”- George Leonard, American Writer</blockquote><p>Machine Learning is an incredibly fascinating and captivating field. However, when it comes to embarking on your first project, it can seem daunting due to the multitude of considerations involved. From the dataset’s size to comparing and selecting models, it’s easy to lose track of where to begin. Drawing from my own learning experience, I have compiled a ten-step guide to assist you in creating your inaugural ML regression model. Lets dive right in!</p><h4>Step 1: Know your data</h4><p>The very first step is to go through all the fields the data comprises of. After you read and store data in a pandas dataframe, df, following methods can be used to understand the data better:</p><ul><li>df.head(n) : Read first n rows of the dataset to get an understanding on fields and their values</li><li>df.describe() : Check the statistics of the data, like min, max, std, mean and count of values in all the fields of the dataframe</li><li>df.info() : Check the datatypes and count of non null values for all fields of the data</li></ul><h4>Step 2: Explore your data</h4><p>Secondly, understand the trend and distribution of data using Exploratory Data Analysis techniques. Libraries like Seaborn, Plotly and Matplotlib can be used to create beautiful charts that can help us understand the data better.</p><h4>Step 3: Engineer your data</h4><p>Third step is to do Feature Engineering and Preprocessing on the data based on the observations gained from the first two steps. This step is basically to make the data consumable. For this, you may be required to rename the fields, convert the datatypes of the fields, drop the columns that you know are not going to contribute to the model (fields like ‘id’ or ‘name’), fill the values with null data or drop those rows that carry null data for the target variable if its low proportion of data. Target variable is what you are trying to predict. For example, if you are trying to predict ‘unit sales’ in test dataset and there are a few rows in training dataset that contain null values for ‘unit sales’, it would make sense to drop these rows. On the other hand, if there is a larger proportion of rows that have null values for target variable, you may want to consider imputing values for it. Another step in preprocessing data is to take care of columns containing date time information. If its not already, you will need to parse the date-time column to give you individual columns for day, date, month, year and time. Next step is to handle Multicollinearity that may be happening in the dataset. Multicollinearity is when some independent variables(fields) from the dataset, show strong dependence on each other. Pandas offer a ‘df.corr()’ method that helps in calculating correlation between two variables. The values can then be plot in a heatmap to visualize correlations between variables. A value closer to +1 or -1 shows strong positive or negative corrrelation.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.com%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D113&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D113&amp;image=https%3A%2F%2Fapi.jovian.com%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00%3Fts%3D1667020065446&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d31312dde84146a7eeec63dd344da8b/href">https://medium.com/media/0d31312dde84146a7eeec63dd344da8b/href</a></iframe><h4>Step 4: Split your data</h4><p>The fourth step is to split the data into train-validation and test datasets. If the test dataset is already given, you just need to split the dataset into training and validation sets. A good ratio of training and validation split would be 75:25. In case test dataset is not given, training-validation-test ratio could be 70:15:15 or 60:20:20 if the dataset is small. Basically, training dataset is to fit the model, the validation dataset is to hypertune the model and test dataset is to evaluate the model’s performance.</p><h4>Step 5: Identify input &amp; target variables</h4><p>The target variable is the one that you are trying to make predictions for. All the other columns (except for the ones that you dropped in step 3, considering that they will not be contributing to the model, are the input variables. You should now have sets of training and validation input and target dataframes in addition to a dataframe for test input variables, test target is what we have to predict.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.com%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D122&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D122&amp;image=https%3A%2F%2Fapi.jovian.com%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00%3Fts%3D1667020065446&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/c709cc6ebaa2b1b93c1d56dfbb459cfa/href">https://medium.com/media/c709cc6ebaa2b1b93c1d56dfbb459cfa/href</a></iframe><h4>Step 6: Imputing Missing values for numeric fields</h4><p>Next, you create two lists, one containing the all the input variable fields with numeric datatype and the other with the categorical datatypes. Our goal is to fill in the missing values that we are seeing in the input datasets. Scikit-learn’s class-<em>SimpleImputer</em> comes in handy to impute the missing values from the fields. The class provides various strategies like use of Mean, Median, Most Frequent and Constant values to fill in the nan values in the field. You need to fill in the missing values in train, validate and test input numeric fields and transform the values in these dataset with the value that the imputer yields after the strategy has been defined.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.com%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D130&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D130&amp;image=https%3A%2F%2Fapi.jovian.com%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00%3Fts%3D1667020065446&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/40abc6507102814690c204e0e62ae105/href">https://medium.com/media/40abc6507102814690c204e0e62ae105/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.com%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D131&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D131&amp;image=https%3A%2F%2Fapi.jovian.com%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00%3Fts%3D1667020065446&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/50ad3c4157a88105c53dbc79d6db9ee9/href">https://medium.com/media/50ad3c4157a88105c53dbc79d6db9ee9/href</a></iframe><h4>Step 7: Scaling the numeric data</h4><p>In order to spit out accurate results, the model needs to be fed with data that doesn’t have any disproportionate impact on its loss. For this, you would be required to scale the values in the numeric fields so they can fit in a range. For this, scikit-learn’s class- <em>MinMaxScaler </em>can help.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.com%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D138&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D138&amp;image=https%3A%2F%2Fapi.jovian.com%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00%3Fts%3D1667020065446&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba56f0b46e2a05c0ee2a170d3dc88295/href">https://medium.com/media/ba56f0b46e2a05c0ee2a170d3dc88295/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.com%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D139&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D139&amp;image=https%3A%2F%2Fapi.jovian.com%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00%3Fts%3D1667020065446&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2a14496c5f219e12b7c05707de50791/href">https://medium.com/media/a2a14496c5f219e12b7c05707de50791/href</a></iframe><h4>Step 8: Encoding categorical data</h4><p>Next, we need to encode the categorical fields to be represented in numerical format. This step is important because machine learning models can only be trained with numeric data. We will be using a technique called one-hot encoding for converting the categorical values to numeric values. This means that the categories within the categorical data will become individual columns.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.com%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D145&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D145&amp;image=https%3A%2F%2Fapi.jovian.com%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00%3Fts%3D1667020065446&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a9ca68988a997760cd9150a7327dc99/href">https://medium.com/media/4a9ca68988a997760cd9150a7327dc99/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.com%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D146&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D146&amp;image=https%3A%2F%2Fapi.jovian.com%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00%3Fts%3D1667020065446&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/7fd4052fbaa04491ab844a77a052e9ac/href">https://medium.com/media/7fd4052fbaa04491ab844a77a052e9ac/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.com%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D148&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D148&amp;image=https%3A%2F%2Fapi.jovian.com%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00%3Fts%3D1667020065446&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac8ca874d60fb95903bc650a409b4caa/href">https://medium.com/media/ac8ca874d60fb95903bc650a409b4caa/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.com%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D149%26hideOutput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D149%26hideOutput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.com%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00%3Fts%3D1667020065446&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/46c037f0b2df9bb52bc60f7952660648/href">https://medium.com/media/46c037f0b2df9bb52bc60f7952660648/href</a></iframe><h4>Step 9: Apply various models for prediction and evaluation</h4><p>You can now start to implement and compare different models. Each model must be applied to the training and validation sets. By looking at the model’s performance with the validation dataset, you can further hypertune the model in order to get better results. Hypertuning helps in improving the performance of the model, generalization ability of the model which ensures that the models not only performs well on the training dataset but also on the unseen data, and prevents overfitting hence yielding a robust model.</p><p>Finding out feature importance of fields will tell you which are the most or least important fields that contribute the the predictions. <em>model.feature_importances_ </em>will help you in this step.</p><h4>Step 10: Calculate the model’s loss</h4><p>By calculating the “loss” of a model, you will get a sense of how well your model is performing. Its basically the difference between the predicted value and the actual target value for the training dataset. Hypertuning the model can help in reducing the loss of the model. Some of the examples of loss functions are <em>Root Mean Squared Error, Mean Squared Error </em>and <em>Mean Absolute Error. </em>You are also required to calculate the loss on the validation set. By doing so, you can monitor how well you model is performing on a newer dataset and see if there is any overfitting happening<em>. </em>Overfitting is when the models loss is less on training dataset but higher on the validation dataset<em>. </em>You need to hypertune your validation set so that the loss is the lowest. The model with least loss value is the model you want to consider.</p><p><strong>Conclusion:</strong></p><p>These steps will help you create your first regression model. Some things to consider is the size of the dataset that you choose to work on, cleaning and feature engineering on the dataset, how you split the data into train-validation and test sets, how you evaluate and compare various models using hypertuning of parameters and choosing the one yielding best results.</p><p><em>Let me know if you enjoyed this read- Happy Learning :)</em></p><p><strong>References:</strong></p><ul><li>Project reference : <a href="https://jovian.com/yasheejoshi/favorita-grocery-sales-forecasting">https://jovian.com/yasheejoshi/favorita-grocery-sales-forecasting</a></li><li>Decision Trees and Random Forests : <a href="https://jovian.ai/learn/zero-to-data-analyst-bootcamp/lesson/decision-trees-and-random-forests">https://jovian.ai/learn/zero-to-data-analyst-bootcamp/lesson/decision-trees-and-random-forests</a></li><li>Gradient Boosting Machines with XGBoost : <a href="https://jovian.ai/learn/zero-to-data-analyst-bootcamp/lesson/gradient-boosting-machines-with-xgboost">https://jovian.ai/learn/zero-to-data-analyst-bootcamp/lesson/gradient-boosting-machines-with-xgboost</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d7ad8b73036" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Machine Learning techniques for unit sale predictions]]></title>
            <link>https://yasheejoshi.medium.com/machine-learning-techniques-for-unit-sale-predictions-488405eeea2c?source=rss-f5d9a1531b4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/488405eeea2c</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[random-forest-regressor]]></category>
            <category><![CDATA[predictive-analytics]]></category>
            <category><![CDATA[gradient-boosting]]></category>
            <category><![CDATA[kaggle-competition]]></category>
            <dc:creator><![CDATA[yashee joshi]]></dc:creator>
            <pubDate>Thu, 10 Nov 2022 14:42:24 GMT</pubDate>
            <atom:updated>2022-11-10T14:42:24.305Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6nfe3scNGByQvPg1" /><figcaption>Photo by <a href="https://unsplash.com/@srz?utm_source=medium&amp;utm_medium=referral">sydney Rae</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>“Machine Learning is the last invention humanity will ever need to make”-Nick Bostrom, Swedish philosopher</blockquote><p><a href="http://www.corporacionfavorita.com/">Corporación Favorita</a> is a large Ecuadorian based grocery retailer and is trying to solve a complex purchasing and sales forecasting problem. Brick and mortar grocery stores constantly try to strike a balance between stocks and sales. Predict the sales a little over result in being overstocked and if the sales prediction fall a little short, result is disastrous resulting in loss in business or customers frustrated. There are other external factors in play as well, like, if certain products are seasonal, if they are trending being popular, if the items cater to unique needs, if the items are new kind of items, the location where these items are available.</p><p>Intending to solve this complex problem, <a href="http://www.corporacionfavorita.com/">Corporación Favorita</a> has challenged Kaggle community to come up with a model that accurately forecasts the sales.</p><p>This project makes use of different machine learning models , they are compared and the one that yields the best result with least loss is chosen to finally make predictions. Lets dive right in!</p><h4>Description of Problem</h4><p>This exercise attempts to solve for a Kaggle problem given here: <a href="https://www.kaggle.com/competitions/favorita-grocery-sales-forecasting/">https://www.kaggle.com/competitions/favorita-grocery-sales-forecasting/</a>. As explained above, we are trying to come up with a machine learning model that allows us to make sales predictions for grocery stores. This data is derived from Corporación Favorita, they operate on a large scale with hundreds of locations and with more than 200,000 different products on their shelves. For solving for this complex issue, we will be using various machine learning models to do a predictive analysis. Python libraries like <em>Scikit learn </em>come in handy for this operation.</p><h4>Import Python Libraries</h4><p>Start with importing the libraries.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D3%26hideOutput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D3%26hideOutput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/564b4cc231d4db03ce22d3318db1faa1/href">https://medium.com/media/564b4cc231d4db03ce22d3318db1faa1/href</a></iframe><h4>Download dataset using opendatasets library</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D8&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D8&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5fb76ae437315c0f0803861f05613bb/href">https://medium.com/media/f5fb76ae437315c0f0803861f05613bb/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D9%26hideOutput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D9%26hideOutput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/04d91b93ce69f65deb66438615bf4e97/href">https://medium.com/media/04d91b93ce69f65deb66438615bf4e97/href</a></iframe><p>Lets create dataframes for the extracted data and check out the data in the csv files.For this, in some cases where the data is large, we will be using Dask dataframe instead of Pandas dataframe. This is because Dask can speed up the data loading as it uses parallel processing. Rest of the dataset will be loaded in Pandas dataframe as usual.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D12%26hideOutput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D12%26hideOutput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/bfcc137bb8af20dd505183662c665896/href">https://medium.com/media/bfcc137bb8af20dd505183662c665896/href</a></iframe><p>Now that we have our data loaded in dask and pandas dataframes, lets check out the data. For this, lets start with first looking at the size of the data.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D15&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D15&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/034d917123144af67771e7f128077e25/href">https://medium.com/media/034d917123144af67771e7f128077e25/href</a></iframe><p>The training and test dataset is huge. Lets use a part of the training dataset to go forward with modeling. By extracting just a fraction of training dataset, we can put that into a pandas dataframe and go ahead with training the model. Later on, when the model is fully trained, we can then use the complete dataset and train the test dataset.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D17&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D17&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/5bab36ffe516c9024fa79377674a3340/href">https://medium.com/media/5bab36ffe516c9024fa79377674a3340/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D18%26hideOutput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D18%26hideOutput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca52e7d7bee0a8a36ec8cff9000f6dc4/href">https://medium.com/media/ca52e7d7bee0a8a36ec8cff9000f6dc4/href</a></iframe><p>The training dataset seems huge. But there is also supplemental data provided in other csv files (other than the test csv file). Lets check out first ten rows of these datasets including the training dataset and try to make a sense of our data. For this, lets use the head method and call out first 10 rows of data</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D21&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D21&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e6b32b30ac151fa8eb0cb0500d1dba0/href">https://medium.com/media/9e6b32b30ac151fa8eb0cb0500d1dba0/href</a></iframe><p>So the train csv has a unique id field, date, store number, item number, target unit sales by date, store number and item number and an ‘onpromotion’ field that tells whether that item was on a promotion for that date and store number. 16% of this value, as given in the description for data in Kaggle, is NaN values.</p><p>Lets check out the supporting information and perform some level of preprocessing to understand the data better.</p><p>The datatype for date column is string. To inspect and analyze the data in some of these files, we will need to use date column. So it makes sense to convert the date column from String to Datetime datatype. Lets define a function for the same.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D23&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D23&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5f456afc69189a3b143c68b7ac58ca6/href">https://medium.com/media/b5f456afc69189a3b143c68b7ac58ca6/href</a></iframe><p>▹ <strong>Transaction and Store dataset merge</strong></p><p>Lets enrich the transaction dataframe with information from stores dataframe. For this we will be using the merge operation.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D36&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D36&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/b59147d572806cc456157b8eba68e02b/href">https://medium.com/media/b59147d572806cc456157b8eba68e02b/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D37&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D37&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b78fbb81998b8d53819f7f85ce79e7d/href">https://medium.com/media/0b78fbb81998b8d53819f7f85ce79e7d/href</a></iframe><p>▹ <strong>Oil dataset and Transaction and Store dataset merge</strong></p><p>Lets merge the oil dataset with the dataframe we created using transaction and stores(transaction_stores_df). The idea is to create a dataframe with all the additional information that we will finally merge with the training and test datasets. We will be using ‘Outer’ join to avoid any loss of info. All the rows that have NaN values that will not be contributing to the prediction while modeling, we will remove those in later steps.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D51&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D51&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/0550b6bcbac0df50ba3ffc4b103e9dd6/href">https://medium.com/media/0550b6bcbac0df50ba3ffc4b103e9dd6/href</a></iframe><p>▹ <strong>Holiday_events dataset and transaction _store dataset merge</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D70&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D70&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/14b9d38c32470750dabeec8ff76cb4b1/href">https://medium.com/media/14b9d38c32470750dabeec8ff76cb4b1/href</a></iframe><p>▹ <strong>Supporting information dataset</strong></p><p>Lets copy the above processed transaction_stores_oil_holiday_df into another dataframe with name ‘supporting_info_df’. We haven’t yet merged the data from the ‘Items_df’ because there are no common field to merge data from items dataframe to the ‘transaction_stores_oil_holiday_df’. We will be directly merging the items data to training/test dataframes as they contain matching fields.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttp%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D72&amp;dntp=1&amp;display_name=Jovian&amp;url=http%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D72&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0d140d6d1f57235f97dc17c067d054d/href">https://medium.com/media/c0d140d6d1f57235f97dc17c067d054d/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D75&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D75&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/4de5cd512b18994c6beb960f55501555/href">https://medium.com/media/4de5cd512b18994c6beb960f55501555/href</a></iframe><p>Lets merge the supporting info with the train and test datasets. We will be using ‘Outer’ method of merging the dataframes in order to avoid any loss of information. We will start with first merging the items data with the training and test data and then merge the supporting info.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D79&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D79&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/4bccd15a24bc94df2cb16be672652249/href">https://medium.com/media/4bccd15a24bc94df2cb16be672652249/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D81&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D81&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/761c0b31734a2058b06481c62f463d34/href">https://medium.com/media/761c0b31734a2058b06481c62f463d34/href</a></iframe><p>Lets now drop all the rows that contain NaN data for all columns from both the datasets</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D83&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D83&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e0c31d3b50debd254099e614772f09b/href">https://medium.com/media/6e0c31d3b50debd254099e614772f09b/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D84&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D84&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0d2015721dc6c835e83c31b21b9d5aa/href">https://medium.com/media/e0d2015721dc6c835e83c31b21b9d5aa/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D85&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D85&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/3aa99291dfbd77bc528998942c7e7aee/href">https://medium.com/media/3aa99291dfbd77bc528998942c7e7aee/href</a></iframe><p>The field of ‘store_nbr’ is showing as datatype ‘float64’ but this data is categorical because this does not represent any physical parameter like transaction of daily oil prices and is more of a data representing a class. Before moving forward, lets covert this field to datatype ‘object’.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D87&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D87&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/58f182277a77a00aebab9308301e3e4b/href">https://medium.com/media/58f182277a77a00aebab9308301e3e4b/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D88&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D88&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/64a56dbf92ebfb73c5df072e7492e72f/href">https://medium.com/media/64a56dbf92ebfb73c5df072e7492e72f/href</a></iframe><p>As can be seen above, the datatype for field ‘store_nbr’ for both the dataframes are now changed to object from float64. Lets proceed ahead.</p><h4>Feature Engineering and Preprocessing</h4><p>Lets take a look into the columns of the merged_df datatframe which is basically the training data merged with the supporting info. In the next step, lets also clean up our data and rename the columns necessary and calculate the date components. We will be repeating the same processing with the test dataset.</p><p>Lets check out the column info for training and test data.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D94&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D94&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/47d8f1dad5a907d340e99989388f334e/href">https://medium.com/media/47d8f1dad5a907d340e99989388f334e/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D95&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D95&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/48e5e7ce4a6ce52270bf1fe334541e50/href">https://medium.com/media/48e5e7ce4a6ce52270bf1fe334541e50/href</a></iframe><p>In the training dataset, lets check out how many rows have ‘onpromotion’ as NaN values. Its important to check these because wherever we find NaN values for ‘onpromotion’ we will assume it to be no promotion for the day and assign a value of 0 to it.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D98&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D98&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad73f030e1a3bbc49c178f76d999c9e6/href">https://medium.com/media/ad73f030e1a3bbc49c178f76d999c9e6/href</a></iframe><p>Lets go ahead and drop the rows that have target variable, unit_sales and store_nbr as null and check the info on dataframe again for the remaining data.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D100&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D100&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2e9e96230ed0d8d4692df09b784dbeb/href">https://medium.com/media/e2e9e96230ed0d8d4692df09b784dbeb/href</a></iframe><p>Let’s check the properties on this dataset now after dropping null values in step above.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D102&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D102&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/aed7c1e73cbf32efbeb6a548e8d5d147/href">https://medium.com/media/aed7c1e73cbf32efbeb6a548e8d5d147/href</a></iframe><p>So, as we can see, there are a few negative values for unit_sales target columns. Lets remove these rows that contain any negative values for unit_sales.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttp%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D104&amp;dntp=1&amp;display_name=Jovian&amp;url=http%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D104&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4c1322699655dab7c5fda759183b9f5/href">https://medium.com/media/c4c1322699655dab7c5fda759183b9f5/href</a></iframe><p>Before moving forward, lets use the parse_date function to convert the string datatype of date colum to datetime format. We will do this for both training and test dataset.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D106&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D106&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/92145fb27d111436a3bb1166ee0ec9f5/href">https://medium.com/media/92145fb27d111436a3bb1166ee0ec9f5/href</a></iframe><p>Also, it doesn’t make sense to keep the rows that have id value as NaN for test dataset. This is a result of the merging operation we have done in steps above.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D108&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D108&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/1906ba6f3731001a47b88136068ae9a1/href">https://medium.com/media/1906ba6f3731001a47b88136068ae9a1/href</a></iframe><p>We can now proceed with the next steps in modeling.</p><p>▹<strong>Handling Multicollinearity</strong></p><p>Before moving ahead with further analysis and processing, lets check out any multicollinearity that may be happening in our dataset. Multicollinearity is basically a condition where some of the independent variables from a dataset show strong correlation with each other. It is important to handle multicollinearity so we can make out which variabes are truly making an impact on our predictions when used as an input to the machine learning model. Pandas offers a .corr() function that helps in calculating correlation between variables. We will eventually create a heatmap to visualize the correlation between variables.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D111&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D111&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/00eb81e996b8db7766baf01ba2ca2f76/href">https://medium.com/media/00eb81e996b8db7766baf01ba2ca2f76/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D112&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D112&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3261eecdffeb34fa4047ec29b4389fa/href">https://medium.com/media/a3261eecdffeb34fa4047ec29b4389fa/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.com%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D113&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D113&amp;image=https%3A%2F%2Fapi.jovian.com%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00%3Fts%3D1667020065446&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d31312dde84146a7eeec63dd344da8b/href">https://medium.com/media/0d31312dde84146a7eeec63dd344da8b/href</a></iframe><p>As can be seen from the heatmap above, variables id — year, id-dcoilwtico, year-dcoilwtico show high correlation. Even if the correlation values are high, it is not a good idea to remove the columns because this will result in loss of data. Its better to treat the multicollinearity by processing the data. But in our case, since ‘id’ field is not contributing to the predictions anyway, we will be getting rid of this field. It makes sense to see high collinearity between ‘dcoilwtico’ and ‘year’ because the former is the daily change in oil prices.</p><h4>Train-Test Split</h4><p>Lets split the merged_df into 75:25 ration of training and validation datasets. We are already given a test dataset so we don’t need to get that data out of the merged_df. For this we will be using a train_test_split library.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D117&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D117&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca26a05566ed94cdffd4e176369b58c6/href">https://medium.com/media/ca26a05566ed94cdffd4e176369b58c6/href</a></iframe><p>▹<strong>Identify Input and Target Columns</strong></p><p>Lets identify the input and the target columns from the merged_item_training_df dataset. This dataset basically contains the training data with the supporting information. As its very obvious, we are predicting unit_sales . So unit_sales becomes our target variable and rest of the columns except for id , are input variables. We are excluding id because it doesn’t contribute to the unit sales for a store as its just a serial number.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D119&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D119&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/e335fa021b800e3d5bb35c4c14223f85/href">https://medium.com/media/e335fa021b800e3d5bb35c4c14223f85/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D120&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D120&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc0bc4a3e0f8723dc86704474f48aa86/href">https://medium.com/media/cc0bc4a3e0f8723dc86704474f48aa86/href</a></iframe><p>Lets make dataframes containing inputs and target columns for train, validation and test data.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.com%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D122&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D122&amp;image=https%3A%2F%2Fapi.jovian.com%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00%3Fts%3D1667020065446&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/c709cc6ebaa2b1b93c1d56dfbb459cfa/href">https://medium.com/media/c709cc6ebaa2b1b93c1d56dfbb459cfa/href</a></iframe><p><strong>▹Numeric and Categorical columns</strong></p><p>Lets next identify the numeric and categorical columns out of the input_cols list.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D124&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D124&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/a667608fd26da049c391110e1a74c430/href">https://medium.com/media/a667608fd26da049c391110e1a74c430/href</a></iframe><ul><li><strong>Impute missing values</strong></li></ul><p>Lets check out the missing values in numerical fields.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D126&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D126&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e6cadf63166bda6d73c5b6cd57746fa/href">https://medium.com/media/6e6cadf63166bda6d73c5b6cd57746fa/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D127&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D127&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/aa335306b19f88d2dcc2ed846269e381/href">https://medium.com/media/aa335306b19f88d2dcc2ed846269e381/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D128&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D128&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/e81af4eb3135bbb0844c99de0148e7c6/href">https://medium.com/media/e81af4eb3135bbb0844c99de0148e7c6/href</a></iframe><p>From the information above, we can see that for train_inputs, val_inputs and test_inputs dataframe, we have null values for transactions, cluster, dcoilwtico columns. This can be a result of merge operation done previously to create a dataframe for supporting info.</p><p>Now lets start filling in the missing values for the numeric fields. Lets use SimpleImputer from sklearn.impute to do so.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.com%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D130&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D130&amp;image=https%3A%2F%2Fapi.jovian.com%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00%3Fts%3D1667020065446&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/40abc6507102814690c204e0e62ae105/href">https://medium.com/media/40abc6507102814690c204e0e62ae105/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.com%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D131&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D131&amp;image=https%3A%2F%2Fapi.jovian.com%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00%3Fts%3D1667020065446&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/50ad3c4157a88105c53dbc79d6db9ee9/href">https://medium.com/media/50ad3c4157a88105c53dbc79d6db9ee9/href</a></iframe><p>Lets check out the train_inputs, val_inputs and test_inputs dataframes again for any null values remaining in the numeric fields.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D133&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D133&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/56f8f914793a5a18c7cab55b690843c4/href">https://medium.com/media/56f8f914793a5a18c7cab55b690843c4/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D134&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D134&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/817bc54c1d624aaf3fe25df89faf2bd2/href">https://medium.com/media/817bc54c1d624aaf3fe25df89faf2bd2/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D135&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D135&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/f258e2ddbf737e294043483ea83c5ab6/href">https://medium.com/media/f258e2ddbf737e294043483ea83c5ab6/href</a></iframe><p>Looks like the numeric fields for both the dataframes are now filled. Lets move on to the next step of scaling the numeric fields.</p><ul><li><strong>Scaling Numeric Features</strong></li></ul><p>In order to avoid having disproportionate impact of these numeric features on the mode’s loss, lets scale the features to be between 0 and 1. To do so, we will be using MinMaxScaler.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.com%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D138&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D138&amp;image=https%3A%2F%2Fapi.jovian.com%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00%3Fts%3D1667020065446&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba56f0b46e2a05c0ee2a170d3dc88295/href">https://medium.com/media/ba56f0b46e2a05c0ee2a170d3dc88295/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.com%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D139&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D139&amp;image=https%3A%2F%2Fapi.jovian.com%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00%3Fts%3D1667020065446&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2a14496c5f219e12b7c05707de50791/href">https://medium.com/media/a2a14496c5f219e12b7c05707de50791/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D140&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D140&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ad834bd9edd65c7ba20478f2802587a/href">https://medium.com/media/1ad834bd9edd65c7ba20478f2802587a/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttp%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D141&amp;dntp=1&amp;display_name=Jovian&amp;url=http%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D141&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/0965e70cee977841e75e7646115fc754/href">https://medium.com/media/0965e70cee977841e75e7646115fc754/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D142&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D142&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/c723c48f5c46f53208ae4cac3bb9afea/href">https://medium.com/media/c723c48f5c46f53208ae4cac3bb9afea/href</a></iframe><p>As can be seen, the describe method when applied to the three dataframes, have min value as 0 and max as 1. This means that the values are now scaled to be in range of 0 to 1 for the three dataframes.</p><p><strong>▹Encoding categorical data</strong></p><p>Now that we have the numerical data imputed and scaled, lets move on to categorical data and encode the values. By doing so, the categories within the categorical columns can be represented by numerical values. This step is important because machine learning models can only be trained with numeric data. We will be using a technique called one-hot encoding for converting the categorical values to numeric values. This means that the categories within the categorical data will become individual columns.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.com%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D145&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D145&amp;image=https%3A%2F%2Fapi.jovian.com%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00%3Fts%3D1667020065446&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a9ca68988a997760cd9150a7327dc99/href">https://medium.com/media/4a9ca68988a997760cd9150a7327dc99/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.com%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D146&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D146&amp;image=https%3A%2F%2Fapi.jovian.com%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00%3Fts%3D1667020065446&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/7fd4052fbaa04491ab844a77a052e9ac/href">https://medium.com/media/7fd4052fbaa04491ab844a77a052e9ac/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D147&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D147&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e27e0f66d18035699ad7bf0a30659c7/href">https://medium.com/media/8e27e0f66d18035699ad7bf0a30659c7/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.com%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D148&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D148&amp;image=https%3A%2F%2Fapi.jovian.com%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00%3Fts%3D1667020065446&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac8ca874d60fb95903bc650a409b4caa/href">https://medium.com/media/ac8ca874d60fb95903bc650a409b4caa/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.com%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D149%26hideOutput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D149%26hideOutput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.com%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00%3Fts%3D1667020065446&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/46c037f0b2df9bb52bc60f7952660648/href">https://medium.com/media/46c037f0b2df9bb52bc60f7952660648/href</a></iframe><h4>Model input prerequisites</h4><p>Before trying out different models on the data, there are a few prerequisites that we need to perform to get the best results. As per the requirement by Kaggle, we are supposed to use Normalized Weight Root Mean Square Logarithmic Error NWRMSLE where weight parameter is under perishable column in Item.csv Just to compare, we will also be calculating RMSE error. We need to make sure that perishable value of 0 is mapped as 1 and value of 1 is mapped as 1.25 when considering these values for weights. Also, because the validation set is carved out of the training set(25% of sample training data is reserved for validation), we will be merging the training and validation sets as one dataset and fitting model to this data once before we apply the model to the test dataset. By doing so, our model will get trained on bigger dataset and will be able to deliver better results. So lets get started on these steps before we train and compare different models.</p><p><strong>▹Normalized Weight Root Mean Square Logarithmic Error function</strong></p><p>[ NWRMSLE = \sqrt{ \frac{\sum{i=1}^n wi \left( \ln(\hat{y}i + 1) — \ln(yi +1) \right)² }{\sum{i=1}^n wi}} ]</p><p>Here w is the weight found in items.csv. Lets write a function to calcute the formula. Because we are dealing with log values, lets make sure that the values we feed for logarithimic calculations are always valid (more than 0). The function below, nwrmsle_err, helps us get NWRMSLE error and any value for predictions that are below zero are converted to be 0.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D152&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D152&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/f782bf2b6e6ec374473759325bb27229/href">https://medium.com/media/f782bf2b6e6ec374473759325bb27229/href</a></iframe><p><strong>▹Big dataset</strong></p><p>Lets merge the training and validation dataset and save as a dataframe. We will use this dataframe to fit the model once before fitting to the test dataset.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D154&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D154&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a90ba94d1911437ee22554abfb2d35a/href">https://medium.com/media/9a90ba94d1911437ee22554abfb2d35a/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D155&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D155&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9d14ede54185b17a6a792a4a3384c68/href">https://medium.com/media/b9d14ede54185b17a6a792a4a3384c68/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D156%26hideOutput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D156%26hideOutput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf9e7969887458979a01186aad45bacc/href">https://medium.com/media/cf9e7969887458979a01186aad45bacc/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D157%26hideOutput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D157%26hideOutput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b915f8ab5364cc42b3e20b5febdc042/href">https://medium.com/media/6b915f8ab5364cc42b3e20b5febdc042/href</a></iframe><p><strong>▹Weights for model</strong></p><p>We are supposed to treat value of 0 as 1 and value of 1 as 1.25 for for perishable column. This is because then we will be able to use these values as weights to the model. Lets map the input dataframes accordingly.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D159%26hideOutput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D159%26hideOutput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d8207381b910443ff687ef827fb2c7b/href">https://medium.com/media/3d8207381b910443ff687ef827fb2c7b/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D160&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D160&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/c302b63a15ffad2423a56cc3597d8cac/href">https://medium.com/media/c302b63a15ffad2423a56cc3597d8cac/href</a></iframe><h4>Model prediction and evaluation</h4><p>We will now start to implement different modelling techniques and compare Random Forest Regressor with Gradient Boosting Regressor models. Lets start with Random forest which is basically a collection of many decision trees. We will be fine tuning the Hyperparameters in Random Forest so our model gives better results.</p><p><strong>▹Random Forest Regressor</strong></p><p>The Decision Tree Models generally tend to overfit and have poor generalization. In this project, we have previously used Decision Tree Regressor model and did not get very good results. For this reason, the next model to try is Random Forest regressor. Many decision trees make a random forest. In this model, each decision tree is trained with slightly different parameters and the errors of the decision trees get cancelled out upon averaging. We will be defining two functions that eventually help us plot training and validation nwrmsle errors when hyperparameters are tuned. Lets first define a function, tune_parameter , that trains a Random Forest regressor model with various hyperparameters and outputs nwrmsle errors. This function will be used as a helper function that gets plugged in another function, tune_and_plot , which shows the training and validation error curves. This graph is known as Model “Complexity” graph and is very helpful in tuning the hyperparameters.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D173&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D173&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9816eed7e2797ee842f793223ecd2be/href">https://medium.com/media/b9816eed7e2797ee842f793223ecd2be/href</a></iframe><p>The function below, tune_and_plot , takes **kwargs as parameters and plots a graph that show us a best fit curve with respect to training and validation dataset.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D175&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D175&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/73489be41c91c8f940eab360454a585c/href">https://medium.com/media/73489be41c91c8f940eab360454a585c/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting-test-2%2Fv%2F33%26cellId%3D176&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting-test-2%2Fv%2F33%26cellId%3D176&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F842807f16a5e41708e934cd6110c6bcf%2Fpreview%2F3bd064852771462f9879797b015e762e&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/cdd4f9bb5fb1ce798972ee42a69cfd31/href">https://medium.com/media/cdd4f9bb5fb1ce798972ee42a69cfd31/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting-test-2%2Fv%2F33%26cellId%3D177&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting-test-2%2Fv%2F33%26cellId%3D177&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F842807f16a5e41708e934cd6110c6bcf%2Fpreview%2F3bd064852771462f9879797b015e762e&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/0afdccc8f667904a3cd9676884956997/href">https://medium.com/media/0afdccc8f667904a3cd9676884956997/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting-test-2%2Fv%2F33%26cellId%3D178&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting-test-2%2Fv%2F33%26cellId%3D178&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F842807f16a5e41708e934cd6110c6bcf%2Fpreview%2F3bd064852771462f9879797b015e762e&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/71f7e26838d5228239a6111992dcf923/href">https://medium.com/media/71f7e26838d5228239a6111992dcf923/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting-test-2%2Fv%2F33%26cellId%3D179&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting-test-2%2Fv%2F33%26cellId%3D179&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F842807f16a5e41708e934cd6110c6bcf%2Fpreview%2F3bd064852771462f9879797b015e762e&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc24313bf0b2cae97efb03752172cdec/href">https://medium.com/media/dc24313bf0b2cae97efb03752172cdec/href</a></iframe><p>So, by above graphs, we can conclude that below are optimum values for hyperparameters to yield us the best results: max_depth = 20 , min_samples_split=5 , n_estimator = 400 , max_samples = 0.9 These values were determined by looking at the graphs above. Usually the best fit is a point where the training error is low and validation/test error is just about to increase.</p><p>Now that we have the best fit values for hyperparameters, lets plug those in the model and fit generate predictions on training, validation and test datasets.</p><ul><li><strong>Training dataset</strong></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F616%26cellId%3D243&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F616%26cellId%3D243&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9d9e3005633c6ae640e411bedad295a/href">https://medium.com/media/b9d9e3005633c6ae640e411bedad295a/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F616%26cellId%3D244&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F616%26cellId%3D244&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/95e0812e3cf4a4ba5f5790195fea39e2/href">https://medium.com/media/95e0812e3cf4a4ba5f5790195fea39e2/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F616%26cellId%3D245&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F616%26cellId%3D245&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/0cc6bc3b2fac6df903892ec340549bb4/href">https://medium.com/media/0cc6bc3b2fac6df903892ec340549bb4/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D185&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D185&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/688abd44d28d37dfa4f92785cdd4a1cb/href">https://medium.com/media/688abd44d28d37dfa4f92785cdd4a1cb/href</a></iframe><ul><li><strong>Validation dataset</strong></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D187&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D187&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/82829adbd8f0fe6a4b94a6fdeed0a5ea/href">https://medium.com/media/82829adbd8f0fe6a4b94a6fdeed0a5ea/href</a></iframe><ul><li><strong>Big training dataset</strong></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D189&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D189&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c1a4a2ef3cd8f5c3da56897a66eabcf/href">https://medium.com/media/4c1a4a2ef3cd8f5c3da56897a66eabcf/href</a></iframe><p><strong>▹Feature Importance</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D191&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D191&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/035a5a5422bf035c2d2807e0df725436/href">https://medium.com/media/035a5a5422bf035c2d2807e0df725436/href</a></iframe><p>So by calculating the feature importance again, we can conclude that the five most important factor contributing to the sales is the item number, followed by class,transactions, the daily oil price and the day of week. As can be seen here too, NWRSMLE gives much better results than RMSE.</p><p><strong>▹ Gradient Boosting Regressor</strong></p><p>Lets enhance our results by using one more model, Gradient Boosting Regressor. The name Gradient Boosting comes from ‘Gradient’ coming from gradient descent algorithm — It minimizes the loss by creating new decision trees. And ‘Boosting’ that learns from the previous decision tree’s prediction. Basically Gradient Boosting is a boosting technique that tries to minimize the error by creating new decision tree every time. The way its significantly different from Random Forest is that the in later, the tree has to learn entire relationships whereas in Gradient Boosting , the model reduces what needs to be learnt. Here, the second decision tree is based on how the previous one was created and what were its predictions.</p><p>We will be using Hyperparameter tuning for this model too. In this case, lets manually hypertune the parameters. For this, we will be manually giving different inputs to the parameters and checking for which combination do we get the best value for NWRMSLE error.</p><p>Here are some combination of values that we have used in the XGBregressor model to train the model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*3y0UYKABXHTfPGRScqvtIw.png" /></figure><p>As in case of Random Forest Regressor model, lets take the best fit parameters and set our hyperparameters accordingly.</p><ul><li><strong>Training dataset</strong></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D198&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D198&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a6719c83058873c7517c043e11db3d4/href">https://medium.com/media/1a6719c83058873c7517c043e11db3d4/href</a></iframe><ul><li><strong>Validation dataset</strong></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D200&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D200&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/56a5bf675abc2ea72587c7744215429e/href">https://medium.com/media/56a5bf675abc2ea72587c7744215429e/href</a></iframe><ul><li><strong>Big training dataset</strong></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D202&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D202&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7a9976b8c3cbf95461b4d43dd25bda0/href">https://medium.com/media/a7a9976b8c3cbf95461b4d43dd25bda0/href</a></iframe><p><strong>▹Feature Importance</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D204&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D204&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/3020338acb1cd39a474d875e57bec7d1/href">https://medium.com/media/3020338acb1cd39a474d875e57bec7d1/href</a></iframe><p>By looking at the results of Gradient Boosting Regression model, we can see that the five most contributing factors to the spike in sales are if the item belonged to Produce, the sales in store number 2, 51 and 21 and the city of Cayambe.Cayambe is a tourist destination because of the compound volcano from the current Holocene epoch. Stores 2 is located in Quito city which is the capital of Ecuador, store 51 is in Guayaquil city which is the most populated city of the county and store 21 is in Santo Domingo which is , again, a very popular touristic destination. These reasons make sense as to what causes the unit sales go up.</p><h4>Comparison to Decision Tree Regressor and Random Forest Regressor</h4><p>As can be seen from the above results, results from Random Forest and Gradient Boosting Regressor are very close, with the Gradient Boosting Regressor model giving us slightly better validation results. The training data and bigger training data too give us better results when fit into Gradient boosting regression model. This makes sense because Gradient Boosting Regressor uses boosting as opposed to bagging that Random Forest Regressor used. The difference is that in boosting, new trees are formed that reduce the errors of the previous predictions. In boosting, we may not necessarily use all the features to train the model, while in case of Random Forest Regressor, all the features of a random sample of data is used as a bagging technique to produce a more robust results than just Decision Tree Regressor.</p><p>Now that we know the best performing model, lets go ahead and draw predictions on the test dataset using this model. After doing so, we will upload our results into Kaggle and check where we stand with our scores.</p><h4>Fitting to Test dataset</h4><p>Lets draw prediction using Gradient Boosting regressor on Test dataset.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D209&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D209&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e79e35c3bba74cb674b04408f703964/href">https://medium.com/media/8e79e35c3bba74cb674b04408f703964/href</a></iframe><p>Before we go ahead with the final result deliverables, lets go ahead and check all the values in the prediction that are below zero and convert those to 0. This way we will not have any negative datapoints in our prediction set. Lets set up a function to do some data cleaning of prediction points.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D211&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ffavorita-grocery-sales-forecasting%2Fv%2F685%26cellId%3D211&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F7e6a294a66324d6a8f73dc7888f4cda6%2Fpreview%2F28e0e35910be4a78a8fdb094b2ac3b00&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/31b76ecd3327eada5acb775eb382e4a1/href">https://medium.com/media/31b76ecd3327eada5acb775eb382e4a1/href</a></iframe><h4>Conclusion</h4><p>In this project, we have compared Random forest regressor and Gradient boosting regressor models. A fraction of training data (0.1 of total training data), was used to train the model because of the low memory issue. Following are the major conclusion of this study.</p><ul><li>Feature engineering helps in transforming the data in format that is best fit for fitting into a model.</li><li>Its always a good idea to compare two or more models to obtain best results.</li><li>It is found that after hypertuning the parameters, the training loss for training and bigger training dataset has significantly improved when measured against the RMSE and NWRMSLE loss.</li><li>Gradient Boosting gives the best result for validation loss for RMSE and NWRMSLE as compared to Decision Tree Regressor or Random Forest Regressor.</li><li>Whole training data must be used to get the best Kaggle score.</li></ul><h3>References</h3><ul><li>How to Feature Selection — A Tutorial [Updated] : <a href="https://jovian.ai/outlink?url=https%3A%2F%2Fwww.kaggle.com%2Fcode%2Fbhatnagardaksh%2Fhow-to-feature-selection-a-tutorial-updated">https://www.kaggle.com/code/bhatnagardaksh/how-to-feature-selection-a-tutorial-updated</a></li><li>Decision Trees and Random Forests : <a href="https://jovian.ai/learn/zero-to-data-analyst-bootcamp/lesson/decision-trees-and-random-forests">https://jovian.ai/learn/zero-to-data-analyst-bootcamp/lesson/decision-trees-and-random-forests</a></li><li>Gradient Boosting Machines with XGBoost : <a href="https://jovian.ai/learn/zero-to-data-analyst-bootcamp/lesson/gradient-boosting-machines-with-xgboost">https://jovian.ai/learn/zero-to-data-analyst-bootcamp/lesson/gradient-boosting-machines-with-xgboost</a></li><li>How to Train a Regression Model Using a Random Forest : <a href="https://jovian.ai/outlink?url=https%3A%2F%2Fmedium.com%2Ftowards-data-science%2Fhow-to-train-a-regression-model-using-a-random-forest-c1cf16288f6b">https://medium.com/towards-data-science/how-to-train-a-regression-model-using-a-random-forest-c1cf16288f6b</a></li><li>Targeting Multicollinearity With Python : <a href="https://jovian.ai/outlink?url=https%3A%2F%2Ftowardsdatascience.com%2Ftargeting-multicollinearity-with-python-3bd3b4088d0b">https://towardsdatascience.com/targeting-multicollinearity-with-python-3bd3b4088d0b</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=488405eeea2c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploratory Data Analysis On Telecom Italia Big Data Challenge]]></title>
            <link>https://yasheejoshi.medium.com/exploratory-data-analysis-on-telecom-italia-big-data-challenge-6522a6d761f9?source=rss-f5d9a1531b4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6522a6d761f9</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[plotly]]></category>
            <category><![CDATA[telecommunication]]></category>
            <category><![CDATA[python-data-science]]></category>
            <category><![CDATA[exploratory-data-analysis]]></category>
            <dc:creator><![CDATA[yashee joshi]]></dc:creator>
            <pubDate>Thu, 28 Oct 2021 02:44:20 GMT</pubDate>
            <atom:updated>2021-10-28T03:20:19.981Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZtMPIpSjsKTx0Tng" /><figcaption>Photo by <a href="https://unsplash.com/@anniespratt?utm_source=medium&amp;utm_medium=referral">Annie Spratt</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote><em>“The goal is to turn data into information and information into insight.”</em></blockquote><blockquote><em>— Carly Fiorina, former CEO and chair of Hewlett-Packard Company</em></blockquote><p>Telecom Italia, a telecom company in Italy, organized a Big Data Challenge back in 2014. The goal of this challenge was to come up with technological ideas related to big data that in return may contribute to innovation in the sector. As a part of this challenge, Telecom Italia collaborated with other Italian industries and academic organizations to collect data between November 2013 and December 2013 to give to the participants to use.</p><p>This project is focused on studying trend of telecom data for 7 days (November 1 2013 through November 7 2013) for Milan province of Italy. The dataset used in this study contains spatially aggregated square cells of study area (Milan province) segmented in 235x235 meters grid structure, the boundary of the Milan Province, telecommunication activity per cell id giving details on to and from locations for telecom activity and what kind of activity-sms, calls or internet usage. The data is downloaded from Kaggle <a href="https://www.kaggle.com/marcodena/mobile-phone-activity.">https://www.kaggle.com/marcodena/mobile-phone-activity</a>.</p><p>Following are the data files used:</p><ol><li>mi-to-provinces-2013-11-01.csv</li><li>mi-to-provinces-2013-11-02.csv</li><li>mi-to-provinces-2013-11-03.csv</li><li>mi-to-provinces-2013-11-04.csv</li><li>mi-to-provinces-2013-11-05.csv</li><li>mi-to-provinces-2013-11-06.csv</li><li>mi-to-provinces-2013-11-07.csv</li><li>milano-grid.geojson</li><li>Italian_provinces.geojson.geojson</li><li>sms-call-internet-mi-2013-11-01.csv</li><li>sms-call-internet-mi-2013-11-02.csv</li><li>sms-call-internet-mi-2013-11-03.csv</li><li>sms-call-internet-mi-2013-11-04.csv</li><li>sms-call-internet-mi-2013-11-05.csv</li><li>sms-call-internet-mi-2013-11-06.csv</li><li>sms-call-internet-mi-2013-11-07.csv</li></ol><p>Final goal of this study is to analyze pattern of the data and observing trends on different kind of telecom activities like receiving and sending calls, sms and internet usages.<br>We start by importing necessary libraries.</p><h3>Importing the Libraries</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F215%26cellId%3D4&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F215%26cellId%3D4&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2F1268f4c3902b49429b2407515c54ea7a&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/36da629cea7f99242ff8ee03b57fbcc6/href">https://medium.com/media/36da629cea7f99242ff8ee03b57fbcc6/href</a></iframe><p>Here,<em> opendatasets </em>— a python library for downloading data from online sources like Kaggle and Google drive, is used to download the datasets from <a href="https://jovian.ai/outlink?url=https%3A%2F%2Fwww.kaggle.com%2Fmarcodena%2Fmobile-phone-activity">https://www.kaggle.com/marcodena/mobile-phone-activity</a>.</p><h4>Downloading the datasets from Kaggle:</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D7&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D7&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/422ee6168b3215c9013f7af0532e5cd3/href">https://medium.com/media/422ee6168b3215c9013f7af0532e5cd3/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D8&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D8&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/90f4da10f08cf1ef95cd7050908b0e87/href">https://medium.com/media/90f4da10f08cf1ef95cd7050908b0e87/href</a></iframe><p>Lets read the .geojson files for the Italian province boundary along with the 235x235 meters grid and store them in a <em>geopandas </em>dataframe. Since the boundary file contains provinces for the whole country, we will be filtering out all but Milan province.</p><h3>Spatial Operations using Geopandas:</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D10&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D10&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4de8826ae096c4d888e97936243bc59/href">https://medium.com/media/b4de8826ae096c4d888e97936243bc59/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D11&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D11&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/73d7155ba48a749e87727797a1944933/href">https://medium.com/media/73d7155ba48a749e87727797a1944933/href</a></iframe><p>The Milan province’s grid breaks the province into ten thousand cells. Some of these cells are slightly outside of the province boundary, so those cells are not considered in the study. To do so, the grid is overlaid on the province boundary using the <em>sjoin</em> operation offered by geopands and only cells within the boundary are considered.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D13&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D13&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/882291f58a4ab4f61ce3d7f9a4877e19/href">https://medium.com/media/882291f58a4ab4f61ce3d7f9a4877e19/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttp%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F217%26cellId%3D17&amp;dntp=1&amp;display_name=Jovian&amp;url=http%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F217%26cellId%3D17&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/c832f34a82fb832156bee28fb4a2c5cc/href">https://medium.com/media/c832f34a82fb832156bee28fb4a2c5cc/href</a></iframe><p>Notice on the top right section of grid on the map. These are some cells that are outside of Milan province boundary. <em>Folium</em> offers interactive map so you are able to zoom in and out of this map.</p><p>Lets check out ‘Milan_cells’ dataframe that contain the cells inside of the Milan province boundary. Notice how there are now 9,746 cells out of 10,000:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D15&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D15&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ae77868e82f7d08fd115c2bb1b13a3c/href">https://medium.com/media/7ae77868e82f7d08fd115c2bb1b13a3c/href</a></iframe><h3>Study data trends using charts</h3><h4>Interaction from cells to the provinces of Italy :</h4><p>The function defined below, ‘C2P_data’ reads the csv to pandas dataframe, only selects the cells that are chosen in the previous step, saves them to a new dataframe ‘new_C2P’. Further processing is done on this new dataframe to drop all the values that are NaN values and only ‘Cell2Province’ and ‘Province2Cell’ are copied over. The ‘datetime’ column is then broken down to show the day and time components and appended back into the ‘new_C2P’ dataframe. In the final dataframe ‘df’ values from ‘new_C2P’ dataframe are sorted for time and ‘cell2Province’ columns and only the first 200 rows are stored. The dataframes for 7 days are then merged into one dataframe, ‘merged_c2p_df’, that is then considers for making a histogram graph.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D18&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D18&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff345547f09c29d21a82376eff3eb74f/href">https://medium.com/media/ff345547f09c29d21a82376eff3eb74f/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D19&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D19&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2a6a24ca43c806b3455fa2bb12fb465/href">https://medium.com/media/b2a6a24ca43c806b3455fa2bb12fb465/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D20&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D20&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/470f796c57ed342ea433a9f81d260291/href">https://medium.com/media/470f796c57ed342ea433a9f81d260291/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D21&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D21&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/d37327e99292e95355725d2309aa94dc/href">https://medium.com/media/d37327e99292e95355725d2309aa94dc/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D22&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D22&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ecfdfbf9ddf575c3284f738c01dbbf8b/href">https://medium.com/media/ecfdfbf9ddf575c3284f738c01dbbf8b/href</a></iframe><p>Lets try to see some pattern in the data for 7 days using a histogram. Plotly supports creating an animated frame which can be used to show trends for each day of the week.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F210%26cellId%3D29&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F210%26cellId%3D29&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Faef194c9d42c4eefa5ae4823b941433c&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/123f0a69326497555b7b6587c2227ba1/href">https://medium.com/media/123f0a69326497555b7b6587c2227ba1/href</a></iframe><p>From the histogram above, we can see that most cell to province activity for days 1, 2 and 4 happens at 11:00 hrs, for day 3 its at 17:00 hrs, for day 5, 6 and 7 its at noon time. We can also see a drastic increase in cell to province telecom activity from day 4 through day 7.</p><p>Same activity is repeated for finding out province to cell trend. A function ‘P2C_data’ returns a dataframe that has top 200 values for each day of the week with sorted values for ‘time’ and ‘Province2cell’ columns. The dataframes for 7 days are then merged into one dataframe, ‘merged_p2c_df’, that is then considers for making a histogram graph.</p><h4>Interaction from provinces to the cells :</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D27&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D27&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae4f2b1e9c1aa10f5677e4ef9cea11ac/href">https://medium.com/media/ae4f2b1e9c1aa10f5677e4ef9cea11ac/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D28&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D28&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/c854bb163c2862ff0984e02995e0ef0d/href">https://medium.com/media/c854bb163c2862ff0984e02995e0ef0d/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D29&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D29&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/05e11c0a448db6fa4c8ab7f8c8f6d0c1/href">https://medium.com/media/05e11c0a448db6fa4c8ab7f8c8f6d0c1/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D31&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D31&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/60c6e79f4f7c12c3d7db19570a7edc42/href">https://medium.com/media/60c6e79f4f7c12c3d7db19570a7edc42/href</a></iframe><p>As can be seen by the histogram above, highest province to cell activity for days 1 and 2 happens at 11:00 hrs, for day 3 is at 17:00 hrs, for day 4 is at 13:00hrs, for day 5, 6, 7 is at noon time. And here too, province to cell activity increase from day 4 through day 7. Also a good point to note from the two histograms above is that the rise in cell 2 province and province to cell activity is at the same hour for day except for day 4 for cell 2 province is highest at 11:00 hrs while province to cell is at 13:00 hrs.</p><p>Next, the cells that are highly active are identified as ones that have both high cell to province and high province to cell activities. To pick out these cells, a function ‘pick_cellid’ is defined showing a peak for activities in histograms above. This is done by first obtaining the cumulative sum of activity grouped by hour of the day and then selecting the max value which results in peak in the histograms. Doing this, we can then see what is the value for time that yields the maximum value for sum of activity. The same function is used twice, first time to pick out the cells with high cell to province activity and second time for high province to cell activity</p><h4>Pick highly active cells :</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D34&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D34&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d47e7bb0574949cbd736c1c89e3f5bf/href">https://medium.com/media/9d47e7bb0574949cbd736c1c89e3f5bf/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D35&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D35&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c129536ce19d2ccce7f1d41f4eee8fd/href">https://medium.com/media/8c129536ce19d2ccce7f1d41f4eee8fd/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D36&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D36&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed2646cf0eb6a4eb3820c3065beb3853/href">https://medium.com/media/ed2646cf0eb6a4eb3820c3065beb3853/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D37&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D37&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/204c626767c572cab48b1de8ce60a8af/href">https://medium.com/media/204c626767c572cab48b1de8ce60a8af/href</a></iframe><p>Now that we have a dataframe each for max cell to province and max province to cell activities, lets try to find out the cells that are common between the two. These will then be the most active cells.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D39&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D39&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a69f836864636c9bf5250f5c79fe7c5/href">https://medium.com/media/7a69f836864636c9bf5250f5c79fe7c5/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D40&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D40&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2484980f91b3a21c7504634de180c4d/href">https://medium.com/media/a2484980f91b3a21c7504634de180c4d/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D41&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D41&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/c803b1c5e439bf15dd66857c9cbac851/href">https://medium.com/media/c803b1c5e439bf15dd66857c9cbac851/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D42&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D42&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/36d7578428f37a168191fafa22195400/href">https://medium.com/media/36d7578428f37a168191fafa22195400/href</a></iframe><p>Find the cells common between the cell to province and province to cell:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D45&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D45&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/64216d897d040d29eeffbe96e58729e7/href">https://medium.com/media/64216d897d040d29eeffbe96e58729e7/href</a></iframe><p>Lets now create a heatmap to get some idea on the trend of telecom activity on cell level. To do so, we need to start with structuring the dataframe in a way we can create the heatmap. For this we need to pivot the dataframe:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D46&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D46&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/022bd37bce73abe946c412e8964a6e95/href">https://medium.com/media/022bd37bce73abe946c412e8964a6e95/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D47&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D47&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/d63e57da3de467d3a26fdb37972df2e8/href">https://medium.com/media/d63e57da3de467d3a26fdb37972df2e8/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D48&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D48&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/7119e37a2e4f9811b198ac646aa69c59/href">https://medium.com/media/7119e37a2e4f9811b198ac646aa69c59/href</a></iframe><p>The trend as can be observed in the heatmap shows that the telecom activity for the cell ids have increased from day 4 to 7 and is relatively low from day 1 to 3. The darker the tone is the more active the cell is.</p><p>Lets try to look at the high telecom activity cells on the map. This may give us interesting insights on why these cells are so high in activity. For doing this, cell id with max activity(from the dataframe ‘revels’) are stored into a list which is then used to filter out records from ‘Milan_cells’ dataframe containing the cell grid geometry<em>.</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D51&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D51&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/494fb741b4b47d019cbd410519e4729a/href">https://medium.com/media/494fb741b4b47d019cbd410519e4729a/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D52&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D52&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/97f2dcc0da788bfa39bf8dbbad0255c9/href">https://medium.com/media/97f2dcc0da788bfa39bf8dbbad0255c9/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D53&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D53&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/46ca2ec75c89c5719a61616ae48a4e67/href">https://medium.com/media/46ca2ec75c89c5719a61616ae48a4e67/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F217%26cellId%3D64&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F217%26cellId%3D64&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Fccc414cd678e492097af5de22b6ef4f4&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/4606943861756c80ad87097115c91e28/href">https://medium.com/media/4606943861756c80ad87097115c91e28/href</a></iframe><p>Now that we have visibility on how the highly active cells look on the map and where they lie, lets try to look into reasons why these cells are so active. Just a little pan on the map around the city of Milan tells us how busy the city looks, with mixed building types like hospitals, offices, churches, university/ schools etc. In the code below, there are a few buildings with latitudes and longitudes from the province that help explaining the active telecom activity in the cells displayed above.</p><h4>Pick out some of the most popular locations in the province:</h4><p>Lets try to pick out 15 popular destinations of the province. The idea is to show a relation between highly active cells with popular locations in the province. For this we first prepare a dataframe with the name, latitude, longitude and category of location and then use this dataframe to show points on map. The points will be be shown as <em>CircleMarker</em> on Folium map with pop-up showing name of the location and its category when clicked<em>.</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D56&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D56&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/af74a979b1f413ffff8201aa08656658/href">https://medium.com/media/af74a979b1f413ffff8201aa08656658/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D57&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D57&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3ee86b14ff6b7178250037c2e2c9759/href">https://medium.com/media/b3ee86b14ff6b7178250037c2e2c9759/href</a></iframe><p>Above map helps in understanding why the overlaid cells may show high telecom activity. Because the points shown on the map are popular locations of the province, these locations may have high traffic which causes the telecom activity rise, especially the internet usage as we are about to observe from the study done in the next section. By clicking on these points, we can see the name of the location and the category of the location. Some of the categories for these points may include Churches, Hospitals and Universities.</p><h3>SMS, Calls and Internet Datasets</h3><p>In this section, new dataset is introduced to the study that has data with sms in, sms out, call in, call out and internet usage of the cells. The activities are proportional to the amount of issued sms in/sms out/calls in/ calls out/ internet usage inside a given cell id during a given time interval. From the prior knowledge of what are the cells with highest activity, a function ‘sci_activity’ is defined below to read the .csv files containing this data for selected cells ids. And rows containing NaN values for any field are eliminated.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D60&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D60&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/e38c8567af8dbd36694a5d0e841c2495/href">https://medium.com/media/e38c8567af8dbd36694a5d0e841c2495/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D61&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D61&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/330d142678f6f9e15abfdfa0edaba06e/href">https://medium.com/media/330d142678f6f9e15abfdfa0edaba06e/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D62&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D62&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e285ae8164517a6401a76d3beabadc4/href">https://medium.com/media/4e285ae8164517a6401a76d3beabadc4/href</a></iframe><h4><strong>Telecom Activity trend:</strong></h4><p>From the dataframe obtained above, ‘’merged_sci_df’, lets find out what kind of activity was highest.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D64&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D64&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/a405dbd14737f7af1a205041c839ca1b/href">https://medium.com/media/a405dbd14737f7af1a205041c839ca1b/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D66&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D66&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/93bd79dd89d1fab064cec9d122a62a6b/href">https://medium.com/media/93bd79dd89d1fab064cec9d122a62a6b/href</a></iframe><p>As seen in the chart above, its clear that the internet activity is highest kind of activity, followed by calls going out issued by user, calls received by the user and sms sent out and the least kind of activity is sms coming in.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D68&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D68&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7185b730e5e7c0bc7d3325a98496167/href">https://medium.com/media/a7185b730e5e7c0bc7d3325a98496167/href</a></iframe><h4>Top ten countries with most activity :</h4><p>Lets check out top ten most contacted countries. This can be shown by using line chart. First, lets have top ten countries with highest activity into a list. Then, ‘merged_sci_df’ dataframe can be filtered to only have countries that are in the list.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D70&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D70&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/f01a88a5efcb6b9642e6fc2d587e1cf7/href">https://medium.com/media/f01a88a5efcb6b9642e6fc2d587e1cf7/href</a></iframe><p>From the dataframe obtained above, a ‘group by’ function is used to group by country codes and number of times they occur is added. For example, country with country code 39 comes 56450 times.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D72&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D72&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e5809cfc9ca4158e22648accf063c7e/href">https://medium.com/media/7e5809cfc9ca4158e22648accf063c7e/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D73&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F198%26cellId%3D73&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Ff509ea40b62f4dcfa3e6c2bd41035210&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ccd6bc43ff30a6842a092c410bae8683/href">https://medium.com/media/ccd6bc43ff30a6842a092c410bae8683/href</a></iframe><p>As can be seen on the chart, the highest calls are made to country code 39 for Italy followed by 41 for Switzerland , 33 for France, 86 for China, 7 for Kazakhstan, 46 for Sweden , 44 for UK, 34 for Spain, 49 for Germany and 1 for United States.</p><h4><strong>Study data distribution for each of these telecom activity:</strong></h4><p>Lets look at the box plots for each of these activities. A box plot is a great way of showing the distribution of data using box and whiskers. The data is distributed starts from ‘Minimum’ , going towards the First Quartile (Q1), in this region lie the first 25 percentile of data points, next is Median (Q2) which is the middle value of the data. This is followed by the the Third Quartile(Q3) which is the value between the median and the maximum value for the data and finally we have the Maximum value for the data. The outlier data values are shown as points in the box plot.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F214%26cellId%3D97&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Ftelcoeda%2Fv%2F214%26cellId%3D97&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2F367eddb8d4ee46debba3c1577bbc4564%2Fpreview%2Fd6e7ff3996ce477f8e03cf54aab3905e&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/00c80c64595f1f6c1f846098ace0480b/href">https://medium.com/media/00c80c64595f1f6c1f846098ace0480b/href</a></iframe><p>Plotly allows us to slice the boxplots. What this does is gives us a zoomed in view for the sliced portion of box plot. Here is a peak at how the boxplots look when zoomed in. The sliced sections are showing the data distribution for each case giving us a view between minimum and maximum values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jr2kxaQY6ZoQUbGUT649BQ.png" /><figcaption>Sliced boxplots</figcaption></figure><p>As can be observed from the box plots above, the maximum value for smsin activity is highest on day 7,maximum value for smsout, callin and callout are highest for day 5 and the maximum value for internet is highest for day 2. The data for internet and smsout shows a more consistent pattern for all the days where median value is at equal distance of Q1 and Q2, while for all other activities, the median value seem to be closer to Q1.However, for all the activities, the median values are somewhat equidistant from Q1 and Q2 for days 1–3. When we see a shorter box plot, that means that the data is distributed consistently around the median values whereas a taller box plot shows much more variation from median values in data. Here, callin data distribution from day 4 through 7 show taller box plots which means that the data distribution is varying from the median values. There are outliers for each activity’s distribution. These outlier points lie further from the maximum end of the whisker, which means that in all the cases the outliers are the values that are greater than the maximum values of the distribution. Another interesting observation from the box plot above is that in some cases, the minimum value (the lower whisker) is close to the Q1 value. This is because of the way the data is distributed.</p><h3><strong>Conclusion</strong></h3><ul><li>This study was done with the data provided by Telecom Italia Big Data Challenge 2014.</li><li>The study handles data that’s 2GB in size which contains csv and .geojson file formats.</li><li>A pattern in telecom activity from cell to province and vice versa is studied using histogram chart. For most of the days the time with highest activity is same between cell and province to and fro.</li><li>A simple seaborn heatmap shows pattern of telecom activity for 100 cells being higher on day 4 through day 7. This can be extended to more number of cells.</li><li>A use of folium maps is made to show Milan province boundary and grid cells on map. Some of the busy locations are shown as circular markers on the map. An overlay of such points on the grid cells with high telecom activity indicate that the busier a place is the higher the telecom activity is going to be.</li><li>In all the telecom activities, the max activity is usage of internet followed by calls made out of the province.</li><li>Box plot charts are a nice way to show spread of data. Data for internet activity seems to show much consistent pattern.</li></ul><h3><strong>Future Scope</strong></h3><p>This study can be taken further by involving more variables like tweets and news feeds during that duration that gives information about the social pulse, the demographics of the area at the time and/or the census data. Next, this project was only focused on study area Milan, but the same can be extended to other provinces of Italy too if the data is available.</p><h3>Reference</h3><ul><li>Kaggle — Mobile Phone Activity in a City (<a href="https://www.kaggle.com/marcodena/mobile-phone-activity">https://www.kaggle.com/marcodena/mobile-phone-activity</a>)</li><li>Barlacchi, G., De Nadai, M., Larcher, R. et al. A multi-source dataset of urban life in the city of Milan and the Province of Trentino. Sci Data 2, 150055 (2015).</li><li>Kung, K., Greco, K., Sobolevsky, S. &amp; Ratti, C. Exploring universal patterns in human home-work commuting from mobile phone data. PLoS ONE 9, 6 (2014).</li><li>Jovian Tutorials: <br>- Data Visualization using Python, Matplotlib and Seaborn (https://jovian.ai/learn/zero-to-data-analyst-bootcamp/lesson/visualization-with-matplotlib-and-seaborn)<br>- Visualization with Plotly &amp; Folium (https://jovian.ai/learn/zero-to-data-analyst-bootcamp/lesson/interactive-visualization-with-plotly-and-folium)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6522a6d761f9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Finding Pizza Places in Massachusetts using OSM REST API and Web Scrapping techniques]]></title>
            <link>https://yasheejoshi.medium.com/finding-pizza-places-in-massachusetts-using-osm-rest-api-and-web-scrapping-techniques-d14ad8f19b09?source=rss-f5d9a1531b4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/d14ad8f19b09</guid>
            <category><![CDATA[openstreetmap]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[gis]]></category>
            <category><![CDATA[web-scrapping]]></category>
            <dc:creator><![CDATA[yashee joshi]]></dc:creator>
            <pubDate>Sun, 23 May 2021 01:31:18 GMT</pubDate>
            <atom:updated>2021-06-30T21:50:21.102Z</atom:updated>
            <content:encoded><![CDATA[<h3>Finding Pizza Places in Massachusetts using OSM REST API and Python Web Scraping techniques</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WRKF4szX2G_YvbtF" /><figcaption>Photo by <a href="https://unsplash.com/@abillion?utm_source=medium&amp;utm_medium=referral">abillion</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote><em>The world is a one big data problem -Andrew McAfee</em></blockquote><p>I like to think of OpenStreetMap as wikipedia for geographical data. Its freely available and open to edits and contributions from the users. So many professionals rely on its data. The data model of OSM is based on three components: <em>Nodes</em>, <em>Ways</em> and <em>Relation. </em>All these components come with IDs and tags. The <em>tags</em> are important feature as they describe in key-value pairs, what the component is about. There can be multiple tags describing a component. Here is an example of tags:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*LJOdYgB_C10Yb_PjCC02Fg.png" /><figcaption>Dunkin’ Donut facility with associated Tags</figcaption></figure><p>In the image above, towards the left under ‘Tags’, we can see all the tags that describe a Dunkin’ Donuts’ facility. The various tags can be found here: <a href="https://taginfo.openstreetmap.org/">https://taginfo.openstreetmap.org/</a> . These are just the tags with no spatial data to show on map. But we can make sense of these tags and get some insights on what all tags are relevant to search when looking for a facility. In the picture, a Dunkin Donut facility is described by tags like, ‘addr:city’,’addr:housenumber’, ‘addr:postnumber’, ‘amenity’, etc.</p><p>These tags help us to get an understanding of forming a query that goes as an input to overpass API <a href="http://overpass-api.de/">http://overpass-api.de/</a>. The overpass API is a REST API that allows us to look for information and extract it with spatial details. The API uses a custom query language, and the Overpass turbo wizard can help generate the queries. Here is an example of generating a query to get all the pizza places in Massachusetts:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gErS1M1LT8l54sLaRgKejA.png" /><figcaption>Turbo query pane</figcaption></figure><p>Note the three components that are queried in the picture above. When just ‘nodes’ are queried, they give back just point locations, ‘ways’ give us a polyline which connects two nodes, when closed, it’s a polyline forming the polygon hence giving the area or building footprint of the facility queried. And finally, ‘relation’ gives us the details about nodes or ways by giving us a list of tags that best describe the components. Relation also gives geographical relationships between components. In this blog, we will be going through how to extract desired dataset by going through right tags linked to it.</p><p><strong><em>Python Libraries and Uses:</em></strong></p><p>Following are the python libraries used and the reasons they are used for:</p><ul><li>Requests, BeautifulSoup &amp; Selenium: To scrape and turn site into a readable doc. Selenium for dynamically loaded data.</li><li>Overpass: To extract information from the OpenStreetMap’s API</li><li>Pandas: To overlay final results to Panda’s DataFrame.</li><li>Geopandas: To convert the Latitude and Longitude in Pandas Dataframe into geometry viewable on map.</li><li>Folium: To add base map and create interactive map</li></ul><p><strong><em>Functions to understand OpenStreetMap Site:</em></strong></p><p>Let’s start by pulling out the taginfo site and analyzing important tags in it. <a href="https://taginfo.openstreetmap.org/">https://taginfo.openstreetmap.org/</a> This is how the site looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*WNMfMSv4RF_ahqL1lmtchg.png" /><figcaption>Taginfo Page for OpenStreetMap</figcaption></figure><p>Here is a function defined, <em>taginfo_analyze</em> that helps in getting into webpage containing related values for a ‘key’ passed. The example below considers ‘Cuisine’ as a ‘key’. A key has various values associated with it. Cuisine has various values like ‘Pizza’, ‘Burger’, ‘Indian’, ‘Asian’ etc. associated. The function takes other keys like ‘Building’, ‘Highway’ or ‘Amenity’ and returns back a doc(HTML) file containing contents of that page.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F19%26cellId%3D14&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F19%26cellId%3D14&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2Ff821617022d144dca2745ccd56131bac%2Fpreview%2F42a1b3527683457d85d3e33193518f19%3Fsize%3Dl&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a328344424ed9b3a67fc0fb4c268234/href">https://medium.com/media/5a328344424ed9b3a67fc0fb4c268234/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F19%26cellId%3D15&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F19%26cellId%3D15&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2Ff821617022d144dca2745ccd56131bac%2Fpreview%2F42a1b3527683457d85d3e33193518f19%3Fsize%3Dl&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c47f5badfc0fe5d6ffa026743737c17/href">https://medium.com/media/2c47f5badfc0fe5d6ffa026743737c17/href</a></iframe><p>The function above gets us an HTML document for <a href="https://taginfo.openstreetmap.org/keys/cuisine">https://taginfo.openstreetmap.org/keys/cuisine</a> page which we will further analyze to get right tags to look for. This is how the page looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lk_0LuZQS3AKETCHObkF7Q.png" /><figcaption>cuisine page obtained through taginfo_analyze function</figcaption></figure><p>The values for the cuisine are under the value tab of the page. There are other tabs like <em>Overview</em>, <em>Combinations</em> and <em>Chronology</em>. Lets see if we can access these tabs. Lets check the links on the page the we have landed.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F19%26cellId%3D17&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F19%26cellId%3D17&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2Ff821617022d144dca2745ccd56131bac%2Fpreview%2F42a1b3527683457d85d3e33193518f19%3Fsize%3Dl&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3c60e3f554d998c17283cf3815a0e94/href">https://medium.com/media/e3c60e3f554d998c17283cf3815a0e94/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TZC865n0a5FEBkuKrsDHgA.png" /><figcaption>anchor tags</figcaption></figure><p>By looking at the picture for <em>anchor</em> <em>tags</em> above, we can make out a pattern. The href is what is holding the values for the tabs. Lets try to get the links to these tabs by filtering out the anchor tags using href .</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F19%26cellId%3D18&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F19%26cellId%3D18&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2Ff821617022d144dca2745ccd56131bac%2Fpreview%2F42a1b3527683457d85d3e33193518f19%3Fsize%3Dl&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/05f87f5eb134c0905aea046e675e7842/href">https://medium.com/media/05f87f5eb134c0905aea046e675e7842/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F19%26cellId%3D19&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F19%26cellId%3D19&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2Ff821617022d144dca2745ccd56131bac%2Fpreview%2F42a1b3527683457d85d3e33193518f19%3Fsize%3Dl&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/21197fad3b8582e0ecf64bc9101bbe13/href">https://medium.com/media/21197fad3b8582e0ecf64bc9101bbe13/href</a></iframe><p>And voila! We got links of tabs in the output</p><p>Now that we can access the values of the key, in this case key is ‘cuisine’, by using the link obtained above <a href="https://taginfo.openstreetmap.org/keys/cuisine#values&#39;,">https://taginfo.openstreetmap.org/keys/cuisine#values</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bTab0RgK8UydsnB5If5fdA.png" /><figcaption>Values for cuisine</figcaption></figure><p>The <em>value</em> tab has all the values for ‘cuisine’ key. These values are dynamically loaded and because of this reason, we can not use<em> Requests </em>library. Therefore we will be using <em>Selenium </em>library to read the values in this page. Selenium requires us to have chrome driver installed in local machine. Below is the function defined to read and get the values from the page.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F19%26cellId%3D21&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F19%26cellId%3D21&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2Ff821617022d144dca2745ccd56131bac%2Fpreview%2F42a1b3527683457d85d3e33193518f19%3Fsize%3Dl&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/6003f729f8bc67d6e3f4f100df483800/href">https://medium.com/media/6003f729f8bc67d6e3f4f100df483800/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D22&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D22&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2Ff821617022d144dca2745ccd56131bac%2Fpreview%2Ff8f1ca81b21447b5b71fc8fbc7b27198%3Fsize%3Dl&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac993b60a26cb200e1069e228646dcab/href">https://medium.com/media/ac993b60a26cb200e1069e228646dcab/href</a></iframe><p>Check out the output from above to see the values obtained from the function above in a list:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aPENz4CKg5NDmd1MFRB60Q.png" /><figcaption>values for cuisine using the tag_keys_values function</figcaption></figure><p>We can plug in values obtained as the resultant list of <em>tag_keys_values</em> function for the key ‘cuisine’ and get to the ‘<em>Combination</em>’ tab to see the tags associated with the key-value pair. The tags are what describe the features, in this case ‘<em>cuisine = pizza</em>’.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D24&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D24&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2Ff821617022d144dca2745ccd56131bac%2Fpreview%2Ff8f1ca81b21447b5b71fc8fbc7b27198%3Fsize%3Dl&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/63da305fba6a9972432c9f822bfdb9ff/href">https://medium.com/media/63da305fba6a9972432c9f822bfdb9ff/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D25&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D25&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2Ff821617022d144dca2745ccd56131bac%2Fpreview%2Ff8f1ca81b21447b5b71fc8fbc7b27198%3Fsize%3Dl&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d940606b3afc7002cce5b537da797d8/href">https://medium.com/media/0d940606b3afc7002cce5b537da797d8/href</a></iframe><p>We get ‘https://taginfo.openstreetmap.org/tags/cuisine=pizza#combinations&#39; as an output of above function. The tags can be viewed in the link obtained from <em>values_for_keys</em> function. A function is defined below to get the data from the link page.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D27&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D27&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2Ff821617022d144dca2745ccd56131bac%2Fpreview%2Ff8f1ca81b21447b5b71fc8fbc7b27198%3Fsize%3Dl&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0f6792f4fe117ec8bf8a789192a94b9/href">https://medium.com/media/c0f6792f4fe117ec8bf8a789192a94b9/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D28&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D28&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2Ff821617022d144dca2745ccd56131bac%2Fpreview%2Ff8f1ca81b21447b5b71fc8fbc7b27198%3Fsize%3Dl&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6f53df0b7b88d5b32f72612fa792c02/href">https://medium.com/media/a6f53df0b7b88d5b32f72612fa792c02/href</a></iframe><p>We get back a list with tags that describe pizza places:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4wsbf1H7I2GXYcVBopQ0Xg.png" /><figcaption>values for combinations using combination_tags function</figcaption></figure><p><strong><em>Using Overpass REST API</em></strong></p><p>Now that we have some understanding of key value pairs and tags associated, we can now get started with using the Overpass REST API: <a href="http://overpass-api.de/api/interpreter">http://overpass-api.de/api/interpreter</a> .OSM allows users to use the Overpass REST API to generate query and extract data out. We can specify what we are looking for in terms of key-value pair, and the tags associated with them. We can also specify the area/region we are trying to query. The below coded, <em>turbo_query </em>function is defined to find all the Italian Restaurants in Massachusetts. The area code for Massachusetts state is 61315 preceded by 36000 as seen here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kO4fZXmW3buYNo2HzyUULA.png" /><figcaption>Massachusetts Region as on OSM</figcaption></figure><p>As seen the values of tags above under <em>Combination</em> tab, we can use these tags to form a query. This is how typically a query and overpass-turbo query pane looks like :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UtIlfryLbeyYsrOYFZbt9A.png" /><figcaption>How a typical overpass-turbo query looks like</figcaption></figure><p>Lets define a function to form a query by using key-value pairs using the knowledge of tags and store the results in a pandas dataframe. In this function use of overpass API is being used.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D35&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D35&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2Ff821617022d144dca2745ccd56131bac%2Fpreview%2Ff8f1ca81b21447b5b71fc8fbc7b27198%3Fsize%3Dl&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/9534b0fa229cecc0aa790942cb45d782/href">https://medium.com/media/9534b0fa229cecc0aa790942cb45d782/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D36&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D36&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2Ff821617022d144dca2745ccd56131bac%2Fpreview%2Ff8f1ca81b21447b5b71fc8fbc7b27198%3Fsize%3Dl&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/6aebaaf9645499bba173f1f302b95180/href">https://medium.com/media/6aebaaf9645499bba173f1f302b95180/href</a></iframe><p><strong><em>Cleaning and reframing the dataframe obtained above:</em></strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D37&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D37&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2Ff821617022d144dca2745ccd56131bac%2Fpreview%2Ff8f1ca81b21447b5b71fc8fbc7b27198%3Fsize%3Dl&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6487e00f12f52888376b52d263090b1/href">https://medium.com/media/c6487e00f12f52888376b52d263090b1/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D38&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D38&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2Ff821617022d144dca2745ccd56131bac%2Fpreview%2Ff8f1ca81b21447b5b71fc8fbc7b27198%3Fsize%3Dl&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/edb5694e6c05f22d3d0a593592e4259d/href">https://medium.com/media/edb5694e6c05f22d3d0a593592e4259d/href</a></iframe><p>The new_df dataframe obtained by the function <em>get_new_df</em> contains geometry type of Node and Polygon represented by Node and Ways respectively. Lets plot first 50 nodes on the map. We can do this using <em>Geopandas</em>.</p><p>We can start by creating a new pandas dataframe and then converting it into geopandas dataframe using the lat-long values as shown in the code snippet below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D45&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D45&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2Ff821617022d144dca2745ccd56131bac%2Fpreview%2Ff8f1ca81b21447b5b71fc8fbc7b27198%3Fsize%3Dl&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/800cf2c1fdd848093c28afcfd3fc1a43/href">https://medium.com/media/800cf2c1fdd848093c28afcfd3fc1a43/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F24%26cellId%3D46&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F24%26cellId%3D46&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2Ff821617022d144dca2745ccd56131bac%2Fpreview%2Fc01dd5d15a884c64bfaa43d41e37c3ea%3Fsize%3Dl&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/52d5bcfa1aa5f02093f22849347558f3/href">https://medium.com/media/52d5bcfa1aa5f02093f22849347558f3/href</a></iframe><p>Check out how ‘lat’,’ lon’ obtained as columns in pandas dataframe that we got using ‘get_new_df’ function are gone and we have ‘geometry’ column instead, in the code above.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D47&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D47&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2Ff821617022d144dca2745ccd56131bac%2Fpreview%2Ff8f1ca81b21447b5b71fc8fbc7b27198%3Fsize%3Dl&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a2fff83409527fa7977d4f59d5b963c/href">https://medium.com/media/1a2fff83409527fa7977d4f59d5b963c/href</a></iframe><p>Lets display these points on a Folium map. This map is going to display 50 Pizza places in Massachusetts.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D48&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fyasheejoshi%2Fextracting-data-from-openstreetmap-using-webscarpping%2Fv%2F22%26cellId%3D48&amp;image=https%3A%2F%2Fjovian.ai%2Fapi%2Fgist%2Ff821617022d144dca2745ccd56131bac%2Fpreview%2Ff8f1ca81b21447b5b71fc8fbc7b27198%3Fsize%3Dl&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ba1a2815ed0434911d35638a88f5e08/href">https://medium.com/media/2ba1a2815ed0434911d35638a88f5e08/href</a></iframe><p><strong><em>Future Scope and Conclusion:</em></strong></p><p>This project was an attempt to web-scrape OSM site to get some understanding on the data being offered. This knowledge comes in handy while understanding and forming query for using the API. In two instances through the projects, we came across using data that is being dynamically loaded, this is something <em>Requests</em> library can not help us with. Hence the best option to extract dynamically loaded values was through using <em>Selenium</em>. In future, we can take it up a notch and try to extract data from next pages also. For now, in this project, only data dynamically loaded from the very first page is considered. More work can be done in this area. The overall experience of using web-scrapping technique for OSM maps was very empowering. With the help of the API, searching for the right data with appropriate tags is possible. Since this project was based on spatial data, using some extra libraries like <em>Folium</em> and <em>Geopandas</em> came in handy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d14ad8f19b09" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>