<?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 Anirudh on Medium]]></title>
        <description><![CDATA[Stories by Anirudh on Medium]]></description>
        <link>https://medium.com/@anirudhsr97?source=rss-7e5d1208416b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*b7WTkbmCbUJKWuR4.jpg</url>
            <title>Stories by Anirudh on Medium</title>
            <link>https://medium.com/@anirudhsr97?source=rss-7e5d1208416b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 08:34:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anirudhsr97/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[German Traffic Signs Detection using Yolov3]]></title>
            <link>https://medium.com/@anirudhsr97/german-traffic-signs-detection-using-yolov3-ab7b974fca4e?source=rss-7e5d1208416b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab7b974fca4e</guid>
            <dc:creator><![CDATA[Anirudh]]></dc:creator>
            <pubDate>Sun, 05 Jul 2020 17:32:43 GMT</pubDate>
            <atom:updated>2020-07-09T04:15:11.509Z</atom:updated>
            <content:encoded><![CDATA[<h3>Business Problem</h3><p>The German Traffic Sign Detection Benchmark is an object detection problem where the task at hand is to detect traffic signs.Traffic sign detection is still a challenging real-world problem of high industrial relevance.Participating algorithms need to pinpoint the location of given categories of traffic signs (prohibitory, mandatory,danger or other)</p><p>The Data-set Information is as follows :</p><p>A single-image detection problem</p><p>● 900 Images (divided in 600 training images and 300 evaluation</p><p>images)</p><h4><strong>Use of Deep Learning</strong></h4><p>The Yolov3 Algorithm uses concepts like Fully Convolutional Networks, Strides and Upsampling from Deep Learning to learn Objects in a given image.The term Fully Convolutional Network simply means the model only uses convolutions throughout right from providing input till getting the output.</p><h4><strong>Why Yolo?</strong></h4><p>Yolo achieves high accuracy while also being able to run in real-time.The Algorithm looks only once at the image in the sense that it requires only one forward propagation pass through the neural networks to make predictions.</p><h4><strong>Dataset Acquisition</strong></h4><p>The Dataset is publicly available in the following link.</p><p><a href="http://benchmark.ini.rub.de/?section=gtsdb&amp;subsection=dataset">German Traffic Sign Benchmarks</a></p><p><strong>Image format</strong></p><ul><li>The images contain zero to six traffic signs. However, even if there is a traffic sign located in the image it may not belong to the competition relevant categories (prohibitive, danger, mandatory).</li><li>Images are stored in <a href="http://en.wikipedia.org/wiki/Netpbm_format">PPM format</a></li><li>The sizes of the traffic signs in the images vary from 16x16 to 128x128</li><li>Traffic signs may appear in every perspective and under every lighting condition</li></ul><p><strong>Annotation format</strong></p><p>Annotations contain the following information:</p><ul><li>Filename: Filename of the image the annotations apply for</li><li>Traffic sign’s region of interest (ROI) in the image</li><li>leftmost image column of the ROI</li><li>upmost image row of the ROI</li><li>rightmost image column of the ROI</li><li>downmost image row of the ROI</li><li>ID providing the traffic sign’s class</li></ul><p><strong>Performance Metric :mAP (Mean Average Precision )</strong></p><p>The computer vision community has converged on the metric mAP to compare the performance of object detection systems.To understand mean average precision, we must spend some meaningful time with the precision-recall curve.</p><p><strong>The Precision Recall Curve</strong></p><p>Precision is a measure of, “w<em>hen your model guesses how often does it guess correctly</em>?” Recall is a measure of “<em>has your model guessed every time that it should have guessed?</em></p><p>Models that involve an element of confidence can tradeoff precision for recall by adjusting the level of confidence they need to make a prediction.In other words, if the model is in a situation where avoiding false positives is more important than avoiding false negatives, it can set its confidence threshold higher to encourage the model to only produce high precision predictions at the expense of lowering its amount of coverage.</p><p>The process of plotting the models precision and recall as a function of the model’s confidence threshold is the precision recall curve. It is downward sloping because as confidence is decreased, more predictions are made (helping recall) and less precise predictions are made (hurting precision).</p><p>As the model is getting less confident, the curve is sloping downwards. If the model has an upward sloping precision and recall curve, the model likely has problems with its confidence estimation.</p><h4>Measuring Correctness via Intersection over Union</h4><p>Object detection systems make predictions in terms of a bounding box and a class label.</p><p>A sketch of object detection by yours truly</p><p>In practice, the bounding boxes predicted in the X1, X2, Y1, Y2 coordinates are sure to be off (even if slightly) from the ground truth label. We know that we should count a bounding box prediction as incorrect if it is the wrong class, but where should we draw the line on bounding box overlap?</p><p>The Intersection over Union (IoU) provides a metric to set this boundary at, measured as the amount of predicted bounding box that overlaps with the ground truth bounding box divided by the total area of both bounding boxes.</p><p>A graphical depiction of the IoU metric by yours truly.</p><p>Picking the right single threshold for the IoU metric seems arbitrary. One researcher might justify a 60 percent overlap, and another is convinced that 75 percent seems more reasonable. <strong>So why not have all of the thresholds considered in a single metric? Enter mAP.</strong></p><p>In order to calculate mAP, we draw a series of precision recall curves with the IoU threshold set at varying levels of difficulty.</p><p>A sketch of mAP precision-recall curves by yours truly.</p><p>In my sketch, red is drawn with the highest requirement for IoU (perhaps 90 percent) and the orange line is drawn with the most lenient requirement for IoU (perhaps 10 percent). The number of lines to draw is typically set by challenge. The COCO challenge, for example, sets ten different IoU thresholds starting at 0.5 and increasing to 0.95 in steps of .05.</p><p>Almost there!</p><p>Finally, we draw these precision-recall curves for the dataset split out by class type.</p><p>A sketch of mAP by object class by yours truly</p><p>The metric calculates the average precision (AP) for each class individually across all of the IoU thresholds. Then the metric averages the mAP for all classes to arrive at the final estimate. 🤯</p><h3><strong>Exploratory Data Analysis</strong></h3><p>First,There are 43 traffic signs in total.Let’s see their names.We have a csv file containing the names of all traffic signs.Pandas Dataframe would help us view the names.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*nBln4xBOU6G1ECcQQQ3dOQ.png" /></figure><p>As information given along with the data-set,the traffic signs which are circular,white ground with red color belong to the <strong>Prohibitory </strong>class.Traffic Signs which are circular and blue ground belong to the <strong>Mandatory</strong> class.The Triangular traffic signs with Red Ground belong to the <strong>Danger</strong> class and the remaining belong to <strong>Other</strong> Class.</p><p>Our Annotations are provided in a file called gt.txt.</p><p>Let’s summarize with a small snippet of code segregating traffic signs according to the above four classes</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f562fb694ddd82b0b0ddaa9cb7dd7186/href">https://medium.com/media/f562fb694ddd82b0b0ddaa9cb7dd7186/href</a></iframe><p>The FinalClassID column in the above image depicts our four final class id’s.</p><h4><strong>Data Preparation</strong></h4><p>Next Step is to create XML files for our annotations.</p><p>For creating XML files we have a package called Element Tree in python.The following snippet of code would help us achieve in creating XML files.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de01f3fced27a4d209c34842bb64fa11/href">https://medium.com/media/de01f3fced27a4d209c34842bb64fa11/href</a></iframe><p><strong>Yolo -Agorithm</strong></p><p>YOLO is a clever convolutional neural network (CNN) for doing object detection in real-time. The algorithm applies a single neural network to the full image, and then divides the image into regions and predicts bounding boxes and probabilities for each region. These bounding boxes are weighted by the predicted probabilities.</p><p>The theory of Yolov3 is nicely explained in the blog below.It’s nice to give it a read than me replicating it.</p><p><a href="https://medium.com/analytics-vidhya/yolo-v3-theory-explained-33100f6d193">YOLO v3 theory explained</a></p><p>Now let’s define some simple terms</p><h4>Anchor Box :</h4><p>Conventionally, one of the biggest challenges in the object detection is to find multiple objects of various shapes within the same neighboorhood. For example, the picture below shows that a person is standing on a boat and hence the two objects are in the close vicinity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G3SyMMNGQ8G7OuYsxl8ZsQ.jpeg" /></figure><p>YOLO uses the idea of “Anchor box” to wisely detect multiple objects, lying in close neighboorhood. YOLO’s Anchor box requires users to predefine two hyperparameters:</p><ul><li>(1) the number of anchor boxs and</li><li>(2) their shapes</li></ul><p>so that multiple objects lying in close neighboorhood can be assigned to different anchor boxes.</p><p>The more anchor boxes, the more objects YOLO can detect in a close neighboorhood with the cost of more parameters in deep learning model.</p><p>Here we will use pre-defined anchors that is dervied using K-Means Clustering on Pascal-VOC Dataset.</p><p><strong>Non-max Suppression</strong></p><p>NMS is used to make sure that in object detection, a particular object is identified only once. Consider a 100X100 image with a 9X9 grid and there is a car that we want to detect. If this car lies in multiple cells of grid, NMS ensures we identify the optimal cell among all candidates where this car belongs.</p><p>The way NMS works is :<br>→ It first discards all those cells where probability of object being present (calculated in final softmax layer) is &lt;= 0.6<br>→ Then it takes the cell with largest probability among candidates for object as a prediction<br>→ Finally we discard any remaining cell with Intersection over union value &gt;= 0.5 with the prediction cell.</p><h4><strong>Yolov3-Darknet Model</strong></h4><p><strong>Feature extractor</strong></p><p>A new 53-layer Darknet-53 is used to replace the Darknet-19 as the feature extractor. Darknet-53 mainly compose of 3 × 3 and 1× 1 filters with skip connections like the residual network in ResNet. Darknet-53 has less BFLOP (billion floating point operations) than ResNet-152, but achieves the same classification accuracy at 2x faster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*g--HTJI517Gng5mHfZT6Yg.png" /></figure><p><strong>Yolov3 Model Architecture</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*8SqQpDoClD9O3Fx_qQhbpg.png" /></figure><p>The Following snippet of code implements the above architecture in tensorflow.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4431d36571d561e5138b526b52d61605/href">https://medium.com/media/4431d36571d561e5138b526b52d61605/href</a></iframe><p><strong>Keras’s Batch Generator</strong></p><p>I will combine all the input and output encoding discussed above and create a Keras’s batch generator. The idea behind using a Keras generator is to get batches of input and corresponding output on the fly during training process, e.g. reading in 100 images, getting corresponding 100 label vectors and then feeding this set to the gpu for training step. I need to use generator as the entire input data (Nimages, height, width, N channel) is pretty large and does not fit in memory.</p><p>During the training,</p><p>simpleBatchGenerator.__getitem__(idx)</p><p>is called at the beginning of every batch calculation to prepare input batch and output batch.</p><h4>Input batch</h4><p>x_batch</p><p>The numpy array of shape (BATCH_SIZE, IMAGE_H, IMAGE_W, N channels).</p><ul><li>x_batch[iframe,:,:,:] contains a iframeth frame of size (IMAGE_H,IMAGE_W).</li></ul><h4>Output batch</h4><p>y_batch</p><p>The numpy array of shape (BATCH_SIZE, GRID_H, GRID_W, BOX, 4 + 1 + N classes). BOX = The number of anchor boxes.</p><ul><li>y_batch[iframe,igrid_h,igrid_w,ianchor,:4] contains (center_x,center_y,center_w,center_h) of ianchorth anchor at grid cell=(igrid_h,igrid_w) if the object exists in this (grid cell, anchor) pair, else they simply contain 0.</li><li>y_batch[iframe,igrid_h,igrid_w,ianchor,4] contains 1 if the object exists in this (grid cell, anchor) pair, else it contains 0.</li><li>y_batch[iframe,igrid_h,igrid_w,ianchor,5 + iclass] contains 1 if the iclassth class object exists in this (grid cell, anchor) pair, else it contains 0.</li></ul><p>b_batch</p><p>The numpy array of shape (BATCH_SIZE, 1, 1, 1, TRUE_BOX_BUFFER, 4).</p><ul><li>b_batch[iframe,1,1,1,ibuffer,:] contains ibufferth object&#39;s (center_x,center_y,center_w,center_h) in iframeth frame.</li><li>If ibuffer &gt; N objects in iframeth frame, then the values are simply 0.</li><li>TRUE_BOX_BUFFER has to be some large number, so that the frame with the biggest number of objects can also record all objects.</li><li>The order of the objects do not matter.</li><li>This is just a hack to easily calculate loss.</li></ul><p>The Following snippet of code achieves the above.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a90627139eb350b96faadc1ffc309144/href">https://medium.com/media/a90627139eb350b96faadc1ffc309144/href</a></iframe><p>Yolov3 Loss</p><p>YOLO predicts multiple bounding boxes per grid cell. To compute the loss for the true positive, we only want one of them to be <strong>responsible</strong> for the object. For this purpose, we select the one with the highest IoU (intersection over union) with the ground truth. This strategy leads to specialization among the bounding box predictions. Each prediction gets better at predicting certain sizes and aspect ratios.</p><p>YOLO uses sum-squared error between the predictions and the ground truth to calculate loss. The loss function composes of:</p><ul><li>the <strong>Classification loss</strong>.</li><li>the L<strong>ocalization/Regression loss</strong> (errors between the predicted boundary box and the ground truth).</li><li>The C<strong>onfidence loss</strong> (the objectness of the box).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ipcAZNtO2O4oZTMsef2uYQ.png" /></figure><p>The loss function starts off by rescaling the predicted output.Note that the predicted y_batch can take any real value as the conv_23 layer has a linear activation.However the predicted rescaled output should be in the following range.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/333/1*H_nUig5y1VdxaY91ngZIWg.png" /></figure><p>Extraction of the ground truth output is simpler than the extraction of the prediction output because the ground truth is already encoded in the correct scales.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*0koeHzbGxlqMMbbYER0SSQ.png" /></figure><h4>Regression Loss</h4><p>The localization loss measures the errors in the predicted boundary box locations and sizes. We only count the box responsible for detecting the object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WZOW8LHmI4iwLW3pb0rSUA.png" /></figure><p>We do not want to weight absolute errors in large boxes and small boxes equally. i.e. a 2-pixel error in a large box is the same for a small box. To partially address this, YOLO predicts the square root of the bounding box width and height instead of the width and height. In addition, to put more emphasis on the boundary box accuracy, we multiply the loss by λ<em>coord.</em></p><p><strong>Confidence loss</strong></p><p>If <em>an object is detected in the box</em>, the confidence loss (measuring the objectness of the box) is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m8crBmAKdKKUpx8f3tUePw.png" /></figure><p>Most boxes do not contain any objects. This causes a class imbalance problem, i.e. we train the model to detect background more frequently than detecting objects. To remedy this, we weight this loss down by a factor λ<em>noobj</em> (default: 0.5).</p><p><strong>Classification loss</strong></p><p>If <em>an object is detected</em>, the classification loss at each cell is the squared error of the class conditional probabilities for each class:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HM3n-dk_aZNxMPI_Hbqxuw.png" /></figure><p>Most classifiers assume output labels are mutually exclusive. It is true if the output are mutually exclusive object classes. Therefore, YOLO applies a softmax function to convert scores into probabilities that sum up to one. YOLOv3 uses multi-label classification. For example, the output labels may be “pedestrian” and “child” which are not non-exclusive. (the sum of output can be greater than 1 now.) <strong>YOLOv3</strong> replaces the <strong>Softmax</strong> function with independent logistic classifiers to calculate the likeliness of the input belongs to a specific label. Instead of using mean square error in calculating the classification loss, YOLOv3 uses binary cross-entropy loss for each label. This also reduces the computation complexity by avoiding the softmax function.</p><p><strong>Bounding box prediction &amp; cost function calculation</strong></p><p>YOLOv3 predicts an objectness score for each bounding box using logistic regression. YOLOv3 changes the way in calculating the cost function. If the bounding box prior (anchor) overlaps a ground truth object more than others, the corresponding objectness score should be 1. For other priors with overlap greater than a predefined threshold (default 0.5), they incur no cost. Each ground truth object is associated with one boundary box prior only. If a bounding box prior is not assigned, it incurs no classification and localization lost, just confidence loss on objectness. We use tx and ty (instead of bx and by) to compute the loss.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HMq5gf1cztd4GTxbcfLYlw.png" /></figure><p><strong>The final loss adds localization, confidence and classification losses together.</strong></p><p><strong>Feature Pyramid Networks (FPN) like Feature Pyramid</strong></p><p>YOLOv3 makes 3 predictions per location. Each prediction composes of a boundary box, a objectness and 80 class scores, i.e. N × N × [3 × (4 + 1 + 80) ] predictions.</p><p>YOLOv3 makes predictions at 3 different scales (similar to the FPN):</p><ol><li>In the last feature map layer.</li><li>Then it goes back 2 layers back and upsamples it by 2. YOLOv3 then takes a feature map with higher resolution and merge it with the upsampled feature map using element-wise addition. YOLOv3 apply convolutional filters on the merged map to make the second set of predictions.</li><li>Repeat 2 again so the resulted feature map layer has good high-level structure (semantic) information and good resolution spatial information on object locations.</li></ol><p>To determine the priors, YOLOv3 applies k-means cluster. Then it pre-select 9 clusters. For COCO, the width and height of the anchors are (10×13),(16×30),(33×23),(30×61),(62×45),(59× 119),(116 × 90),(156 × 198),(373 × 326). These 9 priors are grouped into 3 different groups according to their scale. Each group is assigned to a specific feature map above in detecting objects.</p><p><strong>Training</strong></p><p>The training is done through batches of images using keras image batch generator which has already been discussed.The training code is given below.We need to pass the necessary parameters as well.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b501e7a76de9bf5954b91858317c1e0/href">https://medium.com/media/7b501e7a76de9bf5954b91858317c1e0/href</a></iframe><p><strong>Final Predictions</strong></p><p><strong>Our Model</strong> does a very good job and achieves a mean Average Precision of 0.7994.</p><p><strong>Predicted Images</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VZdcugxT7b7BiQUMoSS13w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dYEgQMIpsE0FLEAMEthfsA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LI18De6KZiFFI9TifKU8DQ.jpeg" /></figure><h3>Additional Work</h3><p><em>Deployment of Model should be done.</em></p><h3>References</h3><ul><li><a href="https://towardsdatascience.com/yolo-v3-object-detection-53fb7d3bfe6b">What’s new in YOLO v3?</a></li><li><a href="https://pylessons.com/YOLOv3-TF2-custrom-images/">Python Lessons</a></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPL_IHmaMAvkVxdDOBRg2CbcJBq9SY7ZUvs%26start%3D0&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DgKreZOUi-O0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FgKreZOUi-O0%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/509e225b6f40d829456e0fcc5e6d754e/href">https://medium.com/media/509e225b6f40d829456e0fcc5e6d754e/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPL_IHmaMAvkVxdDOBRg2CbcJBq9SY7ZUvs%26start%3D0&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DgKreZOUi-O0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FgKreZOUi-O0%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/509e225b6f40d829456e0fcc5e6d754e/href">https://medium.com/media/509e225b6f40d829456e0fcc5e6d754e/href</a></iframe><ul><li><a href="https://machinelearningmastery.com/how-to-perform-object-detection-with-yolov3-in-keras/">How to Perform Object Detection With YOLOv3 in Keras - Machine Learning Mastery</a></li><li><a href="https://mlblr.com/includes/mlai/index.html#yolov2">ML &amp; AI</a></li><li><a href="https://medium.com/@jonathan_hui/map-mean-average-precision-for-object-detection-45c121a31173">mAP (mean Average Precision) for Object Detection</a></li><li><a href="https://github.com/experiencor/keras-yolo3">experiencor/keras-yolo3</a></li><li><a href="https://medium.com/@ODSC/overview-of-the-yolo-object-detection-algorithm-7b52a745d3e0">Overview of the YOLO Object Detection Algorithm</a></li><li><a href="https://mc.ai/what-is-mean-average-precision-map-in-object-detection/">What is Mean Average Precision (mAP) in Object Detection?</a></li></ul><p>The Whole Code for the project can be accessed from the following link</p><p><a href="https://github.com/AnirudhRajhgopalann/German-Traffic-Sign-Detection">AnirudhRajhgopalann/German-Traffic-Sign-Detection</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab7b974fca4e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Don’t Over-fit 2]]></title>
            <link>https://medium.com/@anirudhsr97/dont-over-fit-2-718dc3202e95?source=rss-7e5d1208416b------2</link>
            <guid isPermaLink="false">https://medium.com/p/718dc3202e95</guid>
            <dc:creator><![CDATA[Anirudh]]></dc:creator>
            <pubDate>Fri, 01 May 2020 12:25:08 GMT</pubDate>
            <atom:updated>2020-08-14T09:20:45.437Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>Business Problem</em></h4><p>Don’t Over-fit 2 is an unique Kaggle problem where we are provided with only 250 training samples and 19750 test data samples. The objective of this problem is to not over-fit with the small training data-set and generalize well with our test set.The data-set consists of 300 continuous variables each with mean centered close to zero and standard deviation close to 1.Performance metric used to measure the performance of the model is Receiver Operating Characteristic Curve.</p><h4>Use of Machine Learning/Deep Learning</h4><p>Leveraging the algorithms in Machine Learning and strategies to train a small data-set,this can be posed as a machine learning problem where we can build a model that learns the patterns from our small data-set and generalizes well with our test data.</p><h4>Source of Data</h4><p>Since this is a Kaggle Problem the data-set is publicly available in the Don’t Overfit 2 Forum.</p><p><a href="https://www.kaggle.com/c/dont-overfit-ii">Don&#39;t Overfit! II</a></p><h4>Existing Approaches</h4><p>This is a unique problem as it forces to use Leader Board Probing Strategy.In a nutshell,Leader Board Probing is a technique used to learn patterns in Public LB data so that the model can generalize well.Users who have topped the competition have used this technique.Some have used simple models with rigorous K-Fold Cross Validation and using Regularization.</p><p>Hyperparameter Tuning (Blog: <a href="https://towardsdatascience.com/hyperparameter-tuning-c5619e7e6624)">https://towardsdatascience.com/hyperparameter-tuning-c5619e7e6624)</a> — It used Ridge, Lasso, Elastic, LassoLars (Lasso model fit when Least Angle Regression), Bayesian Ridge regression, Logistic Regression, and SGD classifier were used in Machine Learning models and evaluate mean cross-validated score and their standard deviation. The parameters keep as per the default values. Found that logistic regression and SGD are the two top models better than others. Then they apply a tuning strategy (Both GridSearchCV and RandomSearchCV) in these models only. Best CV score (not Kaggle Score) got using GridSearchCV in Logistic regression model: <strong>0.789</strong></p><h4>My Approach and Improvements</h4><ol><li>An improvement to the existing approach is using Calibrated Classifier on top of existing models.Calibrated Classifier helps to get the actual probabilities for our predicted data points making our model more accurate.This has significantly improved the model performance.</li><li>Use simple feature engineering like sum(), mean(), standard_deviation() as additional features.</li><li>Using Feature Selection Techniques like SFS and then modelling on top of these important features.</li></ol><h4>Exploratory Data Analysis</h4><p>Our data-set consists of 300 continuous random variables labelled from 0–299.A total of 250 samples are present in train data.The independent variable is depicted by the Target column consisting of the class that a particular data point belongs to.</p><p>train.csv- 250 samples of data</p><p>test.csv-19750 samples of data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*f6-k2ziOher_kdKjAb_-uA.png" /></figure><p>We can see that our mean is very close to zero and standard-deviation close to zero and standard deviation close to 1.</p><h4>Class Distribution</h4><p>Now let us check the Distribution of our class labels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*-pfLJ0ivf2nR_zUaigobeQ.png" /></figure><p>Clearly,we can see that we have an imbalanced data-set.We have 160 data points belonging to Class 1 and we have 90 data points belonging to Class 0.</p><p>Now,Let’s do some simple statistical analysis with our data at hand to understand the data well.A simple code snippet could tell us about the mean,standard-deviation and percentiles of all our 300 continuous variables.Let us use the describe() function to check the above.</p><h4>Probability Density Function</h4><p>The Probability Density Function gives the probability of a Random Variable at a particular range of value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*bBmTrIcRqaVpiCimqzzUMw.png" /></figure><p>After running for many iterations,we see most of the random variables follow a Gaussian distribution.</p><h4>PDF with respect to Class Labels</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*Q06wOVmEPPW4FEn7GsNQog.png" /></figure><p>The Classes Overlap Each Other.This makes things harder for our models.</p><h4>Box-Plots</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*kT1OIF5juuJaw7658XyB8Q.png" /></figure><h4>Violin Plots</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*UwcsKxJtTj677flTl-6gPA.png" /></figure><p><strong><em>Final Observations</em></strong></p><p><strong>The training set is an imbalanced data-set consisting of 160 samples belonging to class 1 and 90 samples belonging to class 0.</strong></p><p><strong>From our EDA,we get to see that most of our random variables follow a Gaussian Distribution.</strong></p><h4><strong>Feature Engineering</strong></h4><ul><li>Since All our Random Variables are real valued,we can add Simple <strong>Descriptive Statistics </strong>like <strong>Mean</strong>,<strong>Standard-Deviation</strong> and<strong> Sum</strong> to our Dataset.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d235fabf44011ba7a040a2109ecfa88/href">https://medium.com/media/7d235fabf44011ba7a040a2109ecfa88/href</a></iframe><h4>Class Imbalance</h4><p>We can handle Class Imbalance using <strong>Class Weights</strong> parameter in sklearn. We can use <strong>class_weight=&quot;balanced&quot;</strong>, which is easier to understand: it basically means replicating the smaller class until you have as many samples as in the larger one, but in an implicit way.</p><h3>Modeling</h3><ol><li>KNN</li><li>Logistic Regression</li><li>Gaussian Naive Bayes</li><li>Random Forests</li><li>Xgboost</li><li>SVM</li><li>Stacking Classifiers.</li></ol><p>I used RepeatedStratifiedKFold Strategy,Hyper-Parameter Tuning and Applied Caliberation on the outputs of my models.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/919b0405103a7881b568dfc51e2ebb24/href">https://medium.com/media/919b0405103a7881b568dfc51e2ebb24/href</a></iframe><h4>Models With Normalization and Forward Feature Selection</h4><p>For Every Split During our training,we just select the top 15–20 features that helps in separating our Dataset and model on top of these features.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ecc0a371b40e192e54148a5b6a287775/href">https://medium.com/media/ecc0a371b40e192e54148a5b6a287775/href</a></iframe><h4>Results</h4><ul><li>Simple Models</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ETxlrhZp8JD6iFBzEzbfMQ.png" /></figure><ul><li>Our Svm Classifier gave us a good score of 0.812.</li></ul><h4>Feature Selection + Normalization + Models</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*449SC9tUpbJIpglIrWNFqw.png" /></figure><p><strong>Future Work</strong></p><ul><li>Application of Deep Learning Models</li><li>Usage of Backward Feature Selection</li></ul><p>References</p><ul><li><a href="https://www.kaggle.com/featureblind/robust-lasso-patches-with-rfe-gs">Robust, Lasso, Patches with RFE &amp; GS</a></li><li><a href="https://www.kaggle.com/rafjaa/dealing-with-very-small-datasets">Dealing with very small datasets</a></li><li><a href="http://rasbt.github.io/mlxtend/user_guide/classifier/StackingClassifier/">StackingClassifier</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=718dc3202e95" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>