<?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 Lokesh Kumar Gupta on Medium]]></title>
        <description><![CDATA[Stories by Lokesh Kumar Gupta on Medium]]></description>
        <link>https://medium.com/@lokeshgupta1212?source=rss-36166eb99f7e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vG36PgIxqO1ndKfVD5om7Q.jpeg</url>
            <title>Stories by Lokesh Kumar Gupta on Medium</title>
            <link>https://medium.com/@lokeshgupta1212?source=rss-36166eb99f7e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 07:08:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lokeshgupta1212/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[Dstl Satellite Imagery Feature Detection]]></title>
            <link>https://medium.com/thecyphy/dstl-satellite-imagery-feature-detection-f186048de52e?source=rss-36166eb99f7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f186048de52e</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[satellite-imagery]]></category>
            <category><![CDATA[image-segmentation]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Lokesh Kumar Gupta]]></dc:creator>
            <pubDate>Fri, 11 Dec 2020 09:41:58 GMT</pubDate>
            <atom:updated>2020-12-11T10:00:30.227Z</atom:updated>
            <content:encoded><![CDATA[<h4>Can you train an eye in the sky?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FRcxwHn1pbwRxC3d.jpg" /></figure><blockquote>“If We Want Machines to Think, We Need to Teach Them to See”<em> </em>— <strong>Fei-Fei Li</strong></blockquote><p>Throughout this article, I will discuss an image segmentation problem such as in Dstl Satellite Imagery Feature Detection and how can it be solved using deep learning.</p><p><strong>The topics that will be discussed in this tutorial are:</strong></p><ol><li>Business Problem.</li><li>Source of data.</li><li>Deep Learning Problem Formulation.</li><li>Data preprocessing.</li><li>Exploratory Data Analysis and observation.</li><li>The existing approach to the problem.</li><li>My first cut approach to solving the problem.</li><li>Models explanation.</li><li>Error analysis.</li><li>Comparison of the models in tabular format.</li><li>Deployment.</li><li>Future work.</li><li>References.</li></ol><h3>1. Business problem:</h3><p><strong>1.1 Overview:</strong></p><p>The significant increase of satellite imagery has given a radically improved understanding of our planet. It has enabled us to better achieve everything from mobilizing resources during disasters to monitoring the effects of global warming. Due to the recent advancements in computer vision and deep learning, along with important improvements in low-cost high-performance GPUs, the Object recognition in aerial imagery enjoys growing interest nowadays.</p><p>The possibility of accurately identifying different kinds of objects in aerial pictures, like buildings, roads, vegetation, and different classes, might greatly facilitate in several applications, such as creating and keeping up-to-date maps, environment monitoring, disaster relief, and improving urban planning. This domain also offers scientific challenges to the computer vision.</p><p>These types of complex and large datasets are increasing exponentially in number, so the <a href="https://www.gov.uk/government/organisations/defence-science-and-technology-laboratory">Defence Science and Technology Laboratory (Dstl)</a> is seeking novel solutions to reduce the burden on their image analysts. In this problem, we have to accurately classify features in overhead imagery. Automating feature labeling will help in smart decisions more quickly around the defense and security but also bring innovation to computer vision methodologies applied to satellite imagery.</p><p><strong>1.2 Objective :</strong></p><p>In this problem, Dstl provides 1km x 1km satellite images in both 3-band and 16-band formats. The objective is to detect and classify the types of objects found in these regions.</p><p>In other words semantic segmentation of different classes in satellite imagery.</p><p><strong>1.3 Constraints:</strong></p><ul><li>Maximum Jaccard Index.</li><li>Doesn’t need so much interpretability.</li><li>low latency concerns.</li></ul><h3>2. Source of Data:</h3><p>The DSTL posted the above problem on the Kaggle platform. Here is a link below to download the datasets.</p><p>Link: <a href="https://www.kaggle.com/c/dstl-satellite-imagery-feature-detection/data">Dstl Satellite Imagery Feature Detection</a>.</p><p><strong>2.1 Data overview:</strong></p><p>We have been provided with the following CSV files:</p><ol><li><em>train_wkt.csv</em> — The WKT format of all the training labels. It consists:</li></ol><ul><li>ImageId — ID of the image.</li><li>ClassType — Type of objects (1–10).</li><li>MultipolygonWKT — The labeled area, which is multipolygon geometry represented in WKT format.</li></ul><p><em>2. three_band.zip</em> — The complete dataset of 3-band satellite images.</p><p><em>3. sixteen_band.zip</em> — The complete dataset of 16-band satellite images.</p><p><em>4. grid_sizes.csv </em>— The sizes of grids for all the images. It consists:</p><ul><li>ImageId — ID of the image.</li><li>Xmax — maximum X coordinate for the image.</li><li>Ymin — minimum Y coordinate for the image.</li></ul><p><em>5. sample_submission.csv</em> — The sample submission file in the correct format. It consists:</p><ul><li>ImageId — ID of the image.</li><li>ClassType — Type of objects (1–10).</li><li>MultipolygonWKT — The labeled area, which is multipolygon geometry represented in WKT format.</li></ul><p><em>6. train_geojson.zip </em>— The geojson format of all the training labels.</p><ul><li>For each image, we are given three versions: grayscale, 3-band, and 16-band. Details are presented in the table below:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*2xTj3dyhcom3TFPLD3yNTA.png" /></figure><ul><li><strong>Object Types</strong><em>:</em> We have to classify objects into one of these classes.</li></ul><ol><li>Buildings — large building, residential, non-residential, fuel storage facility, fortified building.</li><li>Misc — Manmade structures.</li><li>Road.</li><li>Track — poor/dirt/cart track, footpath/trail.</li><li>Trees — woodland, hedgerows, groups of trees, standalone trees.</li><li>Crops — contour ploughing/cropland, grain (wheat) crops, row (potatoes, turnips) crops.</li><li>Waterway.</li><li>Standing water.</li><li>Vehicle Large — large vehicle (e.g. lorry, truck, bus), logistics vehicle.</li><li>Vehicle Small — small vehicle (car, van), motorbike.</li></ol><h3>3. Deep Learning Problem Formulation:</h3><ul><li>The above problem is an image segmentation problem, where input is an image and output is also an image and can be solved using Deep Learning techniques to detect and classify the types of objects found in a particular region.</li><li>The Convolutional Neural Networks (CNN) is the main supervised approach that can be used for this task. <a href="https://lmb.informatik.uni-freiburg.de/people/ronneber/u-net/">U-Net</a> is specially designed to effectively solve image segmentation problems. The most successful state-of-the-art deep learning method the Fully Convolutional Network (FCN) can be used for this task.</li></ul><p><strong>3.1 Performance Metric:</strong></p><p>The performance metric is chosen for this problem which is<strong> </strong>the<strong> </strong>Average Jaccard Index. This is a vector-based metric where we use polygon geometries to evaluate how well your predictions are aligned with the answer.</p><p>The <a href="https://en.wikipedia.org/wiki/Jaccard_index">Jaccard Index</a> for two regions A and B, also known as the “intersection over union”, is defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/0*RBVX4RXmunZAuj8w" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/202/0*EpfhvxptQ_n2Y8dE" /></figure><p>where TP is the true positives area, FP is the false positives area, and FN is the false negatives area.</p><h3>4. Data preprocessing:</h3><ul><li>First, combine all train images into a large X array and their masks into a large Y array and saved them into the disk.</li><li>The masks for each image is calculated and shown in below code snippets.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1204b6f43dc9c9beadc0352a235b7a48/href">https://medium.com/media/1204b6f43dc9c9beadc0352a235b7a48/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77a04fdd579bf1030bf6bc9d4dedf8c6/href">https://medium.com/media/77a04fdd579bf1030bf6bc9d4dedf8c6/href</a></iframe><ul><li>We used only train images and produced more images using augmentation. We did random crops of size 160*160 for both images and masks. we split the train images into train data, validation data, and test data.</li><li>We took nearly 8K train images and their masks(6K from augmentation and 2k from non-augmentation), 1.6K validation images and their masks(1.2K from augmentation and 0.4K from non-augmentation), and 1.6K test images and their masks(1.2K from augmentation and 0.4K from non-augmentation).</li><li>Below is the code snippet for random crops.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/986af29736a61eec67652e3340aaed6d/href">https://medium.com/media/986af29736a61eec67652e3340aaed6d/href</a></iframe><h3>5. Exploratory Data Analysis and its observation:</h3><p>To solve the problem through machine learning, first, we have to understand the data which is an important approach is known as Exploratory data analysis. This provides insights into data and the advanced exploration of the data in different visualizations.</p><p><strong>5.1 Reading the data</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7a04c9c27613024994af0869f957efc/href">https://medium.com/media/e7a04c9c27613024994af0869f957efc/href</a></iframe><p><strong>5.2 Basic information about data</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/95ae4fd8aaa73e3b684ac94255078c0d/href">https://medium.com/media/95ae4fd8aaa73e3b684ac94255078c0d/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*fLNZDlRbVIpBF8Q-g-9NIA.png" /></figure><p><strong>Observations:</strong></p><ol><li>There are 25 unique images in the training data.</li><li>Trees are present in mostly all the given images.</li><li>Man-made structures and buildings are present in half of the images.</li><li>The waterway is present only in one image.</li></ol><p><strong>5.3 Areas of the objects in training images</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23797ff5bc2ad88d3edd88ae2dc0e189/href">https://medium.com/media/23797ff5bc2ad88d3edd88ae2dc0e189/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d7a5768cb18a7661e36713982a25d25/href">https://medium.com/media/0d7a5768cb18a7661e36713982a25d25/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*iSUzEct1K4Cp8oReX8yK9w.png" /></figure><p><strong>Observations:</strong></p><ol><li>There are 25 unique images in the training data.</li><li>Crops occupied the largest area in an image.</li><li>After crop class trees and tracks classes occupied a large area respectively.</li><li>Buildings are present in 11 of the 25 training images.</li><li>Water and vehicle classes are present in very less quantities.</li></ol><p><strong>5.4 Plotting train images</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d0f84de617a823aa88b09efb68b0307/href">https://medium.com/media/2d0f84de617a823aa88b09efb68b0307/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/290/1*Yj3w4aFydV0hjsB-z57dzw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*h02VapCKMpz605ytLTDnPg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/285/1*Ac8V7VAzzEavvZgYRSC7Pg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/290/1*DkBihg0vnNU2rr0xMHsL1g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*Eaqoy6lJjOXTGfQmWeg5iA.png" /></figure><p><strong>5.5 Plotting images from wkt multipolygon objects</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bdc6dd51d6be24f06274a63ec8fb25d9/href">https://medium.com/media/bdc6dd51d6be24f06274a63ec8fb25d9/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/1*-nw456RfzkJUMzaRMP7Ozw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/1*lbT_qx7Lp6DeVrqKIUc5ig.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/1*29srvmHP17DkfYoeFLk1pA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/1*hHQYy9BhrVLVke_KnD5zDg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/1*pfz3OVuXES3qGXbPnO287g.png" /></figure><p><strong>5.6 Display an image and its masks</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef47ec626d1fd19c917e9d401b817320/href">https://medium.com/media/ef47ec626d1fd19c917e9d401b817320/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*8NieUMKDEFVXgKrnksWF9A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*C1mFss2OPHtXUAgESvQANA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*xbtoHvMcRlbYIQ1X_kRxZQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*HcjSx973Wabp4UF5Ma2XWw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*SvSn42YveW2ke2EvjsT7cw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*mUvf1IObl5ZEHX7FH3Gmiw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*rnFPnJcel2L8eG6QNqCDEw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*f1e2HR6WfXeoje43PFEiTQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*jbatVwNEri0Dxof3tC6KUg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*5BP78SxThuJYPcZ4j5UKwA.png" /></figure><p><strong>Observations</strong>:</p><ol><li>Training labels are in wkt format(Multipolygons) and defines different objects in the training images.</li><li>Training set images belong to different places and also very different in context.</li><li>Some classes are very rare such as water bodies and vehicle classes.</li><li>Objects in the images are not in equal proportions.</li></ol><h3>6. Existing approach of the problem</h3><p><strong>Solution 1:</strong></p><p><a href="https://www.kaggle.com/alijs1/squeezed-this-in-successful-kernel-run">https://www.kaggle.com/alijs1/squeezed-this-in-successful-kernel</a></p><p>The above link applied a modified U-Net — an artificial neural network for image segmentation. They first preprocess the data i.e made masks for given images and used only 16 band M channels images.</p><p>After preprocessing they passed images and masks into modified U-Net model and trained the model. And then did prediction by model. In post-processing, convert predicted masks to WKT format.</p><p>By this model implementation, the final result they got is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*0JJXz2SqZLhxH_NxBCmJ-Q.png" /></figure><p><strong>Solution 2:</strong></p><p><a href="https://deepsense.ai/deep-learning-for-satellite-imagery-via-image-segmentation/">https://deepsense.ai/deep-learning-for-satellite-imagery-via-image-segmentation</a></p><p>The above link team secured 4th place in this Kaggle competition. They applied a modified U-Net — an artificial neural network for image segmentation. They solved the problem in the following steps:</p><ol><li>Preprocessing</li></ol><p>For each image in the data, three versions: grayscale, 3-band, and 16-band are given. They resized and aligned 16-band channels to match those from 3-band channels. The alignment was necessary to remove shifts between channels. Finally, all channels were concatenated into a single 20-channels input image.</p><p>2. Modeling</p><p>Their fully convolutional model is inspired by the family of U-Net architectures, where low-level feature maps are combined with higher-level ones, which enables precise localization. Our final architecture is depicted below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/0*JvHxYExeTb7xCk4P" /></figure><p>3. Post-processing</p><p>Actual truth labels are provided in <a href="https://en.wikipedia.org/wiki/Well-known_text">WKT format</a>, presenting objects as polygons (defined by their vertices). In the post-processing stage, they used morphology dilation/erosion and simply removed objects/holes smaller than a given threshold.</p><p>By this approach implementation, the average IOU was 0.46.</p><h3>7. My First Cut Approach to the above problem:</h3><ol><li>The first way to know about the data is to do some preprocessing techniques such as read WKT format, project geometry to pixel coordinates, and open GeoTiff files.</li><li>Then performed Exploratory Data Analysis to understand the data and to get insights of the dataset. This will help me to get a better score.</li><li>The masks(labels) are generated for each of the objects in the train images.</li><li>After that, I used only train images, and using augmentation produced more train images and split the train images into the train data, validation data, and test data.</li></ol><p>5. Model implementation:</p><ul><li>This problem is an image segmentation problem where input is an image and output is also an image and can be solved using Deep Learning techniques to detect and classify the types of objects found in a particular region.</li><li>The Convolutional Neural Networks (CNN) is the main supervised approach that can be used for this task. <a href="https://lmb.informatik.uni-freiburg.de/people/ronneber/u-net/">U-Net</a> is especially designed to effectively solve image segmentation problems. The U-Net architecture will be modified to get a good score.</li><li>Relu activation function and He normal weight initializer will be used. Batch normalization and dropout will be used to prevent overfitting.</li><li>Transfer learning can be used to initialize weights of the U-Net model and the most successful state-of-the-art deep learning method the Fully Convolutional Network (FCN) can be used for this task.</li></ul><p>6. Post-Preprocessing:</p><p>Ground truth labels are provided in <a href="https://en.wikipedia.org/wiki/Well-known_text">WKT format</a>, presenting objects as polygons (defined by their vertices). First, converted predicted masks into polygons and then polygons into wkt.</p><h3>8. Models Explanation</h3><p>Here we used two models:</p><ol><li>U-Net.</li><li>Seg-Net.</li></ol><p><strong>U-Net:</strong></p><ul><li>The U-Net architecture is built upon the Fully Convolutional Network and modified in a way that it yields better segmentation in medical imaging. The U-Net owes its name to its symmetric shape, which is different from other FCN variants. Compared to FCN-8, the two main differences are (1) U-net is symmetric and (2) the skip connections between the downsampling path and the upsampling path apply a concatenation operator instead of a sum. These skip connections intend to provide local information to the global information while upsampling.</li><li>Because of its symmetry, the network has a large number of feature maps in the upsampling path, which allows to transfer information. By comparison, the basic FCN architecture only had <em>number of classes</em> feature maps in its upsampling path.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*WpwCJqmQ9L_Z7nSx.jpg" /></figure><ul><li>We modified U-Net according to our problem and below is the code snippet which explains all things.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ee64a618bfe45c81d149191437c361c/href">https://medium.com/media/5ee64a618bfe45c81d149191437c361c/href</a></iframe><ul><li>Using the U-Net model the Jaccard score we got for test data is <strong>0.3752.</strong></li></ul><p><strong>Seg-Net:</strong></p><p>SegNet is applied to solve the image segmentation problem. It consists of sequence of processing layers (encoders) followed by a corresponding set of decoders for a pixelwise classification. Below image summarizes the working of SegNet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*dSXL2oGkmzfGYXwH.png" /></figure><p>One key feature of SegNet is that it retains high frequency details in the segmented image as the pooling indices of encoder network is connected to pooling indices of decoder networks. In short, the information transfer is direct instead of convolving them.</p><ul><li>We modified Seg-Net according to our problem and below is the code snippet which explains all things.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf2f801d2d57e6795948feeef5cbd14e/href">https://medium.com/media/bf2f801d2d57e6795948feeef5cbd14e/href</a></iframe><ul><li>Using the Seg-Net model the Jaccard score we got for test data is <strong>0.4463.</strong></li></ul><p><strong>Performance characteristic graphs of SegNet Model through Tensor board:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*uvRU8WPpqSGGX6PGmRSyjQ.png" /><figcaption><strong>Model performance</strong></figcaption></figure><p><strong>Observations:</strong></p><blockquote><em>From the above plot the train jaccard score(orange curve) and validate jaccard score(blue curve) both smoothly increases as when epoch increases.</em></blockquote><blockquote><em>Thus by the graph train jaccard score obtained as 0.42 and validate jaccard score obtained as 0.35. And the model is little bit underfit.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*jokbopt4JFva-vdROjBoxg.png" /><figcaption><strong>Model performance</strong></figcaption></figure><p><strong>Observations:</strong></p><blockquote><em>From the above plot the train loss(orange curve) and validate loss(blue curve) both are smoothly decreases as when epoch increases.</em></blockquote><blockquote><em>Thus by the graph train loss obtained as 0.1269 and validate loss obtained as 0.0881.</em></blockquote><h3>9. Comparison of the models in tabular format and results</h3><ul><li>Comparison of models is as follows:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*Tb7FTVh5LT37wxhetgNITw.png" /></figure><ul><li>From the above table, we can conclude that Seg-Net is the best model.</li></ul><p><strong>Results:</strong></p><p>The output masks of an image by Seg-Net model are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*Zwa-WaHXmzikZdT6gInH1A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*I4vnD281Jdram0QzuvziSg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*qHuc-FZHrrKgSmjfUvG27w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*ZenxPEQSLz9Cacb2XNF8bw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*HYI2dbrH45yATQXUhHf_qg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*SHY9AWhKeyXUoMUzgdnnaA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*iFgD0f6d0nS6wIIFTPAP4Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*yZb4Cdgwtro8NXmDqo9RgQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*39N99rXl8XUA-LSnrLKipA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*52uYsVQotfRNJ8T0Fxe1cw.png" /></figure><h3><strong>10. Error analysis:</strong></h3><p>The main idea behind error analysis is to know what type of data is leading to a bad Jaccard Score and whether we have similar patterns in the data.</p><p>We did this based on the Jaccard Score of each data point. We divided Jaccard Score into very low Jaccard Score, medium Jaccard Score, and very high Jaccard Score. Then took the very low Jaccard Score data points and did the EDA to get the patterns.</p><ul><li>Below is the code to explain all these things.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ebfb510e69c73d78cac072c9c681ee4/href">https://medium.com/media/2ebfb510e69c73d78cac072c9c681ee4/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c66abf5a923fe0237d89570f9f8fa20/href">https://medium.com/media/6c66abf5a923fe0237d89570f9f8fa20/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*wccMXIe8DLRb7KnpvEZnLQ.png" /></figure><p><strong>Observations:</strong></p><ol><li>Classes 2, 3, 4, 6, 7, 8, and 9 are totally absent.</li><li>Only a few images have class 10.</li><li>Class 4 is almost present in all images.</li></ol><ul><li><strong>EDA on pixels:</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97c290f660a3ea8d1f3a4d327819b686/href">https://medium.com/media/97c290f660a3ea8d1f3a4d327819b686/href</a></iframe><p><strong>Observations:</strong></p><ol><li>The percentage of values less than threshold 0.4 is 57.066874999999996.</li><li>More values less than taken threshold value implies that image brightness is not so good.</li></ol><h3><strong>11. Deployment</strong></h3><p>We deployed the Seg-Net model and code snippets for deployment are given below:</p><p>The code snippet for the main app.py is</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40b9c0fd168ce12812f3e963c2f07340/href">https://medium.com/media/40b9c0fd168ce12812f3e963c2f07340/href</a></iframe><p>The code snippet for the index html page is</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e684e1c91e064ead0871ff83f9988bf2/href">https://medium.com/media/e684e1c91e064ead0871ff83f9988bf2/href</a></iframe><p>Now here is the recording of the inference time.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F7KCC5A_JeJc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D7KCC5A_JeJc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F7KCC5A_JeJc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/48588b1ae22fa1ce8cbc6c28786a9ca2/href">https://medium.com/media/48588b1ae22fa1ce8cbc6c28786a9ca2/href</a></iframe><h3>12. Future Work</h3><ol><li>In the future, if we train with more satellite images we can expect better results than the above results with a good score.</li><li>As the class number of vehicles is present in a very small quantity, so to combat this separate models can be trained for large and small vehicles.</li><li>Multi-Scale Attention for Semantic Segmentation can be used to improve the results.</li></ol><h3>13. References:</h3><ol><li><a href="https://www.jeremyjordan.me/semantic-segmentation/#:~:text=Because%20our%20target%20mask%20is,activated%22%20in%20the%20target%20mask.&amp;text=This%20loss%20fu">https://www.jeremyjordan.me/semantic</a></li><li><a href="https://www.kaggle.com/randel/25-images-and-polygons-side-by-side-eda">https://www.kaggle.com/randel/25-images-and-polygons-side-by-side</a></li><li><a href="https://www.kaggle.com/drn01z3/end-to-end-baseline-with-u-net-keras">https://www.kaggle.com/drn01z3/end-to-end-baseline-with-u-ne</a>t</li><li><a href="https://deepsense.ai/deep-learning-for-satellite-imagery-via-image-segmentation/">https://deepsense.ai/deep-learning-for-satellite-imagery-via-image</a></li><li><a href="https://towardsdatascience.com/dstl-satellite-imagery-contest-on-kaggle-2f3ef7b8ac40">https://towardsdatascience.com/dstl-satellite-imagery-contest-on-kaggle</a></li><li><a href="https://www.appliedaicourse.com/">https://www.appliedaicourse.com</a></li></ol><h3>Github Repo</h3><ul><li>If you are interested in this case study or wants to improve it further, then Jupyter Notebook is available with all code at my following repo:-</li></ul><p><a href="https://github.com/gupta-lokesh/Dstl-Satellite-Imagery-Feature-Detection">gupta-lokesh/Dstl-Satellite-Imagery-Feature-Detection</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f186048de52e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thecyphy/dstl-satellite-imagery-feature-detection-f186048de52e">Dstl Satellite Imagery Feature Detection</a> was originally published in <a href="https://medium.com/thecyphy">TheCyPhy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[M5-Forecasting-Accuracy]]></title>
            <link>https://medium.com/thecyphy/m5-forecasting-accuracy-af6c45fb7d58?source=rss-36166eb99f7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/af6c45fb7d58</guid>
            <category><![CDATA[time-series-forecasting]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[kaggle-competition]]></category>
            <dc:creator><![CDATA[Lokesh Kumar Gupta]]></dc:creator>
            <pubDate>Mon, 28 Sep 2020 18:17:11 GMT</pubDate>
            <atom:updated>2020-12-08T08:05:27.578Z</atom:updated>
            <content:encoded><![CDATA[<p>Estimate the unit sales of Walmart retail goods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*A6U9Z3LpMFBpPOXYBt7hOg.jpeg" /></figure><p><strong>Table of content:</strong></p><ol><li>Business Problem.</li><li>Source of data.</li><li>How the problem is solved through Machine Learning.</li><li>Exploratory Data Analysis and it’s observation.</li><li>Existing approach of the problem.</li><li>My first cut approach to solve the problem.</li><li>Models explanation.</li><li>Comparison of the models in tabular format.</li><li>Kaggle submission.</li><li>Final pipeline of the problem.</li><li>Future work.</li><li>References.</li></ol><h3>1. Business problem:</h3><p><strong>1.1 Overview:</strong></p><p>In today’s ultra-competitive business landscape, everyone wants to increase their revenue. We as a whole heard about strategic planning when to hire new people, but do you really know when exactly you need to expand your team, start your next promotional campaign or launch your new item? For all these things revenue forecasting is done.</p><blockquote>So are we predicting future? yes!! but not not so accurately. It is done using Machine learning.</blockquote><p>The Makridakis Open Forecasting Center (MOFC) at the University of Nicosia conducts cutting-edge forecasting research and provides business forecast training. It helps companies achieve accurate predictions, estimate the levels of uncertainty, avoiding costly mistakes, and apply best forecasting practices.</p><p>The MOFC is well known for its Makridakis Competitions and In this problem, the fifth iteration(M5 forecasting) the hierarchical sales data from Walmart, the world’s largest company by revenue is given, to forecast daily sales for the next 28 days.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*QB295vWojJ56IIEfTdSKKw.gif" /></figure><p><strong>1.2 Objective :</strong></p><p>The main objective is to<em> estimate or predict the unit sales of Walmart retail goods at stores in various locations for the next 28-days.</em> This estimation certainly helps different companies to increase their revenues.</p><h3>2. Source of Data:</h3><p>The MOFC posted the above problem on the Kaggle platform. The data provided in CSV file format. Here is a link below to download the datasets.</p><p>Link: <a href="https://www.kaggle.com/c/m5-forecasting-accuracy">M5 Forecasting-Accuracy</a></p><p><strong>2.1 Data overview:</strong></p><p>The M5 dataset involves the unit sales of various products sold in the USA, organized in the form of grouped time series.</p><p>The overview of how the M5 series are organized is shown in the below figure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*Jv5yyc-m-f0cKlLHCtcAlQ.png" /><figcaption><strong>An overview of how the M5 series is organized.</strong></figcaption></figure><p>We have been provided with the following CSV files:</p><ol><li><em>calendar.csv: Contains information about the dates on which the products are sold.</em></li><li><em>sales_train_validation.csv: Contains the historical daily unit sales data per product and store.</em></li><li><em>sell_prices.csv: Contains information about the price of the products sold per store and date.</em></li><li><em>sample_submission.csv: The correct format for submissions.</em></li><li><em>sales_train_evaluation.csv: Includes sales [ d_1 — d_1941] .</em></li></ol><h3>3. How the problem is solved through Machine Learning:</h3><p>The above problem is a time-series data problem and can be solved using Classical Machine Learning techniques to estimate the unit sales to a particular day by using historical sales data.</p><p>● The given time series data can be re-framed as a supervised learning dataset by using Feature Engineering techniques and then can apply machine learning algorithms on it.</p><p>● It can be solved using a Machine Learning Regression model as input variables are generated features and items sold on a particular date as output variable which belongs to a real number.</p><p><strong>3.1 Performance Metrics:</strong></p><p>The custom performance metric is chosen for this problem which is Root Mean Squared Scaled Error (RMSSE). It is a variant of the well-known Mean Absolute Scaled Error (MASE). The measure is calculated for each series as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/302/1*6hipYwjdiVvW_pQ9ygWXbA.png" /></figure><p>where Yₜ is the actual future value of the examined time series at point t, Ŷₜ the generated forecast, n the length of the training sample (number of historical observations), and h the forecasting horizon.</p><p>After estimating the RMSSE for all 42,840-time series, then Weighted RMSSE (WRMSSE) will be calculated as described later in <a href="https://mofc.unic.ac.cy/m5-competition/">The M5 Competition MOFC,</a> using the following formula:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/216/1*5Rr8dxja8fN0RjFPMaKy5Q.png" /></figure><p>where wᵢ is the weight of the ith series. A lower WRMSSE score is better.</p><h3>4. Exploratory Data Analysis and it’s observation:</h3><p>To solve the problem through machine learning, first, we have to understand about the data which is an important approach is known as Exploratory data analysis. This provides insights into data and the advanced exploration of the data in different visualizations which helps in feature engineering to create appropriate features.</p><p><strong>4.1 Reading the data</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4386b3aa8f31914e656b86400f77be0b/href">https://medium.com/media/4386b3aa8f31914e656b86400f77be0b/href</a></iframe><p><strong>4.1.2 Basic information about data</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f50d1dedccb50586db7b6ad43dc0744d/href">https://medium.com/media/f50d1dedccb50586db7b6ad43dc0744d/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*5KeGni93ONaCL085x9T2wA.png" /></figure><p><strong>Observations:</strong></p><ol><li>In the data, there are 3 states, 10 stores, 3 categories, 7 departments, and 3049 items.</li><li>a. States are CA, TX, and WI.<br>b. Stores are CA_1, CA_2, CA_3, CA_4(CA), TX_1,TX_2, TX_3(TX) and W1_1, WI_2, WI_3(WI).<br>c. Categories are FOODS, HOUSEHOLD, and HOBBIES.<br>d. Departments are FOODS_1, FOODS_2, FOODS_3(FOODS), HOUSEHOLD_1, HOUSEHOLD_2(HOUSEHOLD) AND HOBBIES_1, HOBBIES_2(HOBBIES).</li></ol><p><strong>4.2 Downcasting the data</strong></p><p>Downcasting means type-casting of the data and to reduce the amount of storage used by them. As pandas automatically create int32, int64, float32, or float64 columns for numeric ones, we can convert them into int8/int16 and float8/float16. Also, Pandas stores categorical columns as objects which take more storage as compare to category datatype, so convert object datatype to category datatype.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*ArpHlzgyTfFSx5j7nH_s9w.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*34Pbni6ryFUfZz1hjjDhGw.png" /></figure><p><strong>Observations:</strong></p><ol><li>The size of all dataframes approximately reduced to one-fourth of the size of the original dataframes.</li><li>It reduced the chances of ‘RAM crashed’ error.</li></ol><p><strong>4.3 EDA of Sales Data</strong></p><p><strong>The first five rows of the sales table</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I2s--kInPwKJ6b42HBlhfA.png" /></figure><p><strong>4.3.1 Mean sales</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2e158bfe2969fe38b1de90e6d6c8a8f/href">https://medium.com/media/c2e158bfe2969fe38b1de90e6d6c8a8f/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*SmdNvDiUhRNw1yjZ51Y3cg.png" /></figure><p><strong>Observations:</strong></p><ol><li>CA stores have the highest mean sales among all the stores and CA_3 has the highest sell among all the stores.</li><li>CA stores have also the highest variance in mean sales among all the stores.</li></ol><p><strong>4.3.2 Rolling Averages sales</strong></p><p>Rolling averages for different window sizes 7, 10, 13, 30, and 90 are taken and their scatter plots and box plots are drawn.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5c8db349729bc7bf037114f9183bd07/href">https://medium.com/media/a5c8db349729bc7bf037114f9183bd07/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*AXqhVBiooEnC8cQDziForA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*ZWIG0pB28qPxEhS7fLe8LA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*BS5D-oHdILM0OfBLxmPB8A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*iSYRYDLJlf3GC7pKOcNXcQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*DU9lFbAlcUtiCdqfEP_n-A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*rpamp5DM60V369IsdJvK1A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*0LgSwb23LSxgahzDEd6Apg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*Y0KHxYJVSdSoFuaL2yfIAg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*NUeX8-ju6dJrAabQr6XbYg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*ORoGQbjkk3GqV9DFMubSHw.png" /></figure><p><strong>Observations:</strong></p><ol><li>Every rolling mean sales curve has a ‘linear oscillation’ trend and also has an upward linear trend.</li><li>CA_3 has the highest sell.</li><li>CA stores have the highest variance in mean sales which may imply that CA has development disparity ie. some places are growing faster than others.</li><li>WI and TX do not have much variance which may imply that development is uniform in these states.</li></ol><p><strong>4.3.3 Rolling Medians sales</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*noyiUTv31Zw1heeDwtlxDw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*jFptxJc1BH2egcut6Zx3cA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*-fhZ9_ifndeBA6ePOfnQgw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*dEL2XPuGyBv_6bECzYKL3Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*LCPW3y3C9jakliE4IuYDxQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*Ln1dm4j3sSiXaYeE-Liu2A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*5H-Dd-3MkuLtt7A-Rdpolw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*FeS7_X8RaabF5JmE_SAxLg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*xCS8JcUjOrWtdIucXnyKpg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*BJ1wkrBVtGhh6c39w9o-pg.png" /></figure><p><strong>Observations:</strong></p><ol><li>Took rolling medians for different window sizes ie. 7, 10, 13, 30, and 90.</li><li>The observations are quite similar to rolling averages.</li></ol><p><strong>4.3.4 Rolling Minimums sales</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*wZ1o9yOdCMOUHmOI6h3T-A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*kzUkVCdEF0tGqr28y47UXg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*I162pUzrfTTh4hRL3w0lTg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*vOXbDg8nc32-3vmBnkWhNA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*PN4D92DczcGTLmTtAjacHQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*s4fWyJO2RJFq07TdfoHvGw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*Lt5U0_JqmgT1LGUGkdkovA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*RfyQIOkgOhN35eqBP1P3FQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*h_WAlpWKSLm_iWs1rZd-Ow.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*HPIJGom7lexl8kDHNTI2FQ.png" /></figure><p><strong>Observations:</strong></p><ol><li>Took rolling minimums for different window sizes ie. 7,10,13,30 and 90.</li><li>The sharp up and down indicates there are days where the unit sales are zero and these days can be holiday days.</li><li>The other observations are quite similar to rolling averages.</li></ol><p><strong>4.3.5 Rolling Maximums sales</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*42PtWDku0p-ngix_Brc7XQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*qWuQIEN8hB703jdgIajQTQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*csyzFC7ssI62in9NC22yig.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*T3o7zZlNvZBvqrHCk_DIQg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*tJ9yVyZtl2NTKOECodLYmg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*tSvaHFE5XtU8G2brTfWLIQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*FJEUOplDOL2dSs929kaPUw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*-p3LX5MI5Os2eGtSh7567w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*ou5PNDB7i8ZDTZQioheS0w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*D0qp2JY7Rea3738GEZMwwQ.png" /></figure><p><strong>Observations:</strong></p><ol><li>Took rolling maximums for different window sizes ie. 7,10,13,30 and 90.</li><li>The observations are quite similar to rolling averages.</li></ol><p><strong>4.3.6 Rolling 25th Percentiles</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*YC9pYTA4JLRPZyA_eMeIVw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*UBN3JUmbD34-g72GGR5YPw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*hMND8C_bXPIFius2MBQc1w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*TgJbQqGIb6KQLo2kNivg8g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*-QsLRbSeMGu7pT4n3lAfpQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*MWnoeYfCqGVeuKxEwmTAQQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*nfNGuJ50-YUyWf4a9fhkww.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*pIaqzNwcB62SYgA8DuQkGA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*EedYmCHreAkn0b9V2w8aOA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*kZT8Z34wNGknqbcKToH3YA.png" /></figure><p><strong>Observations:</strong></p><ol><li>Took rolling 25th Percentiles<strong> </strong>for different window sizes ie. 7,10,13,30 and 90.</li><li>The observations are quite similar to rolling averages.</li></ol><p><strong>4.3.7 Sales on the state(California)</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9c823711807de3743553adc1529b54b/href">https://medium.com/media/c9c823711807de3743553adc1529b54b/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*PYtOWXEPNBi8kzpFCuBQLw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*h1EDWH-q52eiKasXHrT3GA.png" /></figure><p><strong>Observations:</strong></p><ul><li>The average sales in descending order are CA_3, CA_1, CA_2, CA_4.</li><li>CA stores have a large disparity in sales and sales curves never meet. This may show that there are “Hubs” of development that don’t change after some time.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/679c130d8dc7cf52ba291798489d25d7/href">https://medium.com/media/679c130d8dc7cf52ba291798489d25d7/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*g7LAVUuzqGgF7c0xc-5YLw.png" /></figure><p><strong>Observations:</strong></p><ul><li>Store CA_3 has maximum sales.</li><li>Store CA_4 has minimum sales</li></ul><p><strong>4.3.8 Sales on the state(Wisconsin)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*hXq5tqArXydkxidYsp3frQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*W3m614EhjogO2GAjWhLa9Q.png" /></figure><p><strong>Observations:</strong></p><ul><li>The average sales in descending order are WI_2, WI_3, WI_1.</li><li>WI stores have a low disparity in sales and sales curves meet which may show that WI does not have specific ‘hubs’ of development and there is equity in development across the state.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*ZHSs7jyUxrLlLZTjm9-N8A.png" /></figure><p><strong>Observations:</strong></p><ul><li>Store W1_2 has maximum sales</li><li>Store W1_1 has minimum sales.</li></ul><p><strong>4.3.9 Sales on the state(Texas)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*lhs-GKb9JrId6KYBndbieQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*u_Qo-lxFlWIMfKQJeIcfqA.png" /></figure><p><strong>Observations</strong></p><ul><li>The average sales in descending order are TX_2, TX_3, TX_1.</li><li>TX stores have a very low disparity in sales and even though the sales curves meet but not like in WI.</li><li>The variance in TX stores is higher as compare to WI which shows that there might be ‘hubs’ of development, but not as in CA stores.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*Ax3BPigv_QaehIrOl_9Q4A.png" /></figure><p><strong>Observations:</strong></p><ul><li>Store TX_2 has maximum sales</li><li>Store TX_1 has minimum sales.</li></ul><p><strong>4.3.9 Items by category</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*tAQ7T_ddsDvX6tY8q-_-2w.png" /></figure><p><strong>Observations:</strong></p><ul><li>FOODS category has the highest number of items.</li><li>The number of items in descending order are FOODs, HOUSEHOLD, and HOBBIES.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*uo9bne78fmF0CK44qlFYbA.png" /></figure><p><strong>Observations:</strong></p><ul><li>FOODS category items have a maximum number of sales.</li><li>For some days sale is nearly zero ie. longer spikes in sales curves, which may show that there is a holiday or item is unavailable on that day.</li></ul><p><strong>4.3.10 Take a random item that sells a lot</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*jbcSijQJkJlI5D0HP5ZflQ.png" /></figure><p><strong>Observations</strong></p><ul><li>The sales curve is very erratic which implies that there are so many factors that affect the sales on a given day.</li><li>For some days the sales curve is flatline which means the item is unavailable.</li><li>Item is unavailable for many periods of time.</li></ul><p><strong>4.4 EDA of sells price data</strong></p><p><strong>The first five rows of sell price data</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*GFhEo86YTq_H-n_DIg38IA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*ZL1cI-fyxKCv-OGRq-cHDA.png" /></figure><p><strong>Observations:</strong></p><ul><li>Item prices distribution is almost uniform in all stores(CA, WI, and TX).</li><li>Item HOBBIES_1_060 is the most expensive item being sold at Walmarts priced at around 30.53 dollars.</li><li>In CA_2, CA_3, and CA_4 the most expensive item being sold is HOBBIES_1_361 and for CA_1 the Item HOBBIES_1_060 is the most expensive item being sold.</li><li>Item HOUSEHOLD_1_060 is the most expensive item being sold at TX priced at around 29.87 dollars.</li><li>Item HOBBIES_1_225 priced at around 30.51 dollars is the most expensive item being sold at TX_1 and TX_2, while item Item HOBBIES_1_361 priced at around 30.51 is the most expensive item at TX_3.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*_OsB6ZdvUPGwXgshZuS6Sg.png" /></figure><p><strong>Observations:</strong></p><ul><li>Food category items are the cheapest items among Food, Hobbies, and Household items.</li><li>Household and Hobbies items have nearly the same price range.</li></ul><p><strong>4.5 EDA of calendar data</strong></p><p><strong>The first five rows of calendar data</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kVFmt7iD5EfSojijKo2NPg.png" /></figure><p><strong>Observations:</strong></p><ul><li>SNAP follows a different pattern in a different state.</li><li>SNAP is allowed on the first ten days in CA, it follows the pattern 101–011 in TX and follows the pattern 011 in WI.</li><li>There are total 30 unique events that belong to 5 unique types.</li><li>There are total 162 not null values in event_name_1 and 5 not null values in event_name_2 for approx 4.5 years, which results that these events occur every year.</li></ul><h3><strong>5. Existing approach of the problem</strong></h3><p><strong>Solution 1:</strong></p><p><a href="https://www.kaggle.com/anshuls235/time-series-forecasting-eda-fe-modelling/">https://www.kaggle.com/anshuls235/time-series-forecasting-eda-fe-modelling</a></p><ol><li>The sizes of the given data are quite large and take a lot of memory, so first downcasting i.e type casting is done. It reduces the amount of storage used by data.</li><li>Combined all the data into a single data ie. merge sales, price, and calendar data into a single dataframe.</li><li>After combining in a single dataframe, feature engineering is applied and various features are introduced such as label encoding, mean encoding, lags, rolling window means, expanding window means, and trends.</li><li>Adding all these features time-based splitting is done.</li><li>The LGBMRegressor model is applied to the data and hyperparameter tuning to select the best parameter is not shown.</li><li>The above solution learnt different types of feature engineering techniques and how the ensemble model can be applied to this problem that helps to solve this problem more better.</li></ol><p><strong>Solution 2:</strong></p><p><a href="https://www.kaggle.com/qcw171717/other-naive-forecasts-submission-score">https://www.kaggle.com/qcw171717/other-naive-forecasts-submission-score/</a></p><p>The above solution used the naive logic to make forecasts by different following approaches and checked the local WRMSSE score for each approach.</p><ol><li>The <em>all 0’s approach </em>forecasts the next all sales as 0.</li><li>The <em>Average through all history </em>approach takes the average of all historical observations and use them as a forecasted value.</li><li>The <em>Mean of previous 10, 20, 30, 40, 50, 60 days</em> approach, takes there respective mean and use them for forecasting.</li><li>The<em> Same as previous 28 days </em>approach takes forecast values the same as the previous 28 days values.</li><li>The<em> Average of same day for all previous weeks</em> approach takes the forecast value of the same day as the average of same day for all previous weeks.</li></ol><p>The local WRMSSE score for each approach as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*GZZi8MpOgv05CVtu8IVWUg.png" /></figure><p>The Local WRMSSE score for the same previous 28 days approach is best, which will help to get a better score for this problem.</p><p>From the above naive approach, it can be concluded that closer time steps give a better score for this problem as compare to faraway time steps. Also moving averages technique can be applied to this problem.</p><h3>Improvements:</h3><ol><li>In the above solutions, none of them handle missing values. Missing values comes from sell price data. In sell price data price of some items is not given. So we handle them through mean imputation technique.</li><li>Convert data into s single dataframe in such a way none item gets miss from the data.</li><li>After converting data into a single dataframe the rows of the data are quite large, take only relevant data.</li><li>Add rolling medians features instead of rolling means features because mean is sensitive to outlier.</li></ol><p>5. Remove redundant features.</p><h3>6. My First Cut Approach of the above problem:</h3><ol><li>As it is a time-series forecasting problem and can be solved using Machine Learning techniques, so first given data are re-framed as a supervised learning single dataset. The sales dataset is melted ie. convert the wide data format to long data format and merged all the datasets ie. data sales, calendar, and sell prices to a single dataframe on “d_” (day number).</li><li>Handled the missing values as it comes from sell price data, through mean imputation techniques.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d553bfcf32f48e0b4ed466e1a2037aef/href">https://medium.com/media/d553bfcf32f48e0b4ed466e1a2037aef/href</a></iframe><p>3. Feature engineering is applied and various features are introduced such as lags, label encoding, and rolling medians.</p><p>4. Some redundant features are removed such as date and weekday.</p><p>5. As the rows of resultant data are quite large so only took rows which have “d_”(day number) is greater than 1050. It reduced the computation time and gave better results.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de5242fa698b4825e83405be402cf371/href">https://medium.com/media/de5242fa698b4825e83405be402cf371/href</a></iframe><p>6. Time based splitting is done and took generated features as input variables and items sold on a particular date as output variable which belongs to the real number.</p><p>7. We did hyperparameter tuning &amp; trained Simple Moving Averages, ExtraTressRegression, RandomForestRegression &amp; LgbmRegression &amp; LGBMRegressor turned out to be the best.</p><h3><strong>7. Models Explanation</strong></h3><p>Here we used one simple model and three ensemble models.</p><ol><li>Simple Moving Averages.</li><li>Random Forest Regression.</li><li>Extra Trees Regression.</li><li>Lgbm Regression.</li><li><strong>Simple Moving Averages:</strong></li></ol><ul><li>Moving averages is a naive and effective technique in time series forecasting. It can be used for data preparation, feature engineering, and even directly for making predictions.</li><li>On hyperparameter tuning, we found out that window size=28 is the best.</li><li>Simple Moving Averages model training &amp; prediction:-</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57efd9a76f397c7674b65a199749805b/href">https://medium.com/media/57efd9a76f397c7674b65a199749805b/href</a></iframe><ul><li>The local WRMSSE score we got for Simple Moving Averages is <strong>1.06</strong>.</li></ul><p><strong>2. Random Forest Regression:</strong></p><ul><li>The Random Forest model is a bagging technique, which uses bootstrap sampling without replacement of every sample to train and it reduces variance while training and prevents from overfitting.</li><li>On hyperparameter tuning, we found out max_depth=26, n_estimators=31.</li><li>RandomForestRegressor model training &amp; prediction:-</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a3756e4914eac52f5ee7b0f791f0d79/href">https://medium.com/media/5a3756e4914eac52f5ee7b0f791f0d79/href</a></iframe><ul><li>The local WRMSSE score we got for RandomForestRegressor is <strong>0.85.</strong></li></ul><p><strong>3. Extra Trees Regression:</strong></p><p>The Extra Trees algorithm fits each decision tree on the whole training datasets whereas random forest develops each decision tree from a bootstrap sample of the training datasets.</p><ul><li>On hyperparameter tuning, we found out max_depth=20, n_estimators=22.</li><li>ExtraTressRegressor model training &amp; prediction:-</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ffbadcad11797903f4f64c75c01c5750/href">https://medium.com/media/ffbadcad11797903f4f64c75c01c5750/href</a></iframe><ul><li>The local WRMSSE score we got for ExtraTressRegressor is <strong>0.82.</strong></li></ul><p><strong>4. Lgbm Regression.</strong></p><ul><li>Lgbm Regression is a boosting technique to reduce bias while training the model. It has faster training speed and higher efficiency. It replaces continuous values to discrete bins which result in lower memory usage.</li><li>On hyperparameter tuning, we found out learning_rate = 0.071, num_leaves = 12 and min_data_in_leaf = 147.</li><li>LgbmRegression<strong> </strong>model training &amp; prediction:-</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7402c57efe82caddc04d4bdecba31db/href">https://medium.com/media/d7402c57efe82caddc04d4bdecba31db/href</a></iframe><ul><li>The local WRMSSE score we got for ExtraTressRegressor is <strong>0.70.</strong></li></ul><h3><strong>8. Comparison of the models in tabular format</strong></h3><ul><li>Comparison of All models is as follows:-</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*ekVbbBpr7WKxaMb-9FJCWA.png" /></figure><ul><li>From the above table, we can conclude that LgbmRegressor is the best model.</li></ul><h3><strong>9. Kaggle submission</strong></h3><ul><li>Kaggle public &amp; private scores for each model is as follows:-</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*6WCMxddbOAIm41PPYxRpVg.png" /><figcaption>Kaggle Submission</figcaption></figure><ul><li>From Kaggle’s public and private scores also, we can conclude that the best performing model for this problem is LgbmRegressor.</li></ul><p>There are about 5,558 participants in the competition and my score stands at 159 which stands below 3 percentile in the score.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*MIzAZK-0-yzePP2pIXdk9A.png" /><figcaption>Kaggle Leaderboard</figcaption></figure><h3>10. Final pipeline of the problem:</h3><p>FHere we are going to see about model productionization.</p><p>We selected Lgbm model is the best model and in real-time process, a single query data point(raw data) is sent to trained model ie. Lgbm model and forecast the query point in sec.</p><p>It happens in the following way:</p><ol><li>Select the random data point from the sales data of size 1*1947 as query point and the next 28 forecasting days are filled with zero initially and appended to query point.</li><li>The query data point is mungled with other data and convert into machine learning data. After that, it sent for feature engineering and gets the desired features to predict the model.</li><li>Finally, data is sent to trained model for prediction.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23237ed9141bdc958c9c7caa1c672faf/href">https://medium.com/media/23237ed9141bdc958c9c7caa1c672faf/href</a></iframe><p>Input:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*moMM0dL2ITj4k2Oh46eXAg.png" /></figure><p>output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y2zJUd3kXJcdesboODou5w.png" /></figure><h3>11. Future Work</h3><ol><li>Adding more features will result in a good score.</li><li>Implementing Neural Network with defining proper layers and hyper-parameter will result in a good score.</li></ol><h3>12. References:</h3><ol><li><a href="https://medium.com/analytics-vidhya/get-started-with-kaggle-competition-m5-forecasting-2aacd6822b36">https://medium.com/analytics-vidhya/get-started-with-kaggle-competition-m5-forecasting</a></li><li><a href="https://www.kaggle.com/anshuls235/time-series-forecasting-eda-fe-modelling/comments">https://www.kaggle.com/anshuls235/time-series-forecasting-eda-fe-modelling</a></li><li><a href="https://www.kaggle.com/tarunpaparaju/m5-competition-eda-models">https://www.kaggle.com/tarunpaparaju/m5-competition-eda-models/</a></li><li><a href="https://machinelearningmastery.com/moving-average-smoothing-for-time-series-forecasting-python/#:~:text=Moving%20averages%20are%20a%20simple,in%20the%20original%20time%20series">https://machinelearningmastery.com/moving-average-smoothing-for-time-series-forecasting</a></li><li><a href="https://www.kaggle.com/qcw171717/naive-baseline/">https://www.kaggle.com/qcw171717/naive-baseline</a></li><li><a href="https://www.appliedaicourse.com/">https://www.appliedaicourse.com</a></li></ol><h3>Github Repo</h3><ul><li>If you are interested in this case study or wants to improve it further, then Jupyter Notebook is available with all code at my following repo:-</li></ul><p><a href="https://github.com/gupta-lokesh/M5-Forecasting-Accuracy">gupta-lokesh/M5-Forecasting-Accuracy</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af6c45fb7d58" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thecyphy/m5-forecasting-accuracy-af6c45fb7d58">M5-Forecasting-Accuracy</a> was originally published in <a href="https://medium.com/thecyphy">TheCyPhy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>