<?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[Data Science 101 - Medium]]></title>
        <description><![CDATA[All you need know about data science from scratch - Medium]]></description>
        <link>https://medium.com/data-science-101?source=rss----969906acbdde---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Data Science 101 - Medium</title>
            <link>https://medium.com/data-science-101?source=rss----969906acbdde---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 05:37:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/data-science-101" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Detecting duplicate questions on Quora- beating Stanford's accuracy]]></title>
            <link>https://medium.com/data-science-101/detecting-duplicate-questions-on-quora-beating-stanfords-accuracy-6f18b3634d06?source=rss----969906acbdde---4</link>
            <guid isPermaLink="false">https://medium.com/p/6f18b3634d06</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[stanford]]></category>
            <category><![CDATA[keras]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Anchit Jain]]></dc:creator>
            <pubDate>Sun, 03 Feb 2019 16:13:35 GMT</pubDate>
            <atom:updated>2019-02-04T06:05:50.077Z</atom:updated>
            <content:encoded><![CDATA[<h3>Detecting duplicate questions on Quora- beating Stanford&#39;s accuracy 🎉</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*eNseZEXViToel_oC_vfSzQ.png" /></figure><p>Recently, I came across a very interesting problem, so thought of sharing with you all. The problem was to identify whether two questions are duplicates or not. For example, let’s take these two questions- “<strong><em>How old are you ?</em></strong> ”&amp;“<strong><em>What is your age</em></strong>?”. Though these questions have no word in common but have the same intent.</p><p>So I thought of building a deep learning based model to detect these duplicate questions.</p><h3>Business Use Case</h3><p>This model can help a variety of businesses which moderate and consolidate user-generated content.</p><p>For example, finding the similarity in text can help reduce human effort to a great extent in the businesses like call centers.</p><p>A few days back, I also came across another interesting problem from Quora to detect toxic content from questions which can help to keep online platforms safe. Would work on this problem sometime soon!</p><h3>Dataset</h3><p>Coming back to the duplicate questions task — I’ve used the dataset provided by Quora. The data set is available on <a href="https://www.kaggle.com/c/quora-question-pairs"><strong><em>Kaggle</em></strong></a>.</p><p>To give you a brief introduction to the data set it has fields like :</p><ol><li><strong>id:</strong> A common id assigned for each sample.</li><li><strong>qid1:</strong> A unique number to identify question 1.</li><li><strong>qid2: </strong>A unique number to identify question 2.</li><li><strong><em>question1: </em></strong>Actual content of question 1.</li><li><strong><em>question2: </em></strong>Actual content of question 2.</li><li><strong>is_duplicate</strong>: If questions have the same meaning then 1 otherwise 0</li></ol><p>Using the combination of natural language processing and deep learning we will see how far we can go using this approach. Since this is supervised learning, we need a set of features and a target variable to train our model. Here we can ignore all columns other than “question1”, “question2”, and “is_duplicate”.</p><p>Another traditional approach like Tf-idf, you can try an easy solution using <strong>sklearn</strong> and it’s going to work fine. Where you generally see these steps:</p><ul><li>Creating a vector representation of each text using <strong>tfidfvectorizer.</strong></li><li>Use the available <strong>Fit </strong>function to vectorize your data and of course by going through the series of data preprocessing.</li><li><strong>Transform</strong> the new entry with the vectorizer previously trained.</li><li>Compute the <strong>cosine similarity</strong> between each vector representation of the elements in your data set.</li></ul><p>This approach of creating embedding works well when you have done data preprocessing in an efficient way. But I want to try out something that doesn’t require much data pre-processing.</p><p>For better understanding, I have broken down the entire process in segments. Let’s check it out.</p><ol><li><strong>Analyzing the data.</strong></li></ol><p>Checking first few samples of data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*VWh5wcelVEG4Eo5JHKipqg.png" /></figure><p>Finding some information that can be helpful in summarizing the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*h4Sy7nD3ovlIv7nO1Z4DvA.png" /></figure><p>From my past experiences, I had to face a challenge of class imbalance so keeping this thing in mind I have plotted a bar graph to visualize the class distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*7BLA5rtIdbgHwV553e2oLg.png" /></figure><p>2. <strong>Creating Embedding.</strong></p><p>Any Deep Learning model does not understand input in the text, speech or an image. For every such input, you need to vectorize the input. For this use case I have used <strong><em>universal-sentence-encoder</em></strong> and as the name suggests, it creates the embedding for the entire sentence rather than working on words.</p><p>I’ll tell you more about this awesome embedding technique. Internally it uses the concept of deep averaging network (DAN) encoder. For more insights, I just came across the research paper which you can access <a href="https://arxiv.org/pdf/1803.11175.pdf"><strong><em>here</em></strong></a><strong><em>.</em></strong></p><p>Moving ahead with the implementation, you just need to pass the string and you will get an embedding of shape <strong>512</strong> which you can directly feed as input to your algorithm, here I have used a neural network.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f34e6b82368f22a638c06ad3426c9af1/href">https://medium.com/media/f34e6b82368f22a638c06ad3426c9af1/href</a></iframe><p>3. <strong>Building a neural network.</strong></p><p>Once we have successfully created the embedding of each sentence we will club all the embedding together to feed in my all-time favourite neural network. A short description for each layer will make you realize the beauty of this algorithm.</p><ol><li><strong>Input Layer:- </strong>Using question1 and question2 to treat input of model</li><li><strong>Lambda Layer:- </strong>Using lambda layer of keras, I have applied the embedding of each input before passing it into model.</li><li><strong>Concatenate Layer:- </strong>Concatenating both embedding of question1,question2</li><li><strong>Batch Normalization: -</strong>Since the distribution of each layer’s inputs change during training, as the parameters of the previous layers change so I have used to normalize the input at each layer.</li><li><strong>Dense Layer:- </strong>Passing input to fully connected layer</li><li><strong>Dropout Layer:- </strong>Adding this layer to previous hidden layer to avoid overfitting.</li></ol><p><strong>4.</strong> <strong>Training and predicting</strong></p><p>After building the model we are now ready to train our model. A little preparation of data won&#39;t hurt you much!</p><ol><li>Splitting features(question1 &amp; question2) and target (is_duplicate) into 80–20%.</li><li>Coverting into list.</li><li>Creating one hot encoding of target variable by converting a categorical variable into dummy variables. A simple pandas.get_dummies will do it in one go.</li><li>Initializing the global variables using the tensorflow hub.</li><li>Finally, training the model by saving the weights after every epoch.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b9ef3aaae58b87dfa90d9e79989d103/href">https://medium.com/media/0b9ef3aaae58b87dfa90d9e79989d103/href</a></iframe><p>After running the 20 epochs of size 512 I was very happy to share that I’ve achieved more accuracy than a paper by Stanford University on the same dataset. <a href="https://www.dropbox.com/s/k6mlz57hye2xx0l/Quora%20Question%20Duplication.pdf?dl=0"><strong><em>Paper here</em></strong></a><strong><em>.</em></strong></p><p>For visualizing the accuracy and loss, we have a great tool <a href="https://www.comet.ml/"><strong><em>comet.ml</em></strong></a><strong><em>.</em></strong>Which supports you to track hyperparameters, environment packages, and GPU usage, also automatically-created graphs for Machine Learning analysis and easy reproduction of experiments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*907YtlW9HizYRUUYWNJgjg.png" /></figure><p>I achieved a <strong>training accuracy of</strong> <strong>88.24 % and validation accuracy of 85.18% </strong>which can be clearly seen from this accuracy graph. The maximum accuracy achieved in the aforementioned paper was only 83.8%</p><p>To predict the intent of questions, Let’s try with some random test questions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e3afffb2958c577f659334a428c853f/href">https://medium.com/media/3e3afffb2958c577f659334a428c853f/href</a></iframe><p>Let’s see what the prediction looks like…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*ykl6lmJnWIhTZa3Zmss5lA.png" /></figure><p><strong>Closing Notes: </strong>This can be seen from the above output that questions <strong>“How old are you?”</strong> &amp; <strong>“What is your age”</strong> are similar. You can access the full code along with the output from <a href="https://colab.research.google.com/drive/1M95Ccrf0lhzyModrMQWQZoho8h-OngSy"><strong><em>here</em></strong></a>.</p><p><strong><em>Thank you for your patience…..Claps(Echoing)</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f18b3634d06" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science-101/detecting-duplicate-questions-on-quora-beating-stanfords-accuracy-6f18b3634d06">Detecting duplicate questions on Quora- beating Stanford&#39;s accuracy</a> was originally published in <a href="https://medium.com/data-science-101">Data Science 101</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Movie Recommendation System  —   Content Filtering]]></title>
            <link>https://medium.com/data-science-101/movie-recommendation-system-content-filtering-7ba425ca0920?source=rss----969906acbdde---4</link>
            <guid isPermaLink="false">https://medium.com/p/7ba425ca0920</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[recommendation-system]]></category>
            <dc:creator><![CDATA[Anchit Jain]]></dc:creator>
            <pubDate>Tue, 08 Jan 2019 17:47:25 GMT</pubDate>
            <atom:updated>2019-01-08T17:47:25.688Z</atom:updated>
            <content:encoded><![CDATA[<h3>Movie Recommendation System — Content Filtering</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N0-ikjPv4RUVvS-6KCgLPg.jpeg" /><figcaption>Netflix Personalized Movie Recommendations</figcaption></figure><p>For a long time, I have been thinking about how shopping websites like Flipkart or Amazon or movie based platforms like Netflix or even on medium suggest anything based on user interest.</p><p>But things are actually very simple. Unlike my other blogs, this will be little short and will suffice enough to brief you about “<strong><em>recommendation system</em></strong>” and of course with working code.</p><p>In this blog post, I will build a movie recommendation system using <a href="https://www.kaggle.com/rounakbanik/the-movies-dataset"><strong><em>The movies dataset</em></strong></a><strong><em> </em></strong>and deploy it using Flask.</p><p>Hearing to what Google has to say about it.</p><blockquote>A <strong>recommender system</strong> or a <strong>recommendation system</strong> (sometimes replacing “system” with a synonym such as platform or engine) is a subclass of information filtering system that seeks to predict the “rating” or “preference” a user would give to an item</blockquote><blockquote>and putting in a simple language “<em>a recommendation system suggest anything relevant based on the used interest</em>”</blockquote><p>The recommendation system is classified into two type <strong>Content-Based</strong> <strong>and</strong> <strong>Collaborative based </strong>recommendation system. Let’s try to understand each one by one.</p><blockquote>The idea behind <strong>Content-based (cognitive filtering) </strong>recommendation system is to recommend an item based on a comparison between the content of the items and a user profile.In simple words,I may get recommendation for a movie based on the description of other movies.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*1b-yMSGZ1HfxvHiJCiPV7Q.png" /></figure><blockquote>The theory behind collaborative filtering to work with collaboration with user or movie id.For example, there are two user <strong>A </strong>and <strong>B, user A </strong>likes movie <strong><em>P</em></strong>,<strong>Q,R,S</strong> and <strong>user B </strong>like movies <strong>Q,R,S</strong>,<strong><em>T</em></strong>. Since movies Q, R and S are similar to both user, therefore, movie P will be recommended to user B and movie T will be recommended to used A.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*DYJ-HQnOVvmm5suNtqV3Jw.png" /></figure><p>Starting with understanding of data first. I have used <a href="https://www.kaggle.com/rounakbanik/the-movies-dataset#links_small.csv"><strong><em>The Movies Dataset</em></strong></a><strong><em>. </em></strong>This dataset has metadata on over 45,000 movies and 26 million ratings from over 270,000 users. For our purpose, we will be using <strong>movies_metadata.csv and links_small.csv . </strong>This dataset describes the one-to-many relationship among the user and ratings. Before we dive in code lets try to figure out our approach towards the solution. For the ease of understanding, I have tried my hands on both (content and collaborative ) filtering approach on the same data set.</p><p>For content-based filtering, the approach is relatively simple we have to just convert the words or text in vector form and to find the closest recommendation to our given movie input title using cosine similarity</p><p>Let’s begin with the code.</p><ol><li>Reading the dataset from google drive into data frame. Deleting some absurd data and looking for only those movies Id’s that are actually present in links_small dataset( look up for movies metadata) and an important part is to merge all the metadata into one which in our case are “<em>overview</em>” and “<em>tagline</em>”.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc3ae71560f152dcd63004024299432c/href">https://medium.com/media/bc3ae71560f152dcd63004024299432c/href</a></iframe><p>2. Once gathering all data as per our need we have chosen <a href="http://www.tfidf.com/"><strong>TF-IDF</strong></a><strong> </strong>to create the vectorizer of our words.The reason behind choosing this algorithm is to give less weight to the words that are occurring frequently example (the, is, and etc.).When calculating the term frequency we divide the total number of words in the document so that longer documents do not have a greater influence than shorter documents.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d81af9e2632e47200c9851afc1091fb3/href">https://medium.com/media/d81af9e2632e47200c9851afc1091fb3/href</a></iframe><p>Since the implemention of Tfidf is very simple but needs to have few improvements. The words like “hate” and “don’t hate” have huge difference but still seems same for the Tfidf.So how can we get out this ?</p><p>Additionally, Using the concept of bigram or trigram where Tfidf help us to create vectors in a pair or more which can differentiate the meaning when comes in such pairs.</p><p>Once having the vector of all the words we are now ready to step into the algorithm which will eventually tell us who all vectors are similar to each other.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5307a6a899879c59088c04bc1131becf/href">https://medium.com/media/5307a6a899879c59088c04bc1131becf/href</a></iframe><p>Finally, we will create a function which will show top best-recommended movies on the given input. For this task, I have build a micro-frame (flask) for making web services in Python.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af6e2162f15f4dbaa7943587e8ddeaf2/href">https://medium.com/media/af6e2162f15f4dbaa7943587e8ddeaf2/href</a></iframe><p><strong>Running the application.</strong></p><ol><li>Navigate to the folder of your code.</li><li>Once you’re in your project directory, run the Flask application by the command <em>python predict.py</em></li><li>If all went good, you will see the following line on your terminal</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*_KhMEaEy0hJ-T5U_DVoMUw.png" /></figure><p>4. Copy paste this URL to your web browser and you are all set to see the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M8-u55phvAfO_Yl_uQfcsQ.png" /><figcaption>Movies similar to “3 Idiots”</figcaption></figure><p><strong>Closing Note: </strong>I hope this blog will help you to build your own recommendation system. In my coming blog, I’ll try to build a generic recommendation system using various embedding technique and neural network.</p><p><strong><em>Thank you for your patience…..Claps(Echoing)</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ba425ca0920" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science-101/movie-recommendation-system-content-filtering-7ba425ca0920">Movie Recommendation System  —   Content Filtering</a> was originally published in <a href="https://medium.com/data-science-101">Data Science 101</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Classifying Job Posts via NLP]]></title>
            <link>https://medium.com/data-science-101/classifying-job-posts-via-nlp-3b2b49a33247?source=rss----969906acbdde---4</link>
            <guid isPermaLink="false">https://medium.com/p/3b2b49a33247</guid>
            <category><![CDATA[projects]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Anchit Jain]]></dc:creator>
            <pubDate>Sun, 14 Oct 2018 19:04:50 GMT</pubDate>
            <atom:updated>2018-10-14T19:04:50.238Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, I will give a brief overview of natural language processing, its applications and how we can build the NLP model to solve some real-world problems.</p><p>In recent days I came across many text classification problems which include language translation or identifying the mail as spam or not and much more endless examples.</p><p>NLP is a phrase that is formed from 3 components — <em>natural</em> — as exists in nature, <em>language</em> — that we use to communicate with each other, <em>processing</em> — something that is done automatically.</p><p>Let’s try solving a real-world problem to understand more about NLP.</p><p><strong>Problem Statement</strong></p><p>A lot of companies post many jobs every day for seeker’s perusal. They tag these jobs such that they could recommend these jobs to the job seekers having similar skills. These tags are primarily entered manually by the recruiters. But in cases where the recruiter is not very enabled with plenty of tags that could hold good with the job, the system would like to make suggestions. So, whenever a recruiter post a job, our system will recommend to the recruiter to associates appropriate tags with the jobs.</p><p>Working with NLP we will try to identify the similar tags that can help recruiters to tag jobs with similar skills.</p><p>Through this article, we will cover the following steps to predict the job post tag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*ONNyU1zP1JrKlxHXUp_4XQ.png" /><figcaption>A typical NLP workflow</figcaption></figure><ol><li><strong>Understanding the data and Text pre-processing</strong></li></ol><p>You can download the data from <a href="https://drive.google.com/file/d/1jaAmlqxexQyVLpf3JhBINFzLtEjX_tge/view?usp=drive_web"><strong><em>here</em></strong></a><strong><em>. </em></strong>The dataset is in JSON format which will be converted into data frames for better understanding in later stages. The data frame will have features like “Id”, “Tittle”, “Description” and “Tags”. Tittle and description will be used as features and tags will act as a target for us.</p><p>Before we go ahead we need to remove some noise from our dataset. Data cleansing has always proved to be useful to remove some unwanted elements from the dataset. While going through the data I have figured out what all things can be done to make data more valuable.</p><ol><li>Removing all the HTML tags from job description using BeautifulSoup library.</li><li>Managing special characters such as @,#,- etc.</li><li>Grammatical or spelling errors.</li><li>Working on abbreviations (yrs and years etc.)</li></ol><p><strong>2. Text Parsing and Exploratory data analysis</strong></p><p>It’s always a good habit to do an exploratory data analysis. After analysis, it is found that in our dataset we have 20,000 job posts with their <em>titles and descriptions and associated tags </em>and a few more things</p><ol><li>Number of training examples: 20000</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19654564d3d665ef989e1fb4925be513/href">https://medium.com/media/19654564d3d665ef989e1fb4925be513/href</a></iframe><p>2. Number of unique tags: 788</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44e6f12de9eefb9a07861412a97ae5e8/href">https://medium.com/media/44e6f12de9eefb9a07861412a97ae5e8/href</a></iframe><p>It is pretty clear that we have a count of total samples and unique tags and also it is very important for us to have balance data which means all class should have almost equal count.</p><p><strong>3. Text Representation and Feature Engineering</strong></p><p>In this part of the blog, we will learn about how we can use our text in the model where we need to convert <strong>text to vector</strong>(a numerical representation of text) — <em>because all ML algorithms work on numbers and we need to find a way to convert text to vector</em>. Luckily we have a few ways that make this task easier for us.</p><p><strong>One hot encoding or Bag of words</strong></p><p>What is it? It is the technique which represents the text in vector form by first identifying all the unique words from the text and then each word of the sentence is marked as 1 whenever it is found against the bag of unique words. Wait a minute. Let me explain by an example. Collecting all the unique words from all the three sentence<em> “The elephant sneezed at the sight of potatoes.”, “Bats can see via echolocation. See the bat sight sneeze”, “Wondering, she opened the door to the studio”. </em>Below picture will help you to visualize the vector representation of our first sentence “The elephant sneeze…..”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kHYLUCu-_G3PIDG2WlVg9w.png" /><figcaption>One hot encoding</figcaption></figure><p>Why it doesn&#39;t work everywhere?</p><ol><li>Works for small corpus — but if corpus is huge the vector size becomes huge.</li><li>Doesn’t take into consideration the position of words.</li><li>Doesn’t understand the similarity between words.</li><li>Doesn’t understand the context of the sentence.</li></ol><p>Covering all these drawbacks Google has once again stepped into AI. Representing the text into a vector with the correct ordering of words and understanding the similarity and context of the word with google universal sentence encoder has helped us to a great extent.</p><p>But how does it work?</p><p>The <strong>Google Universal Sentence Encoder </strong>makes getting sentence level embeddings as easy as it has historically been to look up the embeddings for individual words. The sentence embeddings can then be trivially used to compute sentence-level meaning similarity as well as to enable better performance on downstream classification tasks using less supervised training data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ed2dd1fde4243eff092fcf3f6afe434/href">https://medium.com/media/6ed2dd1fde4243eff092fcf3f6afe434/href</a></iframe><p><strong>4. Modelling &amp; Training the data</strong></p><p>We have training data with us and can be used for training. For this, we have designed a neural network and one way to speed up the training time is to improve the network adding “Convolutional” layer. Convolutional Neural Networks (CNN) come from image processing. They pass a “filter” over the data and calculate a higher-level representation. They have been shown to work surprisingly well for text.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0427184235f84535aaf9427906d29429/href">https://medium.com/media/0427184235f84535aaf9427906d29429/href</a></iframe><p>This model might not work well but when added with LSTM it proved out with better efficiency.</p><p>Running around 50 epoch will show a gradual increase in accuracy, however, we might need to switch to another model if this doesn&#39;t work. Using spacy.io can result in better accuracy because this library works in a more efficient way when we talk about data pre-processing.</p><p>You can access the entire code from <a href="https://github.com/jainanchit51/classifying_job_post"><strong><em>here</em></strong></a>.</p><p><strong><em>Closing note:</em></strong> Since this is my first blog on NLP and this is just a gist of what you can do with NLP. In future posts, we’ll talk about other applications of NLP Text Classification using <a href="https://spacy.io/"><strong><em>spacy.io</em></strong></a>.</p><p><strong><em>Thank you for your patience…..Claps(Echoing)</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b2b49a33247" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science-101/classifying-job-posts-via-nlp-3b2b49a33247">Classifying Job Posts via NLP</a> was originally published in <a href="https://medium.com/data-science-101">Data Science 101</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Face recognition — OpenCV]]></title>
            <link>https://medium.com/data-science-101/face-recognition-opencv-e841dc0006c6?source=rss----969906acbdde---4</link>
            <guid isPermaLink="false">https://medium.com/p/e841dc0006c6</guid>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Anchit Jain]]></dc:creator>
            <pubDate>Wed, 08 Aug 2018 19:19:15 GMT</pubDate>
            <atom:updated>2018-08-13T06:34:48.173Z</atom:updated>
            <content:encoded><![CDATA[<p>Face recognition has evolved as one of the most widely used biometric in the recent times. Face recognition has stamped its uses in fields like auto door lock-unlock, criminal face detection, auto car start and it’s one of my favourites.</p><p>In this blog post, I’ll demonstrate how you can recognise face using python.</p><p>Being a path finder, something with a single way doesn’t please me much so here I have tried to recognise the face using different ways. I have implemented the architect of OpenCV using python and the entire summary can be jotted down in just few simple steps.</p><ol><li>Reading and gathering the data.</li><li>Training the dataset.</li><li>Detecting the face (creating box around the face and mapping the result with correct name)</li><li>Recognizing the name.</li></ol><p>Before we dive into coding stuff a little knowledge about the algorithm helps you to understand the picture more clearly</p><blockquote><strong><em>OpenCV-Python is a library of Python bindings designed to solve computer vision problems.Using this library we not only can read image as input to our model but also we can use to detect and recognize the face of the given person.</em></strong></blockquote><p>Let’s see how the things works with the simple implementation of code.First things first,prepare your data. Below is the folder structure which is must for this code.</p><p><strong>training-data →person1,person2</strong></p><p>Where person1 and person2 contains 10–15 or more training images of a person to be recogninzed .</p><p><strong>test-data →test1.jpg,test2.jpg…..</strong>some test images.</p><p>So this is how you need to structure your images to train.Moving ahead, create a list of labels don’t worry labels are nothing but the names of the person you want to train just remember the order of the names in the list should match with ordering of images folder in training-data and test-data.</p><p>We will begin with preparing our data.For this task we need to declare two list, one for face and another for storing the corresponding name for the trained faces.You can avoid this step by keeping the folder name with the same as the index of the recognized face in the label list because our end goal is to just to train the face with the name.Using an external source of labels is preferred for large number of dataset as per good ML standards.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88d167cab9a97dcf3cfff7d05744c37b/href">https://medium.com/media/88d167cab9a97dcf3cfff7d05744c37b/href</a></iframe><p>Done with data preparation ? We now want to detect the face by drawing the rectangle around the face.Below code of lines will help you in this.Big thanks to openCV for making this simple.Since we are using openCV multi scale detection for which we need to first convert the original image in gray scale.OpenCV comes with a in-built detector which will help us to detect the region of interest (ROI) and the method returns the coordinates of the detected face.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*9yFT4NM2ZqvZdTKxzqMm1w.jpeg" /><figcaption><strong>Face Detection using Haar Cascades</strong></figcaption></figure><p>You can use either LBP classifier (fast in process) or Haar cascade classifier which is quite slow as compared to LBP but more accurate.You can download these xml files from <a href="https://github.com/opencv/opencv/blob/master/data/lbpcascades/lbpcascade_frontalface.xml"><strong>here</strong></a><strong> </strong>and <a href="https://github.com/opencv/opencv/blob/master/data/haarcascades/haarcascade_frontalface_default.xml"><strong>here</strong></a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ac90758a520892632349afed2ad807e/href">https://medium.com/media/6ac90758a520892632349afed2ad807e/href</a></iframe><p>Once we have gained the co-ordinates of detected face we can create functions to draw the box around the face and and write the name of recognized person.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e765227d2657ae173de1dd59bda8f42a/href">https://medium.com/media/e765227d2657ae173de1dd59bda8f42a/href</a></iframe><p>Now comes the most important part of this blog. How can we forget about classifier of course the entire story is about classifying an image with correct label.Well again openCV did this with an great ease.What if i say with single line of code ? Right, you heard me.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/efb7a8f65826b3dda32b674cab2d77a0/href">https://medium.com/media/efb7a8f65826b3dda32b674cab2d77a0/href</a></iframe><p>Although its seems easy to use but let’s try to understand the working of this classifier.First, the original image is converted into gray scale in order to opt the value of pixel in binary format.A scrolling matrix window of size 3 x 3 is rolled over the gray image of pixels in the range (0–255).Picking up the central value of matrix as a threshold value and remaining values are converted is being converted in the 0 or 1 by setting 1 if the value of pixel is equal or greater than threshold value and 0 if the value is less than threshold value.Now we have linear binary number for eg. 11001010 (ignoring the central value) and this linear binary number is converted into a decimal number which is set back to the original image with new better characteristic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*62S1IkDkmzU1wCwcI0gB8w.png" /><figcaption>Architect Diagram of LBHP</figcaption></figure><p>Next, a grid of 8 x 8 is placed on the converted image and a histogram is formed after creating a bar of these grid.All these bars are then amalgamated into a histogram and then compared with histogram of the original image.</p><p>Finally,we need to find the image that matches the input image we just need to compare two histograms and return the image with the closest histogram using Euclidean distance.</p><p>For further insights read <a href="https://towardsdatascience.com/face-recognition-how-lbph-works-90ec258c3d6b"><strong><em>here</em></strong></a>.</p><p>Here comes the final part of this blog,prediction.Once again OpenCv has made this very easy for us. Just loading the test image, using opencv’s face_recognizer.predict method with faces and labels,calculating the accuracy of test model calling the text and rectangle method and we are done.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67cfc3b904167a662da81b34e1ba87bc/href">https://medium.com/media/67cfc3b904167a662da81b34e1ba87bc/href</a></iframe><p>After running the entire code, you can see the output below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9eRjwVIe71qpUNVuDDqcMg.png" /></figure><p>Well this is only one way to recognize your face.I have also implemented the same task using other algorithms like <strong>KNN </strong>and <strong>CNN .</strong></p><p>You can download the full source code from <a href="https://github.com/jainanchit51/face-recognition"><strong><em>here</em></strong></a>.</p><p>That’s all folk.</p><p><strong><em>Thank you for your patience…..Claps(Echoing)</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e841dc0006c6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science-101/face-recognition-opencv-e841dc0006c6">Face recognition — OpenCV</a> was originally published in <a href="https://medium.com/data-science-101">Data Science 101</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Improve your model accuracy by Transfer Learning.]]></title>
            <link>https://medium.com/data-science-101/transfer-learning-57ce3b98650?source=rss----969906acbdde---4</link>
            <guid isPermaLink="false">https://medium.com/p/57ce3b98650</guid>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Anchit Jain]]></dc:creator>
            <pubDate>Mon, 09 Jul 2018 21:18:19 GMT</pubDate>
            <atom:updated>2018-07-10T12:15:11.329Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog post, I’ll help you in understanding how we can work with real-life implementations of images or object recognition with one of the most vital design methodologies of deep learning that is <strong><em>TRANSFER LEARNING</em></strong>. Before we dive into the pool of transfer learning, let us warm up with some opening concepts that we need to understand.</p><p>The traditional machine learning models give a lot of pain when we do not have sufficient labeled data for the specific task or domain we care about to train a reliable model. For example, I need to train handwritten text recognition using some model trained on <a href="http://www.fki.inf.unibe.ch/databases/iam-handwriting-database/download-the-iam-handwriting-database"><strong><em>IAM</em></strong></a> data set. Transfer learning allows us to deal with these scenarios by leveraging the already existing labeled data of some related task or domain. We try to store this knowledge gained in solving the source task in the source domain and apply it to our problem of interest.</p><blockquote>In short, transfer learning is nothing but learning from others knowledge.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*NF1_eYZrV5fj0_EICLKytw.jpeg" /><figcaption>Transfer learning vs. Machine learning</figcaption></figure><p>This figure clearly reflects the beauty of transfer learning as you can see that you can train your own customized model with minimal labeled dataset while you can see there is a lack of such feature in machine learning.</p><p>For your better understanding, I have implemented the working of a simple convolutional neural network on image classification. In this blog, we will learn about various methodologies of transfer learning and will check the accuracy on each one of them. Let us have a quick look at a process of CNN.</p><ol><li>Loading data using python libraries.</li><li>Preprocess of data which includes reshaping, one-hot encoding and splitting.</li><li>Constructing the model layers of CNN followed by model compiling, model training.</li><li>Evaluating the model on test data.</li><li>Finally, predicting the correct and incorrect labels.</li></ol><p>For detail explanation of each step, you can refer my last blog on<a href="https://medium.com/data-science-101/creating-a-simple-dog-cat-image-classifier-using-keras-7dffdeea0f66"> <strong><em>image classification</em></strong></a><strong><em> </em></strong>using CNN. Let us begin with the traditional approach of machine learning using the standard CNN model.</p><p>First things first. Loading and Pre-processing the data. You can download the dataset from <a href="https://www.kaggle.com/c/dogs-vs-cats/data"><strong><em>here</em></strong></a>. and follow the given folder directory structure to access the dataset- data/train/cats, data/train/dogs, data/validation/cats, data/validation/dogs. Where each folder of cats and dogs in train folder contains 1000 images respectively and each folder of cats and dogs in validation folder contains 400 images respectively.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7fb8e99a789255c489f80f4e89c8440e/href">https://medium.com/media/7fb8e99a789255c489f80f4e89c8440e/href</a></iframe><p>Done so far? It’s time to train our model.No worries I have another gist that will help you to train. But before you scroll down make sure that you have understood each and every layer thoroughly because this will help in understanding the twist we gonna make during transfer learning.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b8bc0bd6bd8f647335763c6225aa3a1/href">https://medium.com/media/3b8bc0bd6bd8f647335763c6225aa3a1/href</a></iframe><p>Moving ahead we need to check how good we are.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*y2ZJXRSEa9unz71qNxPl-w.png" /><figcaption>CNN model output with accuracy 68.75%</figcaption></figure><p>Once we are done with training the model and with an accuracy of 68.75% after 50 epochs but this is not where we can stop. Even experimenting with hidden layers, number of neurons in hidden layers and drop out rates. We could not manage to substantially increase my training accuracy. Then how can we achieve this accuracy up to 90% or more? Yes, it is possible and this is were transfer learning comes into play. Embedding the concept of transfer learning we will see how freezing the layers of existing model will trigger the performance of the model.</p><p>Moving ahead, we will use pre-trained image recognition model called INCEPTION V3 which will help us in two ways extracting features from existing CNN and classification of fully connected softmax layers.</p><p>The entire process will cover the following scenarios.</p><ol><li>training a neural network from scratch(see above)</li><li>using <strong>bottleneck features</strong> of inception v3 model.</li><li><strong>fine tuning</strong> on a newly trained model.</li></ol><p>Working more on model layers we will see that how a change in CNN layers using inception v3 models will help to achieve good results in our accuracy. Once we succeed in building the model from scratch then working on inception v3 model won’t trouble you much. Let’s check it out.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef74de4894ca59bdc1a9d9b13f48a3d0/href">https://medium.com/media/ef74de4894ca59bdc1a9d9b13f48a3d0/href</a></iframe><p>Running the above code will give you the following result after running the 10 epochs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*OeLkw7FwJsUKOhk39NkyaQ.png" /><figcaption>Bottleneck features with 92.93% accuracy</figcaption></figure><p>If you can notice in above lines code, the functionality of the entire code are divided into two-phase bottleneck featuring and Fine tuning</p><blockquote>‘Bottleneck’ is an informal term we often use for the layer just before the final output layer that actually does the classification.</blockquote><blockquote>Fine-Tuning is training the variables of an imported module together with those of the model around or in simple words we can say that it is the process in which the parameters of a trained model must be adjusted very precisely while we are trying to validate that model.</blockquote><p>Once defining the inceptionv3 layers with bottleneck featuring we are about to compile the model and using the process of data augmentation on training and test data we can help our model to grab more features of an image by eventually increasing the size of the database. Data augmentation also plays one of the most vital roles in increasing the accuracy of any model.</p><p>And we are all set for training our model with new accuracy.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a76fc86531dcc5942c91404cbfe09828/href">https://medium.com/media/a76fc86531dcc5942c91404cbfe09828/href</a></iframe><p>So far we have now achieved a good accuracy on this model by freezing the base layers and unfreezing the top layers of the model. What if we can further improve the accuracy from 92 % to 97.88 %. By using the process of fine-tuning in the above code we can reach to this accuracy. After tuning very precisely the entire model we were able to achieve the following result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*gmUO1WXhmtX99rYICCWdxw.png" /><figcaption>Fine tuning with accuracy of 97.88 %</figcaption></figure><p><strong><em>SUMMARY :</em></strong>Using these two process of an inceptionv3 model we have learned that how we can improve the accuracy of any model and below summary table will help you to identify the distinguished accuracy among them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*uIl6n3GNuNLkH7CN9-ejFQ.png" /><figcaption>Summary</figcaption></figure><p>You can access the full code <a href="https://github.com/jainanchit51/transfer_learning"><strong><em>here</em></strong></a><strong><em>.</em></strong></p><p><strong><em>Thank you for you patience…………Claps (Echoing)</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57ce3b98650" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science-101/transfer-learning-57ce3b98650">Improve your model accuracy by Transfer Learning.</a> was originally published in <a href="https://medium.com/data-science-101">Data Science 101</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a simple dog  vs cat  image classifier using Keras]]></title>
            <link>https://medium.com/data-science-101/creating-a-simple-dog-cat-image-classifier-using-keras-7dffdeea0f66?source=rss----969906acbdde---4</link>
            <guid isPermaLink="false">https://medium.com/p/7dffdeea0f66</guid>
            <category><![CDATA[projects]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Anchit Jain]]></dc:creator>
            <pubDate>Fri, 25 May 2018 21:51:56 GMT</pubDate>
            <atom:updated>2018-12-06T10:57:32.363Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been learning various machine learning algorithms like <a href="https://medium.com/data-science-101/writing-multivariate-linear-regression-from-scratch-19e32eeb6ab0">Linear Regression</a>, <a href="https://medium.com/data-science-101/building-a-spam-messages-detector-using-machine-learning-a866931382df">Logistic Regression</a> and Decision Trees for a while, it’s time for me to explore Neural Networks for advanced Machine Learning problems.</p><p>In this blog I’ll be discussing all the basic fundamentals of Machine line(ML) and using this branch of science I’ll help you to figure out how we can work on problem where we need to predict something.</p><p>So what is Machine learning ?</p><p>Copying few lines from <a href="https://en.wikipedia.org/wiki/Machine_learning"><strong><em>wikipedia</em></strong></a><strong><em> </em></strong>lets see what they say.</p><blockquote><strong>Machine learning(ML)</strong> is a field of computer science that often uses statistical techniques to give computers the ability to “learn” (i.e., progressively improve performance on a specific task) with data, without being explicitly programmed.</blockquote><p>Well said.Using the same concept we will try to train our model with large data set with all parameters and at the end we will test of model with some inputs.</p><p>A little theory for big picture should not be painful.</p><p>I’ll try to precise every linked topic with minimal theory and maximum knowledge. Now how can we use ML(please excuse my laziness) for our problem statement and how can I use ML for my problem and this is where the concept of <a href="https://machinelearningmastery.com/what-is-deep-learning/"><strong><em>Deep learning</em></strong></a> comes into play. In simple word deep learning is the way to implement ML using algorithms and inspired by the functionality of the brain called artificial neural networks.</p><blockquote><strong>Deep learning</strong> is an aspect of artificial intelligence (<a href="https://searchenterpriseai.techtarget.com/definition/AI-Artificial-Intelligence">AI</a>) that is concerned with emulating the learning approach that human beings use to gain certain types of knowledge.</blockquote><p>Did you see that ? …. <strong>Artificial Neural Network. </strong>Yes please pay your attention here.It is a machine learning algorithm, which is built on the principle of the organization and functioning of biological neural networks.Now look at the beauty of ML here is that our entire neural network model will work in the same way like human brain work.Let see what our dear google has to say about artificial neural networks.</p><blockquote><strong>An artificial neuron network</strong> (ANN) is a computational model based on the structure and functions of biological neural networks. Information that flows through the network affects the structure of the ANN because a neural network changes — or learns, in a sense — based on that input and output.</blockquote><p>The below image briefs you about how a message is being transferred from one neuron to another where each neuron is located in a series of layer where we feed data to <strong><em>input layer</em></strong> and by passing it through successive <strong><em>hidden layer</em></strong> and training our model simultaneously we reach to layer called <strong><em>output layer</em></strong> where we can predict our output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CH0rUNdcWD2O2gwBwaJSXA.png" /><figcaption>Artificial Neural Network</figcaption></figure><p>I guess this much theory is suffice to learn our problem statement. It’s time to dive in our coding pool.</p><p>For those of you who want to understand Neural Networks in more depth — I’d recommend watching this short, yet exhaustive explanation of neural networks <a href="https://www.youtube.com/watch?v=GQVLl0RqpSs">here</a>.</p><p><strong><em>Image classification:</em></strong></p><p>The very first step in CNN is to classify image,since it very easy to visualize an image with human eye but how can we make the same thing to visualize through our machine …..sad but machines can see :( this can be achieved through the matrix representation of image. See how.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*av47vApmzuM0AN21VaIcSA.png" /><figcaption>Image classification</figcaption></figure><p>From the above image we can easily see the image (digit 8 ) now what is image <strong><em>nothing but the collection of pixels</em></strong>. So here the image consists 28 number of rows and 28 number of columns which is equal to 784 pixels in total and these 784 pixels will act as an input to our first layer of CNN that is input layer.In a similar way we have taken thousands of images of dog and cat and we have taken 150 by 150 pixels as an input. Also, we rather than taking each image one by one I have created a batch of images of size 16 for faster iteration.Taking samples of 2000 images in iterating the entire model for 50 (Epochs)</p><blockquote>One <strong>Epoch</strong> is when an ENTIRE dataset is passed forward and backward through the neural network only ONCE.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23727e33f93e780c92cde21362b3f771/href">https://medium.com/media/23727e33f93e780c92cde21362b3f771/href</a></iframe><p>Okay ! now we have designed our input layer and now moving ahead with further layers we chooses our model to be sequential since the output of one layer is input to another layer and so on.Let check how these layers looks like.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8fa08dae12613dca90831fea3c48d013/href">https://medium.com/media/8fa08dae12613dca90831fea3c48d013/href</a></iframe><p>Let us see each function one by one….here we go.</p><ol><li><strong><em>Sequential() : </em></strong>The sequential model is just a linear stack of layers. add() method help you to add layers in your model.</li><li><strong><em>Conv2D : </em></strong>This layer creates a convolution kernel that is coiled with the input layer to produce a tensor (generalization of matrices) of outputs.</li><li><strong><em>Activation :</em></strong> This function is a <strong><em>node </em></strong>between the output of one layer to another.</li><li><strong><em>MaxPooling2D : </em></strong>It is the process of down-sampling(reducing dimensions) the representation of image.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*iv7fsvgvJ5eBv--iabxqkA.png" /><figcaption>MaxPooling2D</figcaption></figure><p>Now once we have created the input and hidden layer, we need to connect all the layers so as to gain the output for that<strong> Flatten() </strong>method is used to take the input which creates 1-D array of input.Followed by <strong>Dense() </strong>method which is used to connect all the layers densely for the final output and the last method is <strong>Dropout() </strong>which is used to avoid overfitting.</p><p><strong><em>Augmenting and Compiling the images :</em></strong></p><p>This is something which helps in training our model with best fit. Augmentation is the pre-processing of image where an model is been trained with wide diversity of an image. This diversity of an image can be carried out in following ways like <strong>scaling, translation, rotation and flipping etc.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96951b418b2f14d5fd878f92fbb10b6e/href">https://medium.com/media/96951b418b2f14d5fd878f92fbb10b6e/href</a></iframe><p>We then compile the CNN using the compile function. This function expects three parameters: the optimizer, the loss function, and the metrics of performance.The optimizer is the gradient descent algorithm we are going to use. We use the <strong><em>binary_crossentropy</em></strong><em> </em>loss function since we are doing a binary classification.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c56903af61130a2c31bc9bcf749e44e0/href">https://medium.com/media/c56903af61130a2c31bc9bcf749e44e0/href</a></iframe><p>Last, after gathering the well structured data it’s time to train the model. We have model.fit_generator() where we take following arguments and train our model multiple times till we achieve the maximum accuracy and minimum loss. The accuracy of our model can be achieved by tuning our hyper-parameters(Epochs). Once we train our model with maximum accuracy we need to save the whole model so as to avoid multiple training for every test.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/53c85b22f1f22a3d5e5af8bcb8cbf1e6/href">https://medium.com/media/53c85b22f1f22a3d5e5af8bcb8cbf1e6/href</a></iframe><p>Its time to summarize our learning&#39;s so far. Lets check it out some necessary steps for building dog-cat classifier.</p><ol><li>Image per-processing</li><li>Creating ANN layers</li><li>Model training</li><li>Model testing</li><li>Model evaluation</li></ol><p>You can access the full code <a href="https://github.com/jainanchit51/datascience/tree/master/machine_learning/dog_cat_classifier"><strong><em>here</em></strong></a><strong><em>.</em></strong></p><p><strong><em>Thank you for you patience…………Claps (Echoing)</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7dffdeea0f66" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science-101/creating-a-simple-dog-cat-image-classifier-using-keras-7dffdeea0f66">Creating a simple dog 🐶 vs cat 🐱 image classifier using Keras</a> was originally published in <a href="https://medium.com/data-science-101">Data Science 101</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a spam messages detector using machine learning]]></title>
            <link>https://medium.com/data-science-101/building-a-spam-messages-detector-using-machine-learning-a866931382df?source=rss----969906acbdde---4</link>
            <guid isPermaLink="false">https://medium.com/p/a866931382df</guid>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Anchit Jain]]></dc:creator>
            <pubDate>Mon, 21 May 2018 04:57:50 GMT</pubDate>
            <atom:updated>2018-05-21T12:44:10.882Z</atom:updated>
            <content:encoded><![CDATA[<p>Over the past few weeks, I’ve been writing some of the most common machine learning algorithms from scratch <a href="https://medium.com/data-science-101/tagged/algorithms">here</a>.</p><p>Now let’s implement them to solve some real world problems.</p><p>Let’s start with creating a simple <strong>Spam Messages Detector </strong>using <a href="https://medium.com/data-science-101/writing-logistic-regression-from-scratch-70c429319633">Logistic Regression.</a> Logistic regression is a simple method to classifying data — be it hot or not hot, spam or not spam.</p><p>Although, the are few Python libraries like Scikit, that can simply ask you to feed input and library can perform the entire operation of classification of our own- but to get a firm understanding of what happens under the hood, I , in my last blog have tried to explain the working of logistic regression using <strong>iris </strong>data set. So before you scroll your eye down please <a href="https://medium.com/data-science-101/writing-logistic-regression-from-scratch-70c429319633"><strong><em>read how to implement logistic regression from scratch here</em></strong></a></p><p>Assuming that you are no more tyro to logistic regression we will begin with data set. The dataset we have used is <a href="https://www.kaggle.com/uciml/sms-spam-collection-dataset/data">SMS Spam Collection Dataset from Kaggle</a>. We have our training data in two columns(type and text).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*ScXxTgQHgPrqDcnhf8yzSg.png" /></figure><p>Before we start with coding stuff, let us first analyse the data set.In our first column we have classified our data as <strong>spam and ham(not spam). </strong>It can be easily seen from the above image that text is in the form of string and we need to first <strong><em>vectorize</em></strong> the string in the numerical list of list, so basically this is used for learning vector representations of words.</p><p><strong>What the hell is vectorization?</strong></p><p>Most of the machine learning algorithms (read all), like logistic regression, understands only numbers. We need to figure out a way to convert a text sentence into numbers.</p><p><a href="https://monkeylearn.com/blog/beginners-guide-text-vectorization/">Vectorization</a> is a simple process of converting a text sentence into a array of numbers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*y8JyHO4sxKax94JEduZ1mw.jpeg" /></figure><p>To do this, we need to create a dictionary of all unique words from the text column as key and indexing from zero as value.While iterating each value from text column (which is an array) and fetching the position (value) of matched word (key) from dictionary.We need to create another array of zero’s and simultaneously updating the position of this zero array corresponding to matched key from our dictionary.</p><p>For example : I have a string say, <strong>”Hello I am Anchit, and I love machine learning”</strong>, our unique dictionary and vectorize form of our input say <strong>“Anchit loves to travel” </strong>would looks like the below dummy code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4096c58cc6f034c002073e1f997cfc5/href">https://medium.com/media/c4096c58cc6f034c002073e1f997cfc5/href</a></iframe><p>The python implementation part is much easier.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e63fe4bf9e417217a5e537f3cd25e7c8/href">https://medium.com/media/e63fe4bf9e417217a5e537f3cd25e7c8/href</a></iframe><p>Now we have vectorize input in our hand,using this vector as an input we will be working on following methods to predict the output from our model.</p><ol><li><strong>Creating matrices :</strong></li></ol><p>This should be pretty routine by now. We append a <strong><em>one’s</em></strong> array to our matrix . Then we concatenate an array of ones to X.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aad40ed70f51f3814cddf04d196c349c/href">https://medium.com/media/aad40ed70f51f3814cddf04d196c349c/href</a></iframe><p><strong>2. Defining Sigmoid and loss function :</strong></p><p>Speaking theoretically <strong><em>“ sigmoid”</em></strong> is a function that takes inputs and to generate probabilities, logistic regression uses a function that gives outputs between 0 and 1 for all values of X and we have another function named <strong><em>“loss or cost function” </em></strong>that consists of parameters or weights we initialize them randomly but we keep them updating with our learning rate and we will use gradient descent to minimize our cost.Following lines of code will guide you further.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8cf6635bfb9e1bddc4494c14b186f4a5/href">https://medium.com/media/8cf6635bfb9e1bddc4494c14b186f4a5/href</a></iframe><p><strong>3.</strong> <strong>Gradient descent </strong>:</p><p>Now, to understand gradient descent, let us imagine the path of the river originating from the top of the mountain. The job of gradient descent is exactly that of what the river aims to achieve; to reach the bottom-most point of the mountain. Now, as we know there is a gravitational force on the earth and hence the river will keep flowing downwards until it reaches the foothill.</p><p>In a similar way we will iterate our sigmoid function several times probably in thousands and simultaneously using the output of sigmoid function in loss function we will minimize the loss function.Below code will help you out in better understanding.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a3e60b91fa46fb5f7393ea68e2e967b/href">https://medium.com/media/4a3e60b91fa46fb5f7393ea68e2e967b/href</a></iframe><p><strong>4. Prediction :</strong></p><p>This is probably the most crucial part of our model where we predict our model.Here we need to understand our prediction, since we have set of input (X) and theta’s (self.theta) we just need to focus on <strong><em>` X @ theta.T `</em></strong> which is a matrix operation of X and theta. It does not matter how many columns are there in X or theta, as long as theta and X have the same number of columns the code will work. We need to set a threshold variable at 0.5 for which values greater than 0.5 are classified in class 1 and values less than 0.5 are classified in class 0.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7add6602f518ba18cbf7826c6f956757/href">https://medium.com/media/7add6602f518ba18cbf7826c6f956757/href</a></iframe><p><strong>6. Evaluation.</strong></p><p>Last but not the least it is always important to know our accuracy of model so we can calculate the accuracy percentage of our model by passing the text and type column in this function and predicting the new type (predicted type) and then calculating the percentage using these features. Don’t you worry following lines of code will clear your more.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79ca0be1046a2e44e07cf46424cc01b9/href">https://medium.com/media/79ca0be1046a2e44e07cf46424cc01b9/href</a></iframe><p>Meanwhile you will be reading this line, I hope you are cleared with the process of mail classification. You can access the full code from <a href="https://github.com/jainanchit51/datascience/tree/master/machine_learning/spam_classifier"><strong><em>here</em></strong></a><strong><em>.</em></strong></p><p>A few things to note about the limitations of my code:</p><ol><li>My code fails to understand the similarity of words like man and men, bed and beds etc. This can be solved using <a href="https://nlp.stanford.edu/IR-book/html/htmledition/stemming-and-lemmatization-1.html">stemming and lemmatization</a>.</li><li>The classification accuracy can be improved by using more sophisticated algorithms like decision trees or neural networks</li><li><a href="https://en.wikipedia.org/wiki/Word2vec">Word2Vec</a> can also drastically improve accuracy.</li></ol><p><strong><em>Thank you for your patience……Claps (Echoing)</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a866931382df" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science-101/building-a-spam-messages-detector-using-machine-learning-a866931382df">Building a spam messages detector using machine learning</a> was originally published in <a href="https://medium.com/data-science-101">Data Science 101</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing Logistic Regression From Scratch]]></title>
            <link>https://medium.com/data-science-101/writing-logistic-regression-from-scratch-70c429319633?source=rss----969906acbdde---4</link>
            <guid isPermaLink="false">https://medium.com/p/70c429319633</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Anchit Jain]]></dc:creator>
            <pubDate>Fri, 18 May 2018 06:03:29 GMT</pubDate>
            <atom:updated>2018-05-18T06:03:29.015Z</atom:updated>
            <content:encoded><![CDATA[<p>It has been two months since I started learning Machine Learning and I believe that the best way to learn it is to write all common algorithms from scratch — without using any libraries like Scikit.</p><p>This is the second post in my series of articles where I re-write common machine learning algorithms from scratch</p><p>Here is my previous post on writing Linear regression</p><p><a href="https://medium.com/data-science-101/writing-multivariate-linear-regression-from-scratch-19e32eeb6ab0"><strong><em>Part1: Writing Multivariate Linear Regression from Scratch</em></strong></a></p><p>Let’s start with understanding the difference between <a href="https://medium.com/data-science-101/writing-multivariate-linear-regression-from-scratch-19e32eeb6ab0">Linear Regression </a>and Logistic Regression and when to use them.</p><p>To put it in very simple words — when the prediction of outcome for the given input is in a range or continuous (i.e regression), let’s say how many runs a batsman will hit in a match where the outcome in a continuous range, we can use Linear Regression.</p><p>While on the other hand, when the prediction of the outcome is in a discrete form (0 or 1) or the output is in the form of yes or no, <strong><em>logistic regression</em></strong> comes into play.</p><p>Like any machine learning model, we have three major topics on which the entire model stands.</p><h4>1. Hypothesis</h4><p>The hypothesis of logistic regression starts with linear regression where linear regression algorithm is used predict y(range of outputs) for given x(inputs). However confining up to linear regression model doesn’t make sense for hθ​(x) to take values larger than 1 or smaller than 0, since as per our requirement it has to be y ∈ {0, 1}. To fix this we will be plugging all values for y in our Logistic function or <strong><em>“Sigmoid function”</em></strong>. Once passing all those values from linear regression to sigmoid function we will get the output in 1 or 0</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/1*2SXHmTmrjwWTdaRV4A3Nyg.png" /><figcaption>Hypothesis of logistic regression</figcaption></figure><p>If you can notice here , Z is nothing but matrix representation of the linear model i.e. <strong>y = mx + c.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*HRvUtEZKCelCZ72D0Y5SnQ.png" /><figcaption>Sigmoid function</figcaption></figure><p>From the above graph we can find that for any real number to the (0, 1) interval, making it useful for transforming an arbitrary-valued function into a function better suited for classification.</p><p>hθ​(x) will give us the <strong><em>probability </em></strong>that our output is 1. For example,hθ​(x)=0.7 gives us a probability of 70% that our output is 1. Our probability that our prediction is 0 is just the complement of our probability that it is 1 (e.g. if the probability that it is 1 is 70%, then the probability that it is 0 is 30%).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30241bd8666f5cc7a27e70208b1aa6e8/href">https://medium.com/media/30241bd8666f5cc7a27e70208b1aa6e8/href</a></iframe><p><strong>2. Cost function or Loss function</strong></p><p>We have some random parameters (represented by theta in our notation) to initialize our cost function. We want to fit the values of weights or parameters in such a way that our model works well that means decreasing the cost will increase the maximum likelihood assuming that samples are drawn from an identically independent distribution.</p><p>Our cost function somehow looks like :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/383/1*wS8jNJwxkItbV6swPLOtAw.png" /><figcaption>Logistic cost function</figcaption></figure><p>The another compact way to express above two condition can be seen from the below code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3955b7fddda8c335de1981627b47953d/href">https://medium.com/media/3955b7fddda8c335de1981627b47953d/href</a></iframe><p>Let me help you in visualizing the cost function through a graph.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jhs-cJTIFyQBV8d04vxR2w.jpeg" /></figure><p>From the above graph, our goal is to reach the bottom-most point in the graph and this can be achieved by adjusting our initial weight through gradient function and iterating the entire gradient function until the <strong><em>loss is minimized.</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8cda4098621b7f74faef3ca12c5c0fc0/href">https://medium.com/media/8cda4098621b7f74faef3ca12c5c0fc0/href</a></iframe><p>Now it’s time to predict our model, by calling our sigmoid function and getting probability &gt; 0.5, we can consider such cases of class 1 and probability &lt; 0.5 can be categorized as of class 0, so this is how the prediction of our model works.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f4c673caeb43b27412e1016f9da54b72/href">https://medium.com/media/f4c673caeb43b27412e1016f9da54b72/href</a></iframe><p>This implementation is for binary logistic regression. For data with more than 2 classes, softmax regression has to be used.( a blog post on that later)</p><p>Let me quickly summarise the entire story, we have started with the loading of data set in such a way that can be used for matrix calculation. We have designed our sigmoid function followed by our loss function.</p><p>Training our model with iterating linear model and plugging the output from linear function to our sigmoid function till we reach the minimum of cost or loss function. Once we train our model we can work on predict and evaluate our model and hence we can calculate the loss and accuracy of our model.</p><p>I will soon write a blog on how I used this piece of code to classify whether a message is spam or not. Stay tuned!</p><p><strong><em>Thank for your patience !!!!!……Claps (Echoing)</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70c429319633" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science-101/writing-logistic-regression-from-scratch-70c429319633">Writing Logistic Regression From Scratch</a> was originally published in <a href="https://medium.com/data-science-101">Data Science 101</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing Multivariate Linear Regression from Scratch]]></title>
            <link>https://medium.com/data-science-101/writing-multivariate-linear-regression-from-scratch-19e32eeb6ab0?source=rss----969906acbdde---4</link>
            <guid isPermaLink="false">https://medium.com/p/19e32eeb6ab0</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Anchit Jain]]></dc:creator>
            <pubDate>Mon, 07 May 2018 06:29:56 GMT</pubDate>
            <atom:updated>2019-02-11T07:24:08.823Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the toughest part of every data scientist’s journey is to really understand what happens behind the hood of popular libraries like scikit for implementing various machine learning algorithms.</p><p>This is a part my multi-post series on implementing various machine learning algorithms from scratch without using any machine learning libraries like scikit, pyspark etc.</p><p>The first algorithm that I am going to discuss is — the most basic — <strong>Multivariate Linear Regression</strong>.</p><p><strong>What is Linear Regression </strong>? Linear regression is a simple data prediction technique to predict dependant variable (Y) using its linear relationship to the independent variable (Y).</p><p>For example, I have data say number of rooms. Using the given input(number of rooms) I want to predict the price of a house. Well that’s not easy but at the end of this article you will surely get something. When I have many more features like (size of bedrooms, number of rooms, distance from city centre etc.) to predict the price of price of house then I’ll say its a <strong>multivariate</strong> Linear regression.</p><p>Now let me show you a glimpse of data using scatter plot. This graph will help you in basic understanding of how data looks like when plotted on graph.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*c3Jfai0Q8HDbCw0yDgkAJQ.jpeg" /></figure><p>From the above graph you may see some blue dots where each dot represent some value with respect to X and Y axis. Now I want to draw a line on the graph in such a way that covers maximum number of blue dots. Speaking technically, I want to find a slope of line in such a way where distance between each dot to line is <strong>minimum</strong>. This is called minimising<a href="https://en.wikipedia.org/wiki/Mean_squared_error"> Root Mean Square error</a></p><p>Hopefully I am clear so far. Moving ahead with my current data set. I have few columns by the name “size of room”,”number of bedrooms” and “price”.Based on size and number of bedrooms I want to predict the price of room.For your ease I have broken the entire process in step for easy learning.</p><p><strong>STEP 1. Reading and Normalising the data.</strong></p><p>Before we start with any problem we need to read and analyse the data.Well at first glance this step seems likely to be very easy, but it can be very painful if not taken care.</p><p>Why do we need to normalise the data? Well, that’s because some of our features might be in a range of 0–1 and other in 0–1000. Feeding the data as it is can lead to wrong fit.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84b4329c655917205de6474e251233f1/href">https://medium.com/media/84b4329c655917205de6474e251233f1/href</a></iframe><blockquote><em>Normalize : To make data scalable to each other.</em></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a681b2701d742ae2a38aad90d75c5ef4/href">https://medium.com/media/a681b2701d742ae2a38aad90d75c5ef4/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f91350f42e40dbc848740bd170683372/href">https://medium.com/media/f91350f42e40dbc848740bd170683372/href</a></iframe><p>If you can notice here, now the data here is scaled to some limited range.Which makes an easy visualisation of data on scatter plot.</p><p>Before we jump on this, we need to understand the use of hyperparameter in our model. These makes sense when we need to tune our model in order to minimise the cost function.Here our model is nothing but a mathematical equation of a straight line that is <strong><em>y = mx + c, </em></strong>where x is the given sets of input,m is the slope of line , c is the constant and y is the output(which is predicted)</p><p><strong><em>Learning rate and iterations </em></strong>these are the hyper-parameter that plays a vital role in tuning our model.Learning rate is a hyper-parameter that controls how much we are adjusting the weights of our network with respect the loss gradient and how many times we need to tune our model is our iteration.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/790ad990d2a4b8a5b295584eadfbcad3/href">https://medium.com/media/790ad990d2a4b8a5b295584eadfbcad3/href</a></iframe><p><strong>Analysis : </strong>In linear regression, we have the training set and the hypothesis. We already have the training set as above and our hypothesis will be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/214/1*xgAthezazqsEz4As2TJ5Wg.png" /><figcaption>Equivalent to y = mx + c</figcaption></figure><p>Where θ’s are the parameters and <strong>h(x) </strong><em>is y-predicted.</em></p><p><strong>STEP 4. Calculate the cost function</strong></p><p>The objective of the machine learning exercise is to find the values of these θ’s so that the function <strong><em>h</em></strong> shown above is close to actual values for the training examples. Speaking in mathematical terms, we want to minimize the difference between <strong><em>h(x) </em></strong>and the corresponding value of <strong><em>y</em></strong> squared. We will call this our cost functions.</p><p>In simple words it is a function that assigns a cost to instances where the model deviates from the observed data. In this case, our cost is the sum of squared errors. The goal of any supervised learning exercise is to minimize whatever cost we chose. Our cost function can also be shown using the below equation and this is how we can calculate our cost function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*UL8kpRowZqZX_6_rDadlKA.png" /><figcaption>Cost function equation</figcaption></figure><p>This equation is nothing but the <strong><em>summation of square of difference between the y-predicted and y actual divided by twice of length of data set. </em></strong>And from above equation our goal is to minimize the function of <strong><em>J.</em></strong></p><p>Ploting <strong>J </strong><em>on graph </em>will give you more clear understanding of this function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*CLlrjZjkr-vUvC2B5wCf9Q.png" /><figcaption>Cost(Squared Error) Vs. No of Iterations</figcaption></figure><p>It can be easily seen from the above graph that at iteration near to 2 the value of cost is minimum and we can say that iterating our training data twice we will get the minimum cost function.</p><p>Let me quickly summarise what we have learnt so far.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*3HBJ3P5c8PUL0hjZtCAUyg.png" /></figure><p>Now let us see how this cost function looks like.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eaad588e788a56a12ceec17fd8037400/href">https://medium.com/media/eaad588e788a56a12ceec17fd8037400/href</a></iframe><p><strong>Step 5. Gradient Descent.</strong></p><p>What does it mean and where does it comes from ? If you can see from the cost function graph our ultimate goal is to move towards the bottom most point of the graph. A way to achieve this is using this Gradient Descent algorithm. As its name suggests we need to iterate the below procedure till convergence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/1*vSqmwDfGaPseN_pn6o4jAQ.png" /><figcaption>Gradient Descent Algorithm</figcaption></figure><p>Here <strong><em>α</em></strong> is the learning rate and we multiply it with the derivative or the gradient of <strong><em>J</em></strong>. Well gradient descent method is not only confined upto linear regression model but can be used in other model as well when iterative optimization of algorithm that finds the minimum value of a function comes into play.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7dec5ea865f1badd1edf9c51f141fd4/href">https://medium.com/media/f7dec5ea865f1badd1edf9c51f141fd4/href</a></iframe><p>Lets check our obligatory analysis for the above code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/291/1*KrT9ssO5MYcPRloIKFLD0g.png" /><figcaption>Gradient Descent</figcaption></figure><p>From the above graph, Our aim is to iterate from starting point and working with iterations in such a way that we finally land up on the minimum point of graph.This is achieved by tuning our model with learning rate and number of iterations.</p><p>So before I wind up let us summarise our learnings so far.</p><ol><li>We have learnt our data set.</li><li>Normalizing the data set</li><li>Training our model with normalized data</li><li>Calculating the cost function</li><li>Minimizing the cost function.</li></ol><p>You can access the complete code and the data set <a href="https://github.com/jainanchit51/datascience/tree/master/machine_learning/linear_regression"><em>here</em></a></p><p>Thank you for your patience …..<strong>Claps (Echoing)</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19e32eeb6ab0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science-101/writing-multivariate-linear-regression-from-scratch-19e32eeb6ab0">Writing Multivariate Linear Regression from Scratch</a> was originally published in <a href="https://medium.com/data-science-101">Data Science 101</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring Breast Cancer Data set]]></title>
            <link>https://medium.com/data-science-101/exploring-breast-cancer-data-set-b1053ea71781?source=rss----969906acbdde---4</link>
            <guid isPermaLink="false">https://medium.com/p/b1053ea71781</guid>
            <category><![CDATA[visualization]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[feature-engineering]]></category>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Anchit Jain]]></dc:creator>
            <pubDate>Sun, 29 Apr 2018 10:42:07 GMT</pubDate>
            <atom:updated>2018-10-03T06:38:59.105Z</atom:updated>
            <content:encoded><![CDATA[<p>Visualising and exploring Breast Cancer data set to predict cancer</p><p>Hello everyone!</p><p>This is my first blog of Machine learning which will help you understand how important it is to analyse a data set before we implement any algorithm in machine learning.</p><p>Now, you may ask how ? Let me show you. Analysing a data set, unlike traditional programming, in Machine Learning one can spend months on a project with no results to show. Jumping directly into implementation of algorithm, which you might feel might work, without analysing it is a big pothole.</p><p>In this post I’ll try to outline the process of visualisation and analysing a dataset.</p><p><strong>Data set</strong>: breast-cancer-wisconsin.csv<br><strong>Source</strong> : https://github.com/jeffheaton/aifh/blob/master/vol1/python-examples/datasets/breast-cancer-wisconsin.csv<br><strong>Description </strong>: This dataset helps you out to make a classification on breast cancer, have a quick glimpse on top five rows of data sets</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*CWHIo4xkvg26L6buuMH70A.png" /></figure><p>Probable like you, I am not a cancer specialist. But let’s pretend to understand that the features in the dateset are sufficient to predict the stage of a cancer patient.</p><blockquote><strong><em>Task</em></strong><em>: Classify the cancer stage of a patient using various features in the dataset</em></blockquote><p>Before we jump on to using some kind of regression algorithm, here is what I would do to gain an intuition/insight into the problem statement:</p><ol><li>Let us first <strong><em>clean up</em></strong> some data.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77ceb5dc55cbd36eaaadc942c945528a/href">https://medium.com/media/77ceb5dc55cbd36eaaadc942c945528a/href</a></iframe><p>This doesn’t ends here. Probably,you need to sweat more to clean the data.The cleaning of real life data has always been a big pain to us, still we will try to cover in later posts.Still just for the taste, cleaning of data deals with handling null values, zeros, or special characters (“?”).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6fc92de99f2e4e7edfe491dad4755422/href">https://medium.com/media/6fc92de99f2e4e7edfe491dad4755422/href</a></iframe><p>2. Start with a <strong>Heat Map</strong> for some initial intuition.</p><p>Now where does this comes from? Well, just to understand which attribute(parameter) is co-related with other, we need to understand the concept behind correlation among attributes.To understand this better,this is where Heat Map comes into play.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35888dd9716a6d889a5689e71d9afedf/href">https://medium.com/media/35888dd9716a6d889a5689e71d9afedf/href</a></iframe><p>This is how a heat-map looks like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*Qg86sdzAA5u1I7NfUHeBkA.png" /><figcaption><strong>Heat Map</strong></figcaption></figure><p>What we need to understand here the co-relation among every attributes, where +1 shows the highest positive co-relativity and -1 being the negative co-relativity.</p><p>Let’s focus on the square where attribute <strong><em>size_uniformity </em></strong>of X-axis and <strong><em>shape_uniformity </em></strong>of Y -axis meet that is <strong>0.91, </strong>which shows that these two attributes are highly co-related to each other. In more simple words, the value of size_uniformity increases when the value of shape_uniformity increases,had it been<strong> -0.91 </strong>again they are highly co-related but this time one increases when another decreases.</p><p>3. Let’s play with other attributes as well…using a <strong><em>bar plot.</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/791b869814e84ad590547bca955c9ae0/href">https://medium.com/media/791b869814e84ad590547bca955c9ae0/href</a></iframe><p>Before I show you the output, try to visualise it. I am taking a column (bland_chromatin) on X axis and trying to predict the outputs on Y axis. That means I’ll get a graph which will shows how many people of each category in bland_chromatin will fall in class 2 or class 4….remember…class 2 means patient is in early stages of cancer while class 4 is malevolent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*T1xZIZQKe0PYrcqQHgEHkA.png" /></figure><p><strong>Observation </strong>: From the graph it is clear to me that when Bland Chromatin is in range in either 1 ,2 ,or 3. The 150,160,130 no. of patient are in benign stage but as soon as the ranges exceeds from 3 to 7 , it is seen that the no of patient are falling in danger situation but still few cases are safe. Once range exceeds 7, it is found no patient was in safe state and hence range 8 ,9 and 10 there were no case who was safe.</p><p>4. <strong>How does all that help?</strong></p><p>Many machine learning projects fail, some succeed. What do you think is the main difference?</p><p><strong>Features</strong> used — have to be the most important factor.</p><p>That’s what any Machine Learning algorithm is trying to do — learn a set of features, so that it can make an accurate prediction based on that.</p><p>So let me quickly put all the story in few lines……</p><ol><li>gain an intuition to what could be a good algorithm to start off with</li><li>helps us in <strong>Feature Engineering</strong> to come up with new features (when the 1st attempt gives unsatisfactory results, which it will, almost all the time)</li><li>helps us develop a mental model in our minds, of what kind of data and problem we are dealing with — this helps us make better decisions throughout the process, <strong>instead of just shooting in the dark and praying something groundbreaking comes out</strong>.</li></ol><p>You can access the complete code and the dataset <a href="https://github.com/jainanchit51/datascience/tree/master/data_analysis/data_visualization">here</a></p><p>Thanks you for your patience …..<strong>Claps (Echoing)</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1053ea71781" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science-101/exploring-breast-cancer-data-set-b1053ea71781">Exploring Breast Cancer Data set</a> was originally published in <a href="https://medium.com/data-science-101">Data Science 101</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>