<?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 Nishna Ajmal on Medium]]></title>
        <description><![CDATA[Stories by Nishna Ajmal on Medium]]></description>
        <link>https://medium.com/@nishnaajmal?source=rss-63ac0c205d76------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*xm6Z8-vWs-7JR3qTr1SBKg.jpeg</url>
            <title>Stories by Nishna Ajmal on Medium</title>
            <link>https://medium.com/@nishnaajmal?source=rss-63ac0c205d76------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 14:08:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nishnaajmal/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[Upgrade your Image Classifier with Balanced data]]></title>
            <link>https://medium.com/data-science/upgrade-your-image-classifier-with-balanced-data-ddea93859c0f?source=rss-63ac0c205d76------2</link>
            <guid isPermaLink="false">https://medium.com/p/ddea93859c0f</guid>
            <category><![CDATA[towards-data-science]]></category>
            <category><![CDATA[data-cleaning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[visualization]]></category>
            <category><![CDATA[image-classification]]></category>
            <dc:creator><![CDATA[Nishna Ajmal]]></dc:creator>
            <pubDate>Sun, 23 Dec 2018 13:36:31 GMT</pubDate>
            <atom:updated>2018-12-23T13:36:31.453Z</atom:updated>
            <content:encoded><![CDATA[<h4>How preprocessing &amp; stratification can do wonders to image classifier performance</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_kVRzmLhSNjqvZNL.jpg" /><figcaption>FER</figcaption></figure><p>This article walks you through the data munging techniques to refine the machine learning models for image classifiers, particularly facial emotion recognition. The R notebook containing the source code is available in the GitHub link <a href="https://github.com/nishnab/Machine-Learning-and-Data-Visualization-Projects">here</a></p><p>In this project the ‘facial emotion recognition’ dataset, from the Kaggle competition <a href="https://www.kaggle.com/c/challenges-in-representation-learning-facial-expression-recognition-challenge/data"><strong>Challenges in Representation Learning: Facial Expression Recognition Challenge</strong></a><strong> </strong>is used. The data consists of 27000 training images (48 x 48 pixels of faces almost centred so that all the faces extend over equal spaces in the image ) and a test set containing 9000 images. This is a classification task is to categorize each image to one of seven classes (0=Angry, 1=Disgust, 2=Fear, 3=Happy, 4=Sad, 5=Surprise, 6=Neutral).</p><p>I tried several algorithms including Nearest Neighbour, Bayesian Classifiers, Decision Trees and Neural Networks to build machine learning model for the task. But, none of them was returning success rate above 30%. That left me wondering what went wrong and how to approach this task differently. Recently I came across an <a href="https://medium.com/neuralspace/kaggle-1-winning-approach-for-image-classification-challenge-9c1188157a86">article </a>by one of the top performers of the <a href="https://www.kaggle.com/c/plant-seedlings-classification">Plant Seedlings Classification Challenge</a>, that suggests the readers deal with the imbalanced class problem before classifying the images.</p><p>In this article, I would explain how I built a better Image classifier with decision tree algorithm using clean balanced data and visualizations.</p><p><strong>Step1: Explore the data</strong></p><p>On visualizing the distribution of each class in the dataset, we understand that the dataset is heavily imbalanced.</p><blockquote>A dataset is described as imbalanced if the classes are not represented approximately equal. [1]</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*dM1Voee-zAbrGxBnm4nEJQ.png" /><figcaption>Distribution of classes</figcaption></figure><p>There are more than 7000 ‘Happy ’images whereas the number of ‘Disgust’ images is less than 500. This would result in a biased classifier that predicts most of the images as majority class.</p><blockquote>Popular algorithms like Decision Tree and Logistic Regression have a bias towards majority classes in the dataset [2]</blockquote><p>To understand the complexity of the algorithm, I applied the technique <a href="https://lvdmaaten.github.io/tsne/">t-Distributed Stochastic Neighbor Embedding</a> (t-SNE), which is considered the best approach to visualize high dimensional data.</p><blockquote>t-SNE is a technique for the visualization of similarity data that is capable of retaining the local structure of the data while also revealing some important global structure such as clusters at multiple scales [3]</blockquote><blockquote>t-SNE that visualizes high-dimensional data by giving each data point a location in a two or three-dimensional map[3]</blockquote><p>The tSNE visualization of the original dataset shows us little insight into the class structure of the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*bMJAE3_1VPTbubg2H7e3RQ.png" /><figcaption>t-SNE Original Dataset</figcaption></figure><p><strong>Step 2: Partitioning</strong></p><p>Next step is to partition the training dataset to train set &amp; validation set. The validation set would be used for tuning and the final model will be evaluated using the test dataset</p><p><strong>Step 3: Creating a benchmark classifier</strong></p><blockquote>The benchmark provides a basis for evaluating and comparing algorithms for learning from examples. [4]</blockquote><p>If we create a benchmark classifier at this stage, the performance would be less than 27 %.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*9MidT7ZNNkR2gJGW3_0kYQ.png" /><figcaption>Benchmark Classifier Results</figcaption></figure><p><strong>Step 4: Data Preprocessing</strong></p><p>On Visualizing a random instance, it’s evident that the image is horizontally aligned and some amount of noise is also present as background.</p><blockquote>Preprocessing methods normalises the image acquired from uncontrolled environments. [5]</blockquote><p>Therefore all the images are first rotated &amp; cropped as shown in the fig below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*olVWPGdnaOVwA33LH7ljdQ.png" /><figcaption>Fig: Sample Image (i) Original (ii) Rotated (iii) Cropped</figcaption></figure><p>The instances are then centred and scaled to the range {0.8, 1.2}. The distribution of values in each pixel before and after the transformation can be plotted as.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*dKqulTOiIT0hDKXZMiMTgQ.jpeg" /><figcaption>Distribution of values in each pixel</figcaption></figure><p><strong>Step 5: Feature extraction</strong></p><p>Well, this is a high dimensional dataset with 2304 features. To reduce the dimensions, we can use the most widely used technique PCA.</p><blockquote>Principal component analysis (PCA) is a statistical procedure that uses an orthogonal transformation to convert a set of observations of possibly correlated variables (entities each of which takes on various numerical values) into a set of values of linearly uncorrelated variables called principal components. [6]</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*qySxsum9BM43qa-gt25Jrw.jpeg" /><figcaption>PCA Output</figcaption></figure><p>From the PCA summary its clear that the first 25 principal components hold more than 80% of the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*ADV2JiD5kHZd6_Dice8t5A.png" /><figcaption>PCA Summary</figcaption></figure><p>The tSNE visualization after PCA is strikingly better, but most of the classes are mapped somewhat proximate and not categorized with clarity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*VI5noR0nEaD6pvEHPpD5fg.png" /><figcaption>t-SNE PC 1–25</figcaption></figure><p>The same preprocessing steps and the orthogonal rotation from PCA are applied to the validation data and test data</p><p><strong>Step 5: Stratification</strong></p><p>In this step, we will deal with the imbalanced class problem in the train data.</p><blockquote>SMOTE is an oversampling approach in which the minority class is over-sampled by creating “synthetic” examples rather than by over-sampling with replacement [1]</blockquote><p>A combination of the synthetic oversampling of minority class (SMOTE)and random undersampling of the majority class, will give a nice balanced train data which can then be used to build a classifier that performs better. This is evident from the tSNE visualization of the new train data below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*MCNsKy3FVPaJJQMiEMhAEg.png" /><figcaption>t-SNE Balanced Data</figcaption></figure><p><strong>Step 6: Classification</strong></p><p>We build a classifier using the prepared train data. From the Confusion matrix of the model, we could see that the overall accuracy has improved and is nearly 60 %.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*c-w3Q5kpXnrcsPA_qjuTpg.png" /><figcaption>Confusion matrix — Classifier trained using the processed data</figcaption></figure><p><strong>Step 7: Hyper parameter tuning</strong></p><p>By tweaking the complexity parameter (cp) we can reduce the relative error as shown in the plot below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*NhJE9V9dX6MVxCJjYisAqA.png" /><figcaption>Variation in Relative error with complexity parameter</figcaption></figure><p><strong>Step 8: Build the final model</strong></p><p>The last step is to build the final model with the tuned parameter (cp value with minimum Xval-Relative Error) and evaluate it using the test data.</p><p>The confusion matrix stats say the classifier performance has improved dramatically and the overall accuracy is greater than 90 %. Other performance metrics such as sensitivity, specificity etc too is better.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/1*ySC2N6xSF8f7LVFIM8UNmg.png" /><figcaption>Confusion Matrix — Final model</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*99-8FXAnfZj_HLR5rlvJeg.png" /><figcaption>Other Performance metrics comparison for various classes</figcaption></figure><p><strong>Conclusion</strong></p><p>The preprocessing, dimensionality reduction &amp; balancing the dataset improved the performance of the decision tree classifier remarkably from 27% to 91%. Visualizing the high dimensional data using tSNE can give you a better idea of the distribution of classes, which can help significantly in preprocessing the data that can be used to build a better classifier.</p><p><strong>References</strong></p><p>[1] N. Chawla, K. Bowyer, L. Hall and W. Kegelmeyer, <a href="https://arxiv.org/pdf/1106.1813">SMOTE: Synthetic Minority Over-sampling Technique</a> (2002), Journal of Artificial Intelligence Research, 16, pp.321–357.</p><p>[2] Guest Blog, <a href="https://www.analyticsvidhya.com/blog/2017/03/imbalanced-classification-problem">How to handle Imbalanced Classification Problems in machine learning</a> (2017), [Blog] Analytics Vidhya</p><p>[3] L. van der Maaten and G.Hinton, <a href="http://www.jmlr.org/papers/volume9/vandermaaten08a/vandermaaten08a.pdf">Visualizing Data using t-SNE</a> (2008), Journal of Machine Learning Research, 9, pp.2579–2605.</p><p>[4] Z. ZHENG, <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.55.6219&amp;rep=rep1&amp;type=pdf">A benchmark for Classifier Learning </a>(1993), In Australian Joint Conference on Artificial Intelligence. World Scientific, pp.281–286.</p><p>[5] M.G. Sumithra and P. Rajeswari, <a href="http://www.aetsjournal.com/journal_issues/A_Survey:_Pre_Processing_techniques_for_Facial_Expression_Recognition.pdf">A Survey: Pre Processing techniques for Facial Expression Recognition</a> (2015), International Journal on Applications of Information and Communication Engineering Volume 1: Issue 1: January 2015, Pages:47–51, 1(1), pp.47–51.</p><p>[6] En.wikipedia.org, <a href="https://en.wikipedia.org/wiki/Principal_component_analysis">Principal component analysis</a> (2018), [online] Wikipedia</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ddea93859c0f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/upgrade-your-image-classifier-with-balanced-data-ddea93859c0f">Upgrade your Image Classifier with Balanced data</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>