<?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 Pragya Sinha on Medium]]></title>
        <description><![CDATA[Stories by Pragya Sinha on Medium]]></description>
        <link>https://medium.com/@ps783937?source=rss-fce9c936f3b8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Kiu3pS7v8UyhjMcO</url>
            <title>Stories by Pragya Sinha on Medium</title>
            <link>https://medium.com/@ps783937?source=rss-fce9c936f3b8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 19:30:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ps783937/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[Data Science and Linear Algebra]]></title>
            <link>https://ps783937.medium.com/data-science-and-linear-algebra-97d7c6baa26c?source=rss-fce9c936f3b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/97d7c6baa26c</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[linear-algebra]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[datasciencecourse]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Pragya Sinha]]></dc:creator>
            <pubDate>Thu, 25 Feb 2021 20:27:08 GMT</pubDate>
            <atom:updated>2021-02-25T20:27:08.521Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ibdA31F6CZ8uEBpg.jpg" /></figure><p>Anyone who wants to grow as a Data Scientist should know maths. The first thing which comes up is Data Science which is used in various application such as:</p><ul><li>Recommending a movie for you to watch on Netflix, product on an ecommmerce store etc.</li><li>Forecasting company sales and profits</li><li>The ithelpdesk can be automated by analysing the issues</li><li>Suggesting a song to add to your playlist</li></ul><p>So how does Mathematics fit into this?</p><p>Mathematics is a branch which is used from the very beginning since data collection, analysis to te final stages of interpretation and presentation..</p><p>Here I have discussed one of the branch of mathematics used in Data Science</p><h3>LINEAR ALGEBRA</h3><p>Linear algebra is behind all the powerful machine learning algorithms we are so familiar with. It’s all widespreading. It can open doors for anyone to understand and manipulate data , which you have never thought of before. You would also be able to code and model from scratch and . Isn’t that’s why we have immense interest in this field and we enjoy doing this? The potential to experiment and play around with our models? Consider linear algebra as the key to unlock a magical world.</p><p>We are all quite familar to the Regression models, say Linear Regression.</p><p>We start for a linear function, use it on the independent features in our dataset and predict an output for the target feature. But wait, How do you calculate the difference between the actual and predicted value. Obviously, the <strong>Loss function</strong> is used. It is just the application in the vector form</p><ol><li>Manhattan Distance: The <strong>distance</strong> between two points measured along axes at right angles. In a plane with p1 at (x1, y1) and p2 at (x2, y2), it is |x1 — x2| + |y1 — y2|</li><li>Euclidean Distance: The length of a line segment between the two points. It can be calculated from the Cartesian coordinates of the points using the Pythagorean theorem.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/0*SR3MigtKVHYLQeTb" /></figure><p>To calculate MSE, you take the difference between your predictions and the ground truth, square it, and average it out across the whole dataset.In the same way in RMSE and all other metrics we use algebra behind this.</p><p><strong>Regularisation:</strong></p><p>This is the another example of the application of linear algeabra. It is method through which we prevent our model from overfitting. Overfitting happens when our the training data fits very well but when the model is applied to a new data set , it causes error due to the noice in the dataset. Regularization penalizes overly complex models by adding the norm of the weight vector to the cost function.</p><p>There are different ways : Lasso Regression and Ridge Regression</p><p>A simple relation for linear regression looks like this. Here Y represents the learned relation and <em>β represents the coefficient for different features</em></p><p><strong><em>Y ≈ β0 + β1X1 + β2X2 + …+ βpXp.</em></strong>The coefficients are chosen in such a way that they minimize this loss function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*YLey1cLLorfdVhqo" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/0*zumQmG0eJK4ydgRj.png" /></figure><p>Now, this will adjust the coefficients based on your training data. <em>If there is noise in the training data, then the estimated coefficients won’t generalize well to the future data. This is where regularization comes in and shrinks or regularizes these learned estimates towards zero.</em></p><h4>Ridge Regression</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*u7x7RzXSpk4DZ-lS" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/0*0EKr-oqUYObsmbtU.png" /></figure><p>Above image shows ridge regression, where the <em>RSS is modified by adding the shrinkage quantity.</em> Now, the coefficients are estimated by minimizing this function. Here, <em>λ is the tuning parameter that decides how much we want to penalize the flexibility of our model.</em> The increase in flexibility of a model is represented by increase in its coefficients, and if we want to minimize the above function, then these coefficients need to be small. This is how the Ridge regression technique prevents coefficients from rising too high. Also, notice that we shrink the estimated association of each variable with the response, except the intercept β0, This intercept is a measure of the mean value of the response when xi1 = xi2 = …= xip = 0.</p><p><em>When λ = 0, the penalty term has no eﬀect</em>, and the estimates produced by ridge regression will be equal to least squares. However, <em>as λ→∞, the impact of the shrinkage penalty grows, and the ridge regression coeﬃcient estimates will approach zero</em>. As can be seen, selecting a good value of λ is critical. Cross validation comes in handy for this purpose. The coefficient estimates produced by this method are <em>also known as the L2 norm</em>.</p><p><em>The coefficients that are produced by the standard least squares method are scale equivariant</em>, i.e. if we multiply each input by c then the corresponding coefficients are scaled by a factor of 1/c. Therefore, regardless of how the predictor is scaled, the multiplication of predictor and coefficient(Xjβj) remains the same. <em>However, this is not the case with ridge regression, and therefore, we need to standardize the predictors or bring the predictors to the same scale before performing ridge regression</em>. The formula used to do this is given below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*QlwXHh7RmAdKB6r2" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/281/0*rQp7P046wAkUy15_.png" /></figure><h4>Lasso</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*V6Hokp9OHXN3ownb" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/0*sqaS72oX2xXOLStc.png" /></figure><p>Lasso is another variation, in which the above function is minimized. Its clear that <em>this variation differs from ridge regression only in penalizing the high coefficients</em>. It uses |βj|(modulus)instead of squares of β, as its penalty. In statistics, this is<em> known as the L1 norm</em>.</p><p>Lets take a look at above methods with a different perspective. <em>The ridge regression can be thought of as solving an equation, where summation of squares of coefficients is less than or equal to s</em>. And <em>the Lasso can be thought of as an equation where summation of modulus of coefficients is less than or equal to s</em>. Here, s is a constant that exists for each value of shrinkage factor <em>λ. These equations are also referred to as constraint functions.</em></p><p><em>Consider their are 2 parameters in a given problem</em>. Then according to above formulation, the <em>ridge regression is expressed by β¹² + β²² ≤ s</em>. This implies that <em>ridge regression coefficients have the smallest RSS(loss function) for all points that lie within the circle given by β¹² + β²² ≤ s.</em></p><p>Similarly, <em>for lasso, the equation becomes,|β1|+|β2|≤ s</em>. This implies that <em>lasso coefficients have the smallest RSS(loss function) for all points that lie within the diamond given by |β1|+|β2|≤ s.</em></p><p>Covariance Matrix:</p><p>When we are performing EDA and visualising our dataset, we want to know the relationship between two variables. Covariance is the measure used to study the relationship between two variables. But now we will think this is statistics , how linear algebra is involved in this. But then I told you before that linear algebra is a key to unlock everything. Using the concept of transpose and matrix multiplication we can calculate the covariance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/201/0*0WXRn1l43JMfqKzp.jpg" /></figure><p><strong>SVM</strong></p><p>Support Vector Machine (SVM) is one of the most powerful out-of-the-box supervised machine learning algorithms. It is the application of the vector spaces in Linear Algebra.</p><p>In this algorithm, we plot each data item as a point in an <strong>n-dimensional space</strong> (where n is the number of features we have) with the value of each feature being the value of a particular coordinate. Then, we perform classification by finding the <strong>hyperplane</strong> that differentiates the two classes very well .</p><p>The vectors (cases) that define the hyperplane are the support vectors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/0*B-bjlxVGSA7WKr3l.png" /></figure><p><strong>Algorithm</strong></p><ol><li>Define an optimal hyperplane: maximize margin</li><li>Extend the above definition for non-linearly separable problems: have a penalty term for misclassifications.</li><li>Map data to high dimensional space where it is easier to classify with linear decision surfaces: reformulate problem so that data is mapped implicitly to this space.</li></ol><p>To define an optimal hyperplane we need to maximize the width of the margin (<em>w</em>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/0*IJmymWaNGu368U1v.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/0*-_PGY90_9N-P5WY2.png" /></figure><p>We find <em>w</em> and <em>b</em> by solving the following objective function using Quadratic Programming.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/239/0*JgpJ9QAgnohi8Ml3.png" /></figure><p>The beauty of SVM is that if the data is linearly separable, there is a unique global minimum value. An ideal SVM analysis should produce a hyperplane that completely separates the vectors (cases) into two non-overlapping classes. However, perfect separation may not be possible, or it may result in a model with so many cases that the model does not classify correctly. In this situation SVM finds the hyperplane that maximizes the margin and minimizes the misclassifications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/0*6FR8g-ohy2Y2RyWt.png" /></figure><p>The algorithm tries to maintain the slack variable to zero while maximizing margin. However, it does not minimize the number of misclassifications (NP-complete problem) but the sum of distances from the margin hyperplanes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/0*I_GNwbUkrKgsDAWj.png" /></figure><p>The simplest way to separate two groups of data is with a straight line (1 dimension), flat plane (2 dimensions) or an N-dimensional hyperplane. However, there are situations where a nonlinear region can separate the groups more efficiently. SVM handles this by using a kernel function (nonlinear) to map the data into a different space where a hyperplane (linear) cannot be used to do the separation. It means a non-linear function is learned by a linear learning machine in a high-dimensional feature space while the capacity of the system is controlled by a parameter that does not depend on the dimensionality of the space. This is called <em>kernel trick</em> which means the kernel function transform the data into a higher dimensional feature space to make it possible to perform the linear separation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/0*W9sGFZFkxArJMNic.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/0*3f38KtEAsRKvxuy4.png" /></figure><p>Map data into new space, then take the inner product of the new vectors. The image of the inner product of the data is the inner product of the images of the data.</p><p><strong>PCA</strong></p><p>This is the algorithm used to for dimension reduction. PCA finds the <strong>directions of maximum variance</strong> and projects the data along them to reduce the dimensions. The direction here are the eigenvectors of the covariance matrix. An eigenvector or characteristic vector of a linear transformation is a nonzero vector that changes by a scalar factor when that linear transformation is applied to it.( direction does not chnage)</p><h4>Dealing with textual data</h4><p>Machine learning algorithms cannot work with raw textual data. We need to convert the text into some numerical and statistical features to create model inputs. There are many ways for engineering features from text data, such as:</p><ol><li>Meta attributes of a text, like word count, special character count, etc.</li><li>NLP attributes of text</li><li>Word Vector Notations or Word Embeddings</li></ol><p>Word Embeddings is a way of representing words as <strong>low dimensional vectors</strong> of numbers while preserving their context in the document. These representations are obtained by training different neural networks on a large amount of text which is called a <strong>corpus</strong>. They also help in analyzing syntactic similarity among word.</p><p><strong>Dealing with images</strong></p><p>The image is a beautiful representation of the neural network, but how a computer can understand this. In a computer, the layers of the neural network are represented as vectors. A digital image is a two-dimensional discrete function, 𝑓(𝑥, 𝑦) with (𝑥, 𝑦) ∈ 𝕫 2 , where each pair of coordinates is called a pixel. The word pixel derived from English “picture element” determines the smallest logical unit of visual information used to construct an image. Without loss of generality one image can be represented by a matrix where each element 𝑖𝑗 corresponds to the value of the pixel image position (𝑖,𝑗).</p><p>These are the some of the applications of Linear Algebra in Data Science and these are just some as i said, there are a lot more.</p><p>Thank You,</p><p>Author: Pragya Sinha</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97d7c6baa26c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Customer- Management System]]></title>
            <link>https://ps783937.medium.com/customer-management-system-fc35e62c6439?source=rss-fce9c936f3b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc35e62c6439</guid>
            <category><![CDATA[naive-bayes]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[multinomialnb]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[consumer-compalints]]></category>
            <dc:creator><![CDATA[Pragya Sinha]]></dc:creator>
            <pubDate>Tue, 23 Feb 2021 17:11:10 GMT</pubDate>
            <atom:updated>2021-02-23T17:12:58.405Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qxP51fAbl4scopLi0ciMNg.png" /><figcaption>Complaint- management</figcaption></figure><p>If you are sitting on a company’s service desk, you might know how hectic it is to identify the issue and route it to the corret team. Even the customer doesn’t get the correct information on which team is woring in it. In this article we will discuss a model where the customer complains about the issue they are facing with the bank.</p><p><strong>Objectives</strong>:</p><ol><li>Finding the important statistical analysis by exploring the data by performing EDA.</li><li>Building the ML model to predict the complaint &amp; the department which should be handling it.</li><li>To build a Web Application for registration of complaints by the uses.</li><li>Database to which all the data is stored.</li></ol><p><strong>Importing the necssary libraries:</strong></p><p>import numpy as np<br>import pandas as pd<br>import matplotlib.pyplot as plt<br>import seaborn as sns<br>%matplotlib inline<br>pd.set_option(‘display.max_columns’,None)</p><p>import warnings<br>warnings.filterwarnings(‘ignore’)</p><p><strong>Importing the dataset:</strong></p><p>df1 = pd.read_csv(‘complaints.csv’)</p><p>The dataset I have used contains of 13 coulums .</p><pre>[&#39;Date received&#39;, &#39;Product&#39;, &#39;Sub-product&#39;, &#39;Issue&#39;, &#39;Sub-issue&#39;,<br>       &#39;Consumer complaint narrative&#39;, &#39;Company public response&#39;,<br>       &#39;Submitted via&#39;, &#39;Date sent to company&#39;, &#39;Company response to consumer&#39;,<br>       &#39;Timely response?&#39;, &#39;Consumer disputed?&#39;, &#39;Complaint ID&#39;],<br>      </pre><p>We will check the missing values:</p><pre>Date received                        0<br>Product                              0<br>Sub-product                     235160<br>Issue                                0<br>Sub-issue                       477597<br>Consumer complaint narrative    704013<br>Company public response         646002<br>Submitted via                        0<br>Date sent to company                 0<br>Company response to consumer         0<br>Timely response?                     0<br>Consumer disputed?              135408<br>Complaint ID                         0</pre><p>So we can see the columns which have null values in it.</p><p>We have also renamed the two culumns Timely response? and Cosnsumer Disputed?</p><p>df2 = df1.rename(columns={‘Timely response?’:’Timely response’, ‘Consumer disputed?’:’Consumer disputed’})</p><p>After exploring the dataset, lets move to EDA and gather some insights from our data.</p><p>The various insigths gathered are:</p><p>a. Most favoured way to file a complaint is through ‘Web’ portal.<br>b. ‘Email’ is the least preferred way to register a complaint.</p><pre>Company gave timely response to 97.28 % users.<br>Company was unable to provide timely response to 2.72 % users.</pre><p>We have alo converted the column with date in date-time format and separed year and month as two differnt columns</p><p>Complains regitstered according to year were:</p><p>year</p><p>2017 207778</p><p>2016 191505</p><p>2015 168520</p><p>2014 153053</p><p>2013 108218</p><p>2012 72373</p><p>2011 2536</p><ol><li>The analysis shows that Complaints increased with every year.</li><li>In Mathematical sense, there is a direct relationship between Complaints registered vs Year.</li></ol><p>We have merged the products to reduce the number odf Departments:</p><p>df2[‘product’][df2[‘product’] == ‘Money transfer, virtual currency, or money service’] = ‘Money transfers’<br>df2[‘product’][df2[‘product’] == ‘Prepaid card’] = ‘Credit card or prepaid card’<br>df2[‘product’][df2[‘product’] == ‘Credit card’] = ‘Credit card or prepaid card’<br>df2[‘product’][df2[‘product’] == ‘Virtual currency’] = ‘Other financial service’<br>df2[‘product’][df2[‘product’] == ‘Payday loan’] = ‘Payday loan, title loan, or personal loan’<br>df2[‘product’][df2[‘product’] == ‘Credit reporting’] = ‘Credit reporting, credit repair services, or other personal consumer reports’</p><p>Also merge the columns related to complaints into a single columns:</p><p>df2[‘updated_complaint_narrative’] = df2[[‘issue’,’sub-issue’,’consumer complaint narrative’]].apply(lambda x:’’.join(x.astype(str)), axis=1)</p><p>After that remove the unwanted columns in the dataset.</p><p>Now to build our model we have used just two culumns because our main aim is to direct the complain to the correcct department.</p><p>Columns used: product and updated_complaint_narrative</p><p><strong>Imported the required libraries for ML building:</strong></p><p>from sklearn.pipeline import Pipeline<br>from sklearn.model_selection import train_test_split<br>from sklearn.feature_extraction.text import CountVectorizer<br>from sklearn.feature_extraction.text import TfidfTransformer<br>from sklearn.naive_bayes import MultinomialNB <br>from sklearn.metrics import confusion_matrix</p><p><strong># creating the pipeline.</strong><br>model_pipeline = Pipeline([<br> (‘vect’, CountVectorizer()),<br> (‘tfidf’, TfidfTransformer()),<br> (‘nb’, MultinomialNB())<br>])</p><pre>The score of the Training data is:- 94.0242040753114<br>The score of the Testing data is:- 93.84073552207106</pre><pre><em># splitting the data into 80% &amp; 20%.</em></pre><pre>X_train, X_test, y_train, y_test <strong>=</strong> train_test_split(df3[&#39;updated_complaint_narrative&#39;], df3[&#39;product&#39;], test_size<strong>=</strong>0.8, random_state <strong>=</strong> 0)</pre><pre>print(&#39;The size of Input Training data:-&#39;, X_train.shape)</pre><pre>print(&#39;The size of Output Training data:-&#39;, y_train.shape)</pre><pre>print(&#39;The size of Input Testing data:-&#39;, X_test.shape)</pre><pre>print(&#39;The size of Output Testing data:-&#39;, y_test.shape)</pre><pre>The size of Input Training data:- (180796,)<br>The size of Output Training data:- (180796,)<br>The size of Input Testing data:- (723187,)<br>The size of Output Testing data:- (723187,)</pre><pre>model_pipeline.fit(X_train, y_train)</pre><p>Out[46]:</p><pre>Pipeline(steps=[(&#39;vect&#39;, CountVectorizer()), (&#39;tfidf&#39;, TfidfTransformer()),<br>                (&#39;nb&#39;, MultinomialNB())])</pre><p>In [47]:</p><pre>training_score <strong>=</strong> model_pipeline.score(X_train, y_train)</pre><pre>testing_score <strong>=</strong> model_pipeline.score(X_test, y_test)</pre><pre>​</pre><pre>print(&#39;The score of the Training data is:-&#39;, (training_score)<strong>*</strong>100)</pre><pre>print(&#39;The score of the Testing data is:-&#39;, (testing_score)<strong>*</strong>100)</pre><pre>The score of the Training data is:- 94.0242040753114<br>The score of the Testing data is:- 93.84073552207106</pre><pre>new_complaint <strong>=</strong> [&quot;This company refuses to provide me verification and validation of debt per my right under the FDCPA. I do not believe this debt is mine.&quot;]</pre><pre>print(model_pipeline.predict(new_complaint))</pre><pre>[&#39;Debt collection&#39;]</pre><pre><em># save the model</em></pre><pre><strong>import</strong> pickle</pre><pre>pickle.dump(model_pipeline, open(&quot;complaint_nb_model.pkl&quot;, &#39;wb&#39;))</pre><p>Finally the model is saved as a pickle file.</p><p>Now we will proceed to the build the web application. Here I have used flask and deployed in Heroku.</p><p>The main file is app.py . Here the model is loaded and the web application and the data base is connected . To get the complete code and description of this please go through</p><p><a href="https://github.com/pragya2502/CMS">pragya2502/CMS</a></p><p>and the app is deployed on: <a href="https://customer-mgment-system.herokuapp.com/">https://customer-mgment-system.herokuapp.com/</a></p><p>Author:<strong> Pragya Sinha</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc35e62c6439" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>