<?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 Rahul Vamusani on Medium]]></title>
        <description><![CDATA[Stories by Rahul Vamusani on Medium]]></description>
        <link>https://medium.com/@rahul.vamusani98?source=rss-d19fdcc9ac69------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Jt3FCxoQX82ED0To.</url>
            <title>Stories by Rahul Vamusani on Medium</title>
            <link>https://medium.com/@rahul.vamusani98?source=rss-d19fdcc9ac69------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 06:53:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rahul.vamusani98/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[Implementation of RNN’s in Text Classification Tasks]]></title>
            <link>https://medium.com/@rahul.vamusani98/implementation-of-rnn-in-text-classification-tasks-172f745a1584?source=rss-d19fdcc9ac69------2</link>
            <guid isPermaLink="false">https://medium.com/p/172f745a1584</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[rnn]]></category>
            <category><![CDATA[lstm]]></category>
            <category><![CDATA[text-classification]]></category>
            <category><![CDATA[recurrent-neural-network]]></category>
            <dc:creator><![CDATA[Rahul Vamusani]]></dc:creator>
            <pubDate>Sat, 16 Jun 2018 13:58:29 GMT</pubDate>
            <atom:updated>2018-06-16T14:16:56.829Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*Ebo78foGYB1WNN8iD0_Cmw.png" /></figure><h4><strong>Why RNN’s are good for Text Classification ?</strong></h4><p>In case of text classification tasks the sequence information is important for interpreting the class of the text. This sequence information is captured by RNN’s. This results in more accurate classification of the text data.</p><p>There are many variations of RNN’s likely <strong>Many-One, Many-Many, bidirectional, </strong>In this case the aim is classify the input text into <strong>positive</strong> and <strong>negative</strong> class. So, set of <strong>Many-One LSTM </strong>units achieves the task as only one value needs to be outputted for determining the <strong>polarity </strong>of the review.</p><h4><strong>WorkFlow of RNN’s implementation on Text Data.</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4wgWbib-yvBtgPkAHeR39Q.png" /></figure><h3><strong>Various stages involved:</strong></h3><h4><strong>Stage 1 — Acquiring the data:</strong></h4><p>There is not much interesting happening at this stage. In this stage the data is present in the form of sentences, each sentence has its label <strong>positive(0) </strong>and<strong> negative(1). </strong>The data exists as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*BHTJ7TEb1gqwBqAzt4D75Q.png" /><figcaption>Sample Dataset</figcaption></figure><p>Here the <strong>data </strong>column represents the <strong>review text </strong>of a movie and the <strong>label </strong>indicates whether the review is <strong>0-positive </strong>or <strong>1-negative. </strong>Here, It is to be noticed that the review is of <strong>arbitrary</strong> length. This data will be converted to equal length of sentence vectors in further stages.</p><h4><strong>Stage 2 — Building Sentence vectors :</strong></h4><p>This stage is the <strong>most important</strong> stage in the workflow. In this stage the <strong>Text</strong> data is converted to numerical <strong>sentence vectors. </strong>The data that is obtained in <strong>Stage</strong> <strong>1 </strong>is passed to <strong>Stage 2</strong>. There are several steps in conversion of<strong> text to sentence vectors</strong></p><p><strong><em>Step -1: </em></strong>The data is being tokenized to set of words and each word occurrences in the whole text corpus is obtained as seen in the figure the frequency of each corresponding word is noted.</p><p><strong><em>Step-2:</em></strong> The obtained word frequencies are ranked based on the number of occurrences. The word with highest number of occurrences is given highest rank and vice versa. Two words can have same rank, In this case the two different words are treated <strong>one </strong>and<strong> the same</strong>. A look up table is constructed based on the rank of each word. This lookup table is used in further stages of the workflow.</p><p><strong><em>Step-3: </em></strong>In this step the sentence vectors are constructed for each of the review in the dataset, this vectors are constructed by referring the look up table for each word that is constructed in previous stage to obtain the rank. <strong>There is one point to note, each of the vectors are not same length.</strong></p><h4><strong>Stage 3 — Building equal Length of Sentence Vectors:</strong></h4><p>In this stage the vectors are converted to <strong>same length</strong> by padding with <strong>zeros </strong>at the starting (pre-padding) to achieve equal length sentence vectors, this helps in better learning process.</p><p><strong><em>Why not train different length sentence vectors?</em></strong></p><p><em>In this case, the vectors are of different length. This makes the</em><strong><em> process of Learning weights of </em></strong><em>arbitrary length</em><strong><em> </em></strong><em>difficult. This is a computational hack to speed up the learning process of </em><strong><em>LSTM</em></strong><em> recurrent networks.</em></p><p>Here equal length vectors of each sentence are obtained. These<strong> sentence vectors</strong> are passed to next stage.</p><h4><strong>Stage 4 — Converting the Sentence Vectors:</strong></h4><p>In this stage <strong>embedding layer</strong> is used to convert the sentence vectors matrix into embedded sentence vector matrix as follows:</p><p>(<strong>number of sentences * length of sentences) → (number of sentences * length of sentence * output dimension)</strong></p><p>Here each <strong>word </strong>with single value<strong> </strong>in the sentence vector will be converted to a <strong>vector.</strong></p><p><strong><em>Why use embedding layers in case of Text data?</em></strong></p><ol><li><strong><em>Embedding layer</em></strong><em> is used to learn sentence vectors as the part of deep learning model itself.</em></li><li><em>It also allows to load </em><strong><em>pre-trained</em></strong><em> word embedding model.</em></li></ol><p>Embedding layer is part of data preparation tasks for RNN. After this stage the <strong>Word Embeddings </strong>and <strong>Sentence</strong> <strong>Labels </strong>of the Review are sent to <strong>next stage.</strong></p><h4><strong>Stage 5 — Budilding the model:</strong></h4><p><strong>Building the Deep Learning Model:</strong></p><p>In this stage <strong>Deep Learning Model </strong>is being built<strong>. </strong>The model consists of <strong>100 LSTM </strong>cells in parallel. Each <strong>LSTM </strong>Cell accepts the same data.</p><p>Each LSTM outputs one value (Many-One). Therefore, <strong>100</strong> values are being outputted. These <strong>100 </strong>values<strong> </strong>are passed to <strong>one sigmoid </strong>unit. This <strong>sigmoid</strong> unit gives the polarity of the review (value between <strong>0–1</strong>).</p><h4><strong>Stage 6</strong> — Defining the Parameters to Train the model<strong>:</strong></h4><p><strong>Defining the training parameters:</strong></p><p>In this stage the training parameters are defined to train the model with the following parameters:</p><p><strong><em>Metric = “Accuracy”</em></strong></p><p>Accuracy is the metric that measures the correctness of the deep Learning model.</p><p><strong><em>Loss = “Binary CrossEntropy”</em></strong></p><p>As this is a binary classification task, “Binary Cross Entropy” is the appropriate loss measure that is used to calculate the errorness of the model.</p><p><strong><em>Optimizer = “Adam”</em></strong></p><p>Optimizer is the key for minimizing the <strong>loss</strong> in any deep learning model, <strong>Adam </strong>is an adaptive learning rate algorithm that minimizes the <strong>loss </strong>and increase the<strong> accuracy </strong>of the model.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=172f745a1584" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ML Fundamentals — Handling Missing values]]></title>
            <link>https://medium.com/@rahul.vamusani98/ml-fundamentals-handling-missing-values-1c9370a4d1e?source=rss-d19fdcc9ac69------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c9370a4d1e</guid>
            <category><![CDATA[model-based-imputation]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[handling-missing-values]]></category>
            <category><![CDATA[data-pre-processing]]></category>
            <dc:creator><![CDATA[Rahul Vamusani]]></dc:creator>
            <pubDate>Tue, 06 Mar 2018 17:38:45 GMT</pubDate>
            <atom:updated>2018-04-26T07:36:55.378Z</atom:updated>
            <content:encoded><![CDATA[<p>I would like to start this article mentioning the challenges in handing and preprocessing the <strong>real world data.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/363/1*kvzZXSsbe7Ce3Fs0Lm1fng.png" /><figcaption><em>Pima Indians Diabetes dataset</em></figcaption></figure><p><em>Throughout this article we are going to work on the above dataset: </em><a href="https://archive.ics.uci.edu/ml/datasets/Pima+Indians+Diabetes"><em>Click Here </em></a><em>to download the dataset.</em></p><p><strong><em>How does the real world data exist ?</em></strong></p><p>Most of the data is being extracted from various sources namely from traditional databases, real time data (sensor data), manual survey data, sound data, sequential data (gene data) and so on..</p><p><strong><em>What all can go wrong when working with data?</em></strong></p><p>The data can be corrupted in many ways at any of the levels that may be during storing, recording, maintaining and also during performing operations on the data.</p><p>Here are some of the cases -</p><ul><li><strong>Sensor data: </strong>In case of sensor data errors can occur due to the malfunction of the sensors this leads to several inconsistencies, let us consider an intelligent system that senses the room temperature<strong>. </strong>The device may output the room temperature is 1000 degrees celsius(or some random value) due to some malfunction which is completely wrong. This type of data may be recorded in the databases.</li><li><strong>Survey data: </strong>The data can be corrupted during the survey by improper entry of values, leaving the data field and many human errors. While transferring the data to some permanent databases there are chances data types and data field mismatch and that may lead to inconsistencies such as ignoring the values that are not valid and the actual data may be transformed.</li></ul><p>These are some of the real world examples that make data errornoes.</p><p>Let’s discuss the statergies of handing missing values in the data.</p><h3><strong>Missing values in the data:</strong></h3><p>Missing values are very commonly observed in the dataset they can be seen as Nan, “-”, &lt;blank space&gt; and so on, handling the missing values is crucial when working with data this increases the quality of the dataset.</p><h4>Handling the missing values —</h4><h4><strong>Why don’t you fill the missing values with some random number </strong>?</h4><p>Filling the missing values with some random number can cause some serious errors in the dataset. The random value can be an outlier data point and this effect few machine learning algorithms to go wrong by fitting the algorithm to the outlier that can lead to wrong interpretations. This is one of the problems of random number imputation.</p><h4><strong>How does a responsible data person* handle the missing values in the data ?</strong></h4><p>These are the popular ways of handling the missing values in the dataset.</p><ul><li><strong>Imputation with an appropriate value : </strong>This is the most often way of handling missing values. The missing values in the data are filled with the mean, median or mode values of the feature that has missing values in case of tabular dataset. The advantage of this technique is it doesn’t affect the distribution of the data. Since, the distribution is not much affected the nature of the data is preserved mostly. There is a modification to this type of imputation, the missing values can be filled by the mean, median and mode of the missing value feature by grouping the data on the class of the data in case of classification problem.</li><li><strong>Model based imputation : </strong>This type of imputation is done by predicting the missing values with a simple machine learning regression algorithms if the missing value feature is real valued and classification algorithms in case of the feature is a classification. The observations that contain missing values are made as test data and the observations that does not contain missing values as training data for the algorithm to predict the missing value. The value that is being predicted is nothing but the weight(W) value/vector that is learned by the linear regression algorithm by minimizing the loss on training data.</li><li><strong>Forward/backward filling of missing values:</strong> This is the more general technique, the missing value in an observation is filled by the preceding value of the observation in the dataset. In the same way backward filling is done by filling with the value of the observation that is after the missing value observation in the dataset. This technique is not the most effective way of imputation.</li><li><strong>Manual entry of missing values: </strong>In this technique the missing values are filled with the help of the domain expert of the dataset. The appropriate value is filled to the knowledge of domain expert.</li><li><strong>Making new features: </strong>The new features can be made in the dataset where the values are missing, that will be the indication of the values that are missing in the dataset.</li></ul><p><strong>Note</strong><em>: These are the general techniques of handling missing values, this is highly dependent on the type of data working on.</em></p><p>Let’s work on the case study of handling missing values in <strong>‘Pima Indians Diabetes’ </strong>Dataset<strong>.</strong></p><p><strong>Case study:</strong></p><p>As mentioned the dataset we are going to work on is the <strong>Pima Indians Diabetes </strong>dataset. The missing values in the dataset are mentioned as “0”. The attributes of the dataset are follows</p><pre>   A. Number of times pregnant<br>   B. Plasma glucose concentration a 2 hours in an oral glucose      tolerance test<br>   C. Diastolic blood pressure (mm Hg)<br>   D. Triceps skin fold thickness (mm)<br>   E. 2-Hour serum insulin (mu U/ml)<br>   F. Body mass index (weight in kg/(height in m)^2)<br>   G. Diabetes pedigree function<br>   H. Age (years)<br>   I. Class variable (0 or 1)</pre><p><strong><em>Summary of the dataset —</em></strong></p><pre>import pandas as pd<br>import missingno as ms<br>import numpy as np</pre><pre>df = pd.read_csv(&quot;pima-indians-diabetes.csv&quot;)<br>df_i = df[&quot;I&quot;]<br>df.columns = [&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;, &quot;E&quot;, &quot;F&quot;, &quot;G&quot;, &quot;H&quot;, &quot;I&quot;]<br>df.describe()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*wwLdO7C_r5ThdZWFHPKq2A.png" /></figure><p><strong><em>Let’s visualize the missing values in the dataset —</em></strong></p><p>The white spaces in the dataset are the missing values in the dataset, the <strong>class </strong>attribute is removed for convenience.</p><pre>col = list(df.columns)<br>data = df[col[0:-1]]<br>data.replace(0, np.nan, inplace=True)<br>ms.matrix(data)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pQ_bgAtLSyufIHxtsHI5Jw.png" /></figure><p>Seems there are more missing values in the dataset, from the visualization it is evident that the attribute <strong>D</strong> and <strong>E</strong> have more number of missing values than the other attributes in the dataset.</p><p>As there are more number of missing values in the attributes <strong>D </strong>and <strong>E, </strong>We can drop these attributes because this attributes are most likely that it does not contribute for the modelling of machine learning algorithms. This can be the approach of treating the very sparse attributes in the dataset, though there is loss of information this could be the approach.</p><pre>data.drop([&quot;D&quot;, E&quot;], axis=1, inplace= True)<br>ms.matrix(data)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6FKa4cId0Yy5U79UNOBHUA.png" /></figure><p>Now, that we have removed the attributes that are very sparse.</p><p>The missing values in the attributes &lt;A, C, F&gt; can be imputed with the mean of their attributes.</p><pre>data[&quot;A&quot;].fillna(data[&quot;A&quot;].mean(), inplace=True)<br>data[&quot;C&quot;].fillna(data[&quot;C&quot;].mean(), inplace=True)<br>data[&quot;F&quot;].fillna(data[&quot;F&quot;].mean(), inplace=True)<br>ms.matrix(data)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GHOA31w6kkUN22QakvWiOQ.png" /></figure><p>Now, we have imputed the missing values in the attributes by mean values.</p><p>For the attribute <strong>B </strong>the missing values can be handled using <strong>model based imputation.</strong></p><p><strong>Model based imputation:</strong></p><p><strong>Procedure:</strong></p><p><strong><em>Step-1</em></strong><em>: </em>Make the attribute&lt;B&gt; as the predictor variable.</p><p><strong><em>Step-2</em></strong>: Split the dataset that contains the missing values and no missing values are test and train respectively.</p><pre>data.replace(np.nan,0, inplace=True)</pre><pre>x_train = data[data[&quot;B&quot;] != 0]<br>y_train = data[data[&quot;B&quot;] != 0]<br>x_test = data[data[&quot;B&quot;] == 0]<br>y_test = data[data[&quot;B&quot;] == 0]<br>x_train = x_train[[&quot;A&quot;, &quot;C&quot;, &quot;F&quot;, &quot;G&quot;, &quot;H&quot;]]<br>x_test = x_test[[&quot;A&quot;, &quot;C&quot;, &quot;F&quot;, &quot;G&quot;, &quot;H&quot;]]<br>y_train = y_train[[&quot;B&quot;]]<br>y_test = y_test[[&quot;B&quot;]]</pre><p><strong><em>Step-3</em></strong>: Train the machine learning algorithm like KNN regressor, It is the most widely used algorithm for imputation of missing values in the dataset.</p><pre>from sklearn.neighbors import KNeighborsRegressor</pre><pre>reg = KNeighborsRegressor(n_neighbors= 5)</pre><pre>reg.fit(x_train, y_train)</pre><pre>Output:</pre><pre>KNeighborsRegressor(algorithm=&#39;auto&#39;, leaf_size=30, metric=&#39;minkowski&#39;,<br>          metric_params=None, n_jobs=1, n_neighbors=5, p=2,<br>          weights=&#39;uniform&#39;)</pre><p><strong><em>Step-4</em></strong>: Predict the missing values in the attribute of the test data.</p><pre>predicted = reg.predict(x_test)<br>print(reg.predict(x_test))</pre><pre>Output:</pre><pre>array([[ 115. ],<br>       [ 101.6],<br>       [ 100.8],<br>       [ 128.6],<br>       [ 154.4]])</pre><p><strong><em>Step-5</em></strong><em>:</em></p><p>Let’s obtain the complete dataset by combining with the target attribute &lt;<strong>I</strong>&gt;.</p><pre>x_train = data[data[&quot;B&quot;] != 0]<br>y_train = data[data[&quot;B&quot;] != 0]<br>x_test = data[data[&quot;B&quot;] == 0]<br>y_test = data[data[&quot;B&quot;] == 0]</pre><pre>x_test[&quot;B&quot;] = predicted</pre><pre>data = pd.concat([x_train, x_test])<br>df = pd.concat([data, df_i], axis=1)</pre><p>These are the missing value imputation techniques that can be used for making the data more reliable.</p><p>The only goal of this article is to cover the various <strong>commonly</strong> used techniques that are used for handling missing values in the dataset.</p><p>The code for this article &lt;- <a href="https://github.com/RahulVamusani/Machine-learning/tree/master/Handling%20missing%20values"><em>Click here</em></a></p><p>* The person who works and deals with data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c9370a4d1e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>