<?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 Astha Sharma on Medium]]></title>
        <description><![CDATA[Stories by Astha Sharma on Medium]]></description>
        <link>https://medium.com/@astha-s15?source=rss-1996ba74e1b7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OirYXixMQrcdootzU1cMLA.png</url>
            <title>Stories by Astha Sharma on Medium</title>
            <link>https://medium.com/@astha-s15?source=rss-1996ba74e1b7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 00:35:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@astha-s15/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[Rethinking ATM Experiences : A User-Centric Approach]]></title>
            <link>https://astha-s15.medium.com/rethinking-atm-experiences-a-user-centric-approach-8f8c8c72220e?source=rss-1996ba74e1b7------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f8c8c72220e</guid>
            <category><![CDATA[ux-research]]></category>
            <category><![CDATA[atm-services]]></category>
            <category><![CDATA[product-design]]></category>
            <category><![CDATA[design-thinking]]></category>
            <category><![CDATA[ux-design]]></category>
            <dc:creator><![CDATA[Astha Sharma]]></dc:creator>
            <pubDate>Sun, 03 Mar 2024 02:55:12 GMT</pubDate>
            <atom:updated>2024-03-03T02:55:12.405Z</atom:updated>
            <content:encoded><![CDATA[<h3>Rethinking ATM Experiences : A User-Centric Approach</h3><figure><img alt="Image Source — Photo by Eduardo Soares on Unsplash" src="https://cdn-images-1.medium.com/max/1024/1*HA9hj2jmqLWjAuFz_Le6pA.jpeg" /><figcaption><strong>Image Source — Photo by </strong><a href="https://unsplash.com/@eduschadesoares"><strong>Eduardo Soares </strong></a><strong>on </strong><a href="https://unsplash.com/photos/person-holding-white-and-red-card-utWyPB8_FU8"><strong>Unsplash</strong></a></figcaption></figure><p>An ATM is something that is frequently used by many people around us. Even in this digital era where we are using some new technologies like online payments (UPI services) for different financial transactions and activities, we cannot deny the fact that ATM’s are still used for cash withdrawals as we are not at that stage yet where we are following a completely cashless economic model in India<strong><em> </em></strong>because cash has been one aspect of the financial sector that has become firmly rooted in our economy.</p><h4><strong>Some context…</strong></h4><p>I have experienced and seen many times my family, friends, and even strangers inside an ATM struggling with certain features of the system to get their work done, and they get disappointed and frustrated because of their bad experience. People often experience discomfort and fear when engaging in financial transactions due to the inherent risks involved. The persistent concern in their minds revolves around the potential consequences if something were to go wrong.</p><p>I have chosen to address this issue because I personally resonate with the challenges people face during financial transactions. I believe that making small changes in ATMs could significantly enhance users experience, fostering a sense of ease, assurance and confidence during any transaction.</p><p>As per understanding the description provided in the Design challenge I am re-defining the Problem statement to make it more specific</p><blockquote><strong>Re-defined Problem statement </strong>— Study the current design of the <strong><em>ATM in your locality</em></strong> and Re-design it to improve the User experience.</blockquote><p>Above problem statement helps me to understand more clearly that as of now I am going to focus only on the ATM in my locality because there are many different ATM’s out there and Not all of them have the same user interface and functionality to serve customers.</p><h4>Design thinking Process</h4><p>To solve this challenge I have followed the following Design process as it helps me to follow proper steps to organize my work and design better solutions to improve ATM experience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nN4nIjYXxGXikhTi1O4FXg.png" /><figcaption>Image taken from google</figcaption></figure><h4>Research</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kX3fs1S48PPbcOw-" /></figure><p><strong><em>Observation made — Pain point based on my experience :</em></strong></p><p>Here are some areas where user experience could be enhanced by addressing potential difficulties and improving interface intuitiveness.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vvVdg22S9p-rzYua" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ht8oZWikcbMT4jRz" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KAQQOoA8vXaqQvTQ" /><figcaption>These images are taken from near by ATM which cover the entire process of transaction <em>to understand the user’s interaction with the machine empathetically.</em></figcaption></figure><p><strong><em>Pain point based on user experience (Via interview process) :</em></strong></p><ol><li>Users have no way of knowing in advance if an ATM machine is out of cash or lacks specific denominations (such as 200 or 1000 notes) before initiating the withdrawal process. This results in users going through the entire process unnecessarily, leading to a waste of their time without any purpose.</li><li>The absence of an option to return to the previous menu makes people re-do the whole operation from the start and leading to more failed transaction and consuming additional time.</li><li>There is no option for card less transactions in case users forget or misplace their card.</li><li>The ATM often returns the card to users after the initial transaction, like cash withdrawal, requiring them to re-insert the card for additional actions such as withdrawing more cash or checking the balance. This extra step contributes to an increased duration of time spent by users at the ATM.</li><li>Language selection options should be on the very first screen.</li><li>The screen lacks instructions regarding whether users should swipe the card or keep it inserted until the transactions are completed.</li><li>Several ATMs request users’ phone numbers during transactions without providing information on the purpose or use of this information.</li></ol><p><strong><em>Based on my research I have made following assumptions :</em></strong></p><ol><li>Typically, individuals utilize ATMs primarily for cash withdrawals.</li><li>Certain users, particularly younger individuals, are infrequent ATM users, relying more on UPI payments. They may only use ATMs to pay in cash for specific services or items.</li><li>Users in their mid-age are familiar with digital payment systems but prefer cash transactions for mental satisfaction. They are frequent users of ATMs.</li><li>Elderly users, less acquainted with technology, rely more on ATMs for their financial transactions.</li></ol><h4>Define</h4><p>In this stage, I have analysed all my observations and feedback collected from the users in the research phase, which helped me to synthesize and define the results of my analysis into a clear design problem, like where I need to focus on, which functionalities should exist or be removed, and how errors can be handled.</p><p><strong><em>Identified and understood how might I improve the impacted areas :</em></strong></p><p>Following are some points which need to be highly focused on in order to improve users experience and to have more intuitive UI. Here I have brainstormed the possible solutions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aJ86UZm9AJy9wwWv" /></figure><p><strong><em>Few more things were considered while designing the solution :</em></strong></p><ol><li>Both card less and card transactions are essential, addressing distinct needs in the user experience.</li><li>Given the high frequency of cash withdrawals and balance inquiries, my current focus will be solely on optimizing these two transactions.</li><li>Recognizing varying levels of user familiarity, emphasis will be placed on making processes self-explanatory to minimize the need for assistance, especially from unfamiliar individuals, reducing potential risks during transactions.</li></ol><h4>Ideate and design</h4><p><strong><em>User flows :</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*h-b5eMfZwegjxCnl" /><figcaption>Current ATM User Flow (Before Re-design)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cA3F1_3dW_G60L2p" /><figcaption>Re-designed ATM User Flow</figcaption></figure><p><strong><em>Wireframes / Sketches :</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mjIr5THXjZ1w9RFk" /><figcaption>Wireframes for with card transactions</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3Z4iK2I0nJQfF6Ks" /><figcaption>Wireframes for card less transactions</figcaption></figure><p><strong><em>Things I have redesigned to improve user experience :</em></strong></p><ol><li>Display a message on the initial screen if the ATM is out of cash, providing users seeking withdrawals with immediate information to save time and effort.</li><li>Introduce card less transactions to assist users who forget or misplace their cards.</li><li>Furnish on-screen instructions to guide users seamlessly through the process, using a minimal number of screens for clarity.</li><li>Include a “back” button on screens to prevent users from restarting the entire process.</li><li>Simplify user interface by prominently featuring “withdrawal” and “balance enquiry” as the primary options, consolidating other functions under an “others” category.</li><li>Add an “on-screen balance” option for users who prefer viewing their available balance directly on the screen without a receipt.</li><li>Eliminate redundant screens requesting users’ phone numbers during card transactions for a more streamlined experience.</li></ol><p><strong><em>ATMs that I think are designed very well Vs the ATM I chose to improve :</em></strong></p><p>There could possibly be many well-designed ATMs in my locality, but out of all the ATMs I have visited for research purpose<strong>, </strong>I think SBI and Axis bank ATMs are the most well designed ATMs compared to others, as per my observation.</p><p>The following are the key differences and reasons why I think they are better in terms of the ATM I have chosen to improve :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pv7IVu3ycHN72f1k" /></figure><h4>Approach to Design Testing</h4><p>I have assessed my solutions by directly interacting with users including friends and acquaintances During these discussions, I explained the design solutions I crafted to address existing issues in ATMs, as identified in the given design challenge.</p><p>Upon engaging with users, particularly those in the mid-aged and older age group, it was apparent that the solutions I crafted resonated well in addressing their pain points. One specific feedback received during these interactions was:</p><ol><li>Adding an option for new transactions, such as <strong><em>“Would you like to initiate another transaction?” </em></strong>would be beneficial. This feature enables users to proceed with additional actions without the need to remove and re-insert their card.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JArgBMJhsUVF1-Os" /></figure><p>Observing the preferences of younger users, it’s clear that they anticipate further digital enhancements to elevate their overall experience.</p><p>Received two primary suggestion from their end :</p><ol><li>Need for a UPI-enabled option for cash withdrawals.</li><li>A call for personalized features, including recommendations based on their past transactions.</li></ol><h4>Future Scope</h4><p>While I was ideating and testing my designs, I came up with some more ideas to improve the user experience, but didn’t implement them in my design solutions for the following reasons:</p><p>At this point in time, I don’t have all the relevant information to design the solutions because<strong><em> I have conducted my research in a very limited sphere.</em></strong> There are so many things that I am not aware of, like</p><ul><li>What are the things that banks can implement that are both technically feasible and cost-effective?</li><li>What are their policies and constraints?</li></ul><p>This is something that we can’t simply assume. We at least need some amount of information to make any sort of assumptions about this. The following are ideas that could be possible to implement after gathering enough information.</p><ol><li>Voice enabled user interface (VUI)</li><li>Card less transactions from any ATM which has this facility, just like we withdraw cash with a card from any ATM irrespective of which bank our account is linked to.</li><li>Option for withdrawing cash using the UPI method. (This idea was given by one of the users during the testing phase).</li></ol><p><strong>The following is just an illustration of how we could withdraw cash using UPI</strong>: <em>(</em><strong><em>Note:</em></strong><em> I adapted this mechanism and idea from RBI news articles to better understand it.)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Eg2G7Wnl2kbQR_cC" /></figure><h4>Conclusion</h4><p>Even within the constraints of a timed exercise, the significant amount of thought invested in delivering the optimal user experience was substantial. This process deepened my comprehension of problem-solving flow in UX and how small changes in UX can offer straightforward and impactful solutions to various challenges.</p><blockquote>Note : <br>This is my first ever UX design challenge, which played a pivotal role in securing my position and initiating my official journey as a UX designer for a company. Your feedback or suggestions are highly appreciated. <br>Thank you!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f8c8c72220e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Being Human In the Age of AI]]></title>
            <link>https://astha-s15.medium.com/being-human-in-the-age-of-ai-aecd5bb28ac6?source=rss-1996ba74e1b7------2</link>
            <guid isPermaLink="false">https://medium.com/p/aecd5bb28ac6</guid>
            <category><![CDATA[future-technology]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[intelligence]]></category>
            <dc:creator><![CDATA[Astha Sharma]]></dc:creator>
            <pubDate>Thu, 15 Jul 2021 09:41:05 GMT</pubDate>
            <atom:updated>2021-07-15T09:41:05.635Z</atom:updated>
            <content:encoded><![CDATA[<h4>Life 3.0 — Being human in the age of Artificial intelligence.<br>by — Max Tegmark</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*9qabOWAuDoj684jP2eo_YQ.jpeg" /><figcaption>Life 3.0 — Image Source-Google(cover page of the book)</figcaption></figure><blockquote>“If you hear the scenario about the world in 2050 and its sound like science fiction, it is probably wrong; but you hear the scenario about the world in 2050 and it does not sound like a science fiction, it is certainly wrong.”</blockquote><blockquote>~ Yuval Noah Harari</blockquote><p>As we all know that Artificial Intelligence(AI) is one of the most controversial yet fascinating topic of the 21st century.</p><p>What once seemed to be science fiction and elusive dream for the technological world is now almost turning into a reality.<br>From personal voice assistant like “Siri” and “Alexa” to self-driving cars, humanity is witnessing a breathtaking advancement in technology which is accelerating like never before and this all because of steady increase in available data, continuously improving algorithms and increasingly<br>efficient computational power which made AI more powerful in recent decade.</p><p>Everyone is talking about AI in the media , at conferences and at different events. Its become like a general topic of discussion among the people. Different people hold different kind of opinions about it in fact AI is the field which has been polarizing popular opinions but we all know one thing for sure from the history of our technological evolution that<br><strong>“technology is never deterministic”</strong>- it can be used to create a very different kind of society that most of the people can hardly even imagine.<br>I think some of the most hyped and debatable question about the future of AI is that :</p><ul><li>How far this insuperable progress in AI will go ?</li><li>What will happens when machines will completely become capable of independent thinking and learning in a wide range of environments and solve all the complex task just like we humans do ?</li><li>Will we control the intelligent machines or will they control us?</li></ul><p>Did you noticed that what is common in all these questions with respect to human psychology?<br>someone once said that — <strong><em>“The oldest and strongest emotion of mankind is fear and the oldest and strongest kind of fear is fear of unknown”.</em></strong><br>I think we can strongly relate to this that we humans have a fear of unknown and we simply don’t know what the future will bring when it comes to computers being smarter than us and this hypothetical point in time in future at which it is impossible to predict what will happen<br>next or how the things will turn out is what termed as — <strong><em>“The technological singularity”.</em></strong></p><p><strong><em>Max Tegmak’s</em></strong>( a Swedish-American physicist, cosmologist and machine learning researcher ) book <strong>“Life 3.0 — Being human in the age of AI”</strong> is I think is the best place to explore the every Possible argument and questions lies within or related to AI that humanity must be aware about if we<br>want to create a best possible future. In this book Max tried to clarify basic terms and all that hyped and debatable topics and dispelled all the common myths related to AI and provides a very broad spectrum of possible scenarios of the future of AI.<br>Instead of jumping to any conclusion or any one agenda Max tried to cover as much ground as possible by mostly avoiding the technical jargons and by writing the book in very accessible and understandable way targeting not only the technologist or AI enthusiasts but also a general public who really wants to be aware about the future of humanity and exploring and discussing<br>wide variety of scenarios concerning the impact of AI on our Society like economy, job market, media and our political system.</p><h4>Three Stages of Evolution- What is Life 3.0?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*R5srYo6-ght6Hn02ollaEw.jpeg" /><figcaption><strong>Three Stages of Evolution</strong></figcaption></figure><p>Authors divides the development of life into three stages as shown in picture above —</p><p>First he simply defines Life broadly as any process that can retain its complexity and reproduce.</p><p><strong><em>life 1.0(biological evolution)- </em></strong>where both the hardware and software are evolved rather than designed(for example bacteria).<br>Humans, on the other hand, are examples of <strong><em>Life 2.0(cultural evolution)-</em></strong> life whose hardware is evolved, but whose software is largely designed.<br>By software Tegmark means all the algorithms and knowledge that we use to process the information from our senses and decide what to do — everything from the ability to recognize the things to walk, read, write, calculate etc and hardware simple means the body.<br>Finally, <strong><em>Life 3.0(Technological evolution)</em></strong>- designs and upgrades both its software and hardware.</p><p>Max begin his book with a fictional but a possible scenario that how a team of<br>scientists and engineer called Omega secretly build an AI machine called ‘Prometheus’ that could learn anything and even design other machines and how it created a most dramatic transition in the history of the world.</p><blockquote><em>“Nothing in the laws of physics that says we can’t build machines much smarter than us” ~ Max Tegmark</em></blockquote><h4>Some of the Thought Provoking Questions</h4><p>As the book Progress he explores some wide implications of AI and clearly provides unbiased discussion on them and also discussed about the current research and some breakthroughs in the field.<br>He also tried to address many thought provoking questions like:</p><ul><li>How to make AI beneficial for humans?</li><li>what sort of future do we want ?</li><li>what would we like to happen with job automation?</li><li>what will it mean to be a human in the age of AI?</li><li>will intelligent machine replace us, coexist with us or merge with us?</li><li>How can we grow our prosperity through automation without leaving people lacking income or purpose?</li><li>How can we make future AI systems more robust, so that they do what we want without crashing, malfunctioning or getting hacked?</li><li>How can you make AI systems understand our goals as they get ever-smarter?</li></ul><h4>Consciousness</h4><p>Then he explores the subject of consciousness and intelligence and discussed his own view about the concept like “What is meant by to be alive, to be conscious etc?”, “ Is consciousness is beyond science?”, “ what are the experimental clues about the consciousness and what are the most common criticism of the theory?” and “Will human being with flesh and bone be needed anymore if we can transform our consciousness into computers?”</p><blockquote>He described Consciousness as a Subjective Experience. <strong>&quot;It is the way information feels when being processed in certain”.</strong> I think this was most interesting part of the book for me.</blockquote><h4><strong>Future of Life Institute(FLI)</strong></h4><p>Last but not the least he ends his book optimistically by describing his work On AI safety Research at <strong>Future of Life Institute(FLI)</strong> Founded by him.<br>The Future of Life Institute is a non-profit research institute and outreach organization in the Boston area that works to mitigate existential risks facing humanity, particularly existential risk from advanced artificial intelligence.<br>Main vision of this is <strong>“Technology is giving life the potential to flourish like never before…Or to self destruct. Let’s make a difference!”</strong></p><p>To know more about FLI you can follow this link👉<a href="https://futureoflife.org/"><strong>https://futureoflife.org/</strong></a></p><p>We are now living in the extraordinary time of change in the world where latest technologies like AI are moving so fast that I don’t think we are prepared for this and their far-reaching Implications on the humanity. This book was actually an eye opener for me which made me aware about many thought provoking questions which humanity must explore if we want to have a positive future. I know There have been so many book which covered this topic and I don’t know about all of them but the best and the unique thing about Max Tegmak&#39;s book is that instead of just raising concerns on the dark side of the AI, he is trying to do something about it in order to create a better future with AI and also his physics perspective about the things made this book more interesting. The main focus of the book is to make people understand that 👉“<a href="https://www.youtube.com/watch?v=2LRwvU6gEbA&amp;t=868s"><strong><em>How to get Empowered, not Overpowered by Artificial Intelligence</em></strong></a>” and why it is so important to be part of This most important conversation of our time.</p><p>Here are some links given below 👇 you can follow to know more about the subject:</p><ul><li><strong>Max Tegmark Talk at Google</strong> — <a href="https://www.youtube.com/watch?v=oYmKOgeoOz4&amp;t=351s"><strong><em>https://www.youtube.com/watch?v=oYmKOgeoOz4&amp;t=351s</em></strong></a></li><li><strong>The Psychology of Existential Risk: Moral Judgments about Human Extinction — </strong><a href="https://futureoflife.org/2019/10/30/the-psychology-of-existential-risk/"><strong><em>https://futureoflife.org/2019/10/30/the-psychology-of-existential-risk/</em></strong></a></li><li><a href="https://www.youtube.com/watch?v=Gi8LUnhP5yU"><strong><em>https://www.youtube.com/watch?v=Gi8LUnhP5yU</em></strong></a></li></ul><p><em>Technology will continue to evolve and grow exponentially with time</em> whether we <em>want it to or not and now its really important to introspect that how we can can amplify our own intelligence with machine intelligence to create a better world.</em> <em>As said by Stephen Hawking, Indeed This is the most important conversation of our time, and Max Tegmak&#39;s intense and thought-provoking book will help you join it.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aecd5bb28ac6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working of Linear Regression Algorithm]]></title>
            <link>https://astha-s15.medium.com/working-of-linear-regression-algorithm-9eeccb70478e?source=rss-1996ba74e1b7------2</link>
            <guid isPermaLink="false">https://medium.com/p/9eeccb70478e</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[optimization-algorithms]]></category>
            <category><![CDATA[linear-regression]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Astha Sharma]]></dc:creator>
            <pubDate>Sun, 20 Jun 2021 13:15:53 GMT</pubDate>
            <atom:updated>2021-06-20T13:15:53.935Z</atom:updated>
            <content:encoded><![CDATA[<h4>One of the foundational algorithm in machine learning.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*agtn8b8mAfMsPnBVWz2zng.jpeg" /><figcaption><strong>Image by Author- Linear Regression</strong></figcaption></figure><p>Linear Regression is often termed as a simple yet very useful and powerful machine learning algorithm to understand data but still only few are aware of its fundamental concepts.</p><p><strong><em>This article aims to help you understand Linear Regression and how it works in principle.</em></strong></p><p>Before we dive into the details of linear Regression algorithm lets first understand <strong>“what is Regression?”</strong></p><p>You have probably heard this that <em>“Regression is a set of statistical process for estimating the relationship among the variables.”</em> or <em>“Regression is used to determine the strength of the relationship between dependent variable and one or more independent variables.”</em> or <em>“Regression is a way to find a trends in data”</em> etc.</p><p>There are various explanations on Regression out there but I feel most of the explanations just directly get into the equations, models, statistical distributions and all that technical stuff. So for a moment forget about all these technical terms and<strong> Let’s try to understand Regression in the simplest possible terms :</strong></p><p><em>If you have ever taken a taxi ride, you can understand regression :</em></p><p><em>The moment you sit in a taxi you see that there’s one fixed amount there(something called as base fair ). Rather that cab moves or you get off, this is what you owe to the driver. The moment you step into the cab…That’s a constant you have to pay that amount. Then as it starts moving, for every meter or 100 meters, the fare increases by certain amount. so there’s a relationship between the distance and the amount you would pay, above and beyond that constant. And if you are not moving and stuck in traffic, then every additional minute, you have to pay more. so as the minutes increase, your fare increases, as the distance increases the fare increases and while all this is happening you’ve already paid a base fare which is constant. This is what the regression is, It will tell you what the base fare is and what is the relationship between the time and fare you have paid and the distance you have travelled.</em></p><p><em>Note : I found this explanation on YouTube by Professor Murtaza Haider.</em></p><p>Here “total fare” is our <strong>dependent/target variable</strong> which we are trying to predict and “distance” and “time” is an <strong>independent variable or predictors.</strong></p><h4><strong>Why to use Regression?</strong></h4><p>Regression is performed when the dependent variable is of continuous data type and Predictors or independent variables could be of any data type like continuous, nominal/categorical etc. It tries to find the best fit line which shows the relationship between the dependent variable and independent variables with least error.</p><h4><strong>Linear Regression</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*QiU6DcP_r9qWLznMw0-M_Q.png" /><figcaption><strong>Linear Regression</strong></figcaption></figure><p><strong><em>Linear regression is a way to modelling the relationship between dependent and independent variables by fitting a linear equation to observed data.</em></strong></p><p>The general equation for best fit line is :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*kgGAOE_VyWCFchnPchG05w.png" /></figure><p>Above equation is a representation of<strong> Univariate or Simple linear regression </strong>where the number of independent variables is one and there is a linear relationship between the independent(<strong>x</strong>) and dependent(<strong>y</strong>) variable.</p><p>The goal of the algorithm is to find the best fitting line for the input data we have i.e. optimal values for the unknown parameters <strong>W0 </strong>and<strong> W1</strong> but there are infinite <strong>W0</strong> and <strong>W1</strong> possibilities so it often comes in the mind that which one to choose or Is there is any way in which we can quantify which is the best fitting model?</p><h4><strong>So Here the Cost Function comes into the picture</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*47mVBfKw9BKH0DWL_iJw5g.png" /><figcaption>LSE (Image source : google)</figcaption></figure><p>It is a function that measures the performance of our model on the given data. It quantifies the error between predicted values and expected values and presents it in the form of a single real number.<em>(whichever choice of </em><strong><em>W0</em></strong><em> and </em><strong><em>W1</em></strong><em> will minimize the total error or cost function that will be the optimal for the model)</em>.</p><p>Most commonly used cost function for Linear Regression model is<strong> MSE(mean squared error)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*mfpWFi1KCDHWPGWepyUQ2g.png" /></figure><p>so basically We square the error difference and sum over all data points and divide that value by the total number of data points. This provides the average squared error over all the data points.</p><p><strong>Note: Minimum the cost function, Higher will be accuracy of the model.</strong></p><h4>Gradient Descent</h4><p>To minimize the cost function(MSE) and to improve model weights(<strong>W0</strong> and <strong>W1</strong>) we use optimization algorithm called <strong>Gradient Descent</strong>.</p><p>Now we have reduced our fitting problem into an optimisation problem.</p><p>So basically what this Gradient Descent algorithm does is that it start with some given arbitrary values for <strong>W0 </strong>and <strong>W1 </strong>and then change these values iteratively until it finds an optimal values for the Weights which leads to the minimum cost function.</p><p><em>But how this algorithm figures out that how much value of </em><strong><em>W0 </em></strong><em>and</em><strong><em> W1</em></strong><em> should change after each iteration/step?</em></p><p>The answer is <strong>Learning Rate. It decides that how fast the algorithm converge to the minima.</strong></p><p>To understand this lets have a look on the diagram given below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DomkxAGDMgj7jGxu3X2a8Q.png" /><figcaption>Learning Rate</figcaption></figure><p>Imagine you are at the top of this U Shaped curve and your goal is to reach at the bottom of this curve. if you decide to take one step at a time you would eventually reach the bottom but this would take a longer time and If you choose to take longer steps each time, you would reach sooner but, there is a chance that you could overstep the bottom and not exactly at the bottom. so in order to reach the bottom fast and without overstepping it we need to select optimal steps which swiftly reaches the bottom point(minima). Here step represents the Learning rate.</p><p>To update parameters(<strong>W0</strong> and<strong> W1</strong>) we take gradients from cost function. To find how these parameter affects the MSE, we take partial derivatives with respect to <strong>W0 </strong>and <strong>W1</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oIplp6wPpfst75KwTelyRA.jpeg" /></figure><p>The partial derivates are the gradients(tells in which direction to move) and they are used to update the values of <strong>W0</strong> and <strong>W1</strong>. Alpha(<strong>α</strong>) is the learning rate which is a hyperparameter(step length) that you must specify.</p><p>The Gradient descent algorithm keeps on finding the optimal value for Wo and W1 until the value of cost function becomes very small or becomes 0 (ideally) and this is how we find our Best Fit Regression Line.</p><h4>Multiple Linear Regression</h4><p>when we deal with real world problems, there are multiple independent variables which contribute to predict target variable instead of just one single variable. So mostly we deal with <strong>Multiple Linear Regression.</strong></p><p><strong><em>Multiple regression models thus describe how a single response variable Y depends linearly on a number of predictor variables.</em></strong></p><p>The equation remains the same just like simple linear regression the only difference is that we simply add multiple independent variables/predictors and their corresponding coefficients.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*J_3vdXySM19h3D6RMtt4EA.png" /></figure><p>Multiple linear Regression is always better than the simpler one as with each additional relevant variable we add , we increase the explanatory power of the model.</p><p><em>Note: The working of the algorithm remains the same, the only thing that changes is the Gradient Descent graph. In Simple Linear Regression, the gradient descent graph was in 2D form, but as the number of independent features/predictors increases, the gradient descent graph’s dimensions also keep on increasing.</em></p><p>The Image given below summarise the steps of working of Linear Regression algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jWE_wNX8FbXJ_CERls7K1Q.jpeg" /><figcaption><strong>Source : </strong><a href="https://astha-s15.medium.com/how-do-machines-actually-learn-16573b71c520"><strong>https://astha-s15.medium.com/how-do-machines-actually-learn-16573b71c520</strong></a></figcaption></figure><p><strong><em>That’s all</em></strong><em>…</em><strong><em>So this is how a Linear Regression algorithms works under the hood.</em></strong></p><p>I hope someone find this article helpful.</p><p>You can connect with me on :</p><ul><li><strong><em>LinkedIn :</em></strong><em> </em><a href="https://www.linkedin.com/in/astha-sharma-47266b11b/"><em>https://www.linkedin.com/in/astha-sharma-47266b11b/</em></a></li><li><strong><em>GitHub : </em></strong><a href="https://github.com/asthasharma98"><em>https://github.com/asthasharma98</em></a></li></ul><p><strong><em>Thank You !</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9eeccb70478e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How do machines Actually learn?]]></title>
            <link>https://astha-s15.medium.com/how-do-machines-actually-learn-16573b71c520?source=rss-1996ba74e1b7------2</link>
            <guid isPermaLink="false">https://medium.com/p/16573b71c520</guid>
            <category><![CDATA[artficial-intelligence]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Astha Sharma]]></dc:creator>
            <pubDate>Sat, 05 Jun 2021 18:36:43 GMT</pubDate>
            <atom:updated>2021-06-05T18:36:43.383Z</atom:updated>
            <content:encoded><![CDATA[<h4>Logic behind the working of Machine Learning Algorithm</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xD3YU3jYl01fgB984k-CVA.jpeg" /><figcaption>(Google-PhonlamaiPhoto via iStock by Getty Images)</figcaption></figure><p>As we all know that Machine learning is the Latest way of approaching and solving problems and by now you have probably heard many explanations on <strong>“what is Machine Learning ? “</strong></p><blockquote>The General Idea behind the Machine learning is that humans generally learns from their past experience and machine follows instructions given by the humans but what if humans can train the machines to learn from the past data and let them improve over time when exposed to new data.</blockquote><p><strong>Great!…So “</strong><em>Machine learning Provide computers an ability to learn from their past experiences and then increase the performance as they feed on more and more data.</em><strong>”</strong></p><p><strong>We got it…but wait “How does it learn ?”</strong></p><p>Most of the time we disregard this question as we got so overwhelmed and fascinated by the trendy libraries that one starts to think that why do even I need to learn the mathematics and logic behind the learning algorithms? every thing is already there, I just need to learn some syntax to import modules and call the functions to get the output. Done!</p><p>But in reality the real world problems need appropriate and feasible solutions which can be derived by the right approach towards the problem and to validate this we need a clear understanding of the fundamentals.</p><p>So In this article I’d like to cover a simple explanation of how machine learning works under the hood.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*jGLxE8v97v1jyR364hqrDw.jpeg" /></figure><p>Here ML task is to learn the relationship between the input data and the output data.</p><p>let us assume this relationship as a mathematical function like one given below. we can call this function a “Model”.</p><p><strong>Y = f(x) = Wx+b</strong></p><p>Above equation says that<strong> W </strong>times <strong>x</strong> plus b makes <strong>y</strong>. In context of ML, <strong>x</strong> would be our input, the result of the equation<strong> y</strong> would be our expected output and <strong>W</strong> and <strong>b</strong> are parameters.</p><p>The goal of the ML algorithm would be to find such values for <strong>W</strong> and <strong>b</strong> so that the output of <strong>W</strong> times <strong>x + b</strong> is as close to the observed value as possible.(i.e. <strong>y</strong>)</p><p>The function has two parts :</p><ul><li>Form of the function (given by user)-the function can be of any form depending on different algorithm.</li><li>Parameters/weight of function (found by the algorithm)</li></ul><p>So basically the entire ML process is about getting lots of examples for input<strong>(x)</strong> and output<strong>(y)</strong> and based on those examples it try to figure out the value of <strong>W</strong> and <strong>b</strong> by making some educated guesses and improving those guesses.</p><p><strong>Learning the Parameter via Feedback</strong></p><p>To learn the parameters there are following steps :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jWE_wNX8FbXJ_CERls7K1Q.jpeg" /><figcaption>Mathematical Representation of ML algorithm</figcaption></figure><ul><li>We start with some point say <strong>x</strong>. i.e. we collect and pass lots of input data <strong>x</strong> and output data <strong>y</strong> to the model.</li><li>Define a form of the function that model has to follow.(In this article I am using simple linear function for the explanation.) ex : <strong>y = f(x) = Wx+b</strong></li><li>Make some arbitrary guess for <strong>W</strong> for which will get some<strong> ŷ</strong>(here <strong>ŷ</strong> is a predicted outcome ).we mostly found some difference between the actual outcome(<strong>y</strong>) and the predicted outcome.(<strong>ŷ</strong>)</li><li>Then define and find the cost function — It is a function that measures the performance of our ML model on the given data. It quantifies the error between predicted values and expected values and presents it in the form of a single real number. Depending on the problem Cost Function can be formed in many different ways. The most common cost function we for linear model is Mean Square Error (MSE)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*Ko9OYL7TTpbVi9UNsvzNbg.png" /></figure><p>The goal is to find the values of model parameters(in this case <strong>W</strong> and <strong>b</strong> ) for which Cost Function(MSE) return as small number as possible.</p><ul><li>To minimise the cost function and to improve <strong>W</strong> we use optimisation algorithm such as Gradient Descent. <strong>Gradient descent</strong> is a first order iterative optimisation algorithm for finding the minimum of the function. It is the most commonly used optimisation algorithm(<em>let’s not get into the details here</em>) but again depending on problems we can use different optimisation algorithms.</li></ul><p><strong>Lets understand the above steps with the help of simple example to get an clear idea :</strong></p><p>Let’s say we have training set which contains single data point(x=4,y=14). we know that if x is 4, y should be 14. We need to find the a, b pair that fits these numbers. As in the equation below.</p><p><strong>a*4 + b = 14</strong></p><p>So before the model starts its search for the a and b values we need to assign some random numbers to the values as it does not use any prior knowledge, No mathematics knowledge, no assumptions, nothing.</p><p>Let’s say, in our example, we initialized as 7 and b as 10. This would give us:</p><p><strong>7*4 + 10 = 38</strong></p><p>The error is: 38–14 = 24. So this would tell us that our a and b values are too high.</p><p>so the next time model tries the new value guided by how much it overstepped the actual value and in which direction. Like, was the guess higher than the expected value or lower then the expected value?</p><p>Now our model might try 2 and 4 next. This would give us:</p><p><strong>2*4 + 4= 12</strong></p><p>This is a much better guess. Our error is only: 12–14 = -2 This error means that now we underestimated the y value. After going with this for a while, let’s say our model tries, 3 and 2:</p><p><strong>3*4 + 2=14</strong></p><p>Ok we are Done! We were able to figure out the a and b values but its not only the values which satisfies the given equation, there might be many such pairs and in reality the process is not so fast. The whole process is trial and error approach and in the end models comes up with optimal values with as minimum error as possible.</p><p>So This how ML model actually learns in Principle.</p><p><em>Well of course not all the Machine learning algorithm follows the linear model. The mathematical equation that needs to be solved is different for each algorithm depending upon the problems and linear model is one of them but the general logic behind the learning is almost same. what we are doing at the end of the day is that we are trying to come up with a mathematical explanation that can closely estimate what happens in the real world.</em></p><p><strong>That’s all.</strong> This basic idea about how machine learns behind the scene helps me alot to develop my interest to learn more about the different algorithms and understanding what is being optimized and what value we are trying to estimate.</p><p>I hope someone find this useful :)</p><p><strong>Thank you!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16573b71c520" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to develop an End-to-End Machine learning Project]]></title>
            <link>https://astha-s15.medium.com/how-to-develop-an-end-to-end-machine-learning-project-3b3488663e01?source=rss-1996ba74e1b7------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b3488663e01</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[data-analytics]]></category>
            <dc:creator><![CDATA[Astha Sharma]]></dc:creator>
            <pubDate>Wed, 02 Jun 2021 18:21:10 GMT</pubDate>
            <atom:updated>2021-06-02T18:21:10.279Z</atom:updated>
            <content:encoded><![CDATA[<h4>A step by step guide to build a web app for prediction from problem definition to model deployment.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G-pHRAJ6cf9oh4rhfcFO1A.jpeg" /></figure><h4><strong>Things we will cover in this Article</strong></h4><ul><li>Data Collection and Problem Statement</li><li>Exploratory Data Analysis with Pandas and NumPy</li><li>Data Pre-processing and feature engineering</li><li>Selecting and Training a few Machine Learning Models using Sklearn</li><li>Model Evaluation</li><li>Deploying the Final Trained Model on Heroku via a Flask App</li></ul><blockquote><strong>Note</strong> : As being a Data and ML enthusiast I have tried many different projects related to the subject but what I have realised is that Deploying your machine learning model is a key aspect of every ML and Data science project. Everything thing I had studied or been taught so far in my Data science and ML journey had mostly focused on defining problem statement followed by Data collection and preparation, model building and evaluation process which is of course important for every ML/DS project but what if I want different people to interact with my models, how can I make my model available for end-users? I can’t send them jupyter notebooks right! That’s why I wanted to try my hands on complete end-to-end machine learning project.</blockquote><h4><strong>Overview of the Project</strong></h4><blockquote><em>A simple Machine learning and NLP based Web Application which classify the given messages as Spam or Ham(Not Spam) build using Flask and deployed on Heroku.</em></blockquote><p><strong><em>To view the Deployed Application, click on the link given below</em></strong> <strong><em>:</em></strong> <a href="https://sms-spam-predictor-nlp.herokuapp.com/">https://sms-spam-predictor-nlp.herokuapp.com/</a></p><p><strong>Demo of the Deployed Web Application</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sUIyaBX1pcyS6Lx0ZXeU0w.gif" /></figure><p><strong><em>Let’s Get Started…</em></strong></p><h4><strong>Step1: Data collection and Problem Statement</strong></h4><p>The very first step of every machine learning Project is focus on the Data. It is very important task to decide what , how and from where to get the required data to solve the given Problem. The required data could be gathered from clients internal DB, third Party APIs, Online Data sites or by web scraping. So for this Project we are going to use UCI-ML SMS Spam Collection Data from the Kaggle.</p><p><strong><em>Here the Link of the Dataset :</em> </strong><br><a href="https://www.kaggle.com/uciml/sms-spam-collection-dataset">https://www.kaggle.com/uciml/sms-spam-collection-dataset</a></p><p><strong>Problem Statement</strong> :<strong> <em>To Classify the given text messages as Spam or Ham.</em></strong></p><h4><strong>Step2 : Loading the Dataset</strong></h4><p>First Import the required libraries to load the data and to perform the EDA.</p><pre>import numpy as np<br>import pandas as pd<br>import matplotlib.pyplot as plt<br>import seaborn as sns</pre><p>Then read and load the file into a dataframe using the read_csv method and lets have a look at basic information about the data with the help of info() method.</p><pre><em>#reading and checking the basic structure of the data</em></pre><pre>sms_data = pd.read_csv(&quot;spam.csv&quot;,encoding=&#39;latin-1&#39;)<br>sms_data.info()</pre><p><em>Note : The character encoding of this dataset character set is latin-1(ISO/IEC 8859–1).</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*AhbKJhV8wPl3S_AZgVQfhQ.png" /><figcaption>sms_data.info()</figcaption></figure><p>The dataset contains 5 columns. Column v1 is the dataset label (“ham” or “spam”) and column v2 contains the text of the SMS message. Columns “Unnamed: 2”, “Unnamed: 3”, and “Unnamed: 4” contain “NaN” (not a number) signifying missing values. They are not needed, so they can be dropped as they are not going to be useful in building the model.</p><p>The following code snippet will drop and rename the columns to improve understandability of the dataset:</p><pre><em># creating a copy of the dataset so that the changes will not affect the original dataset.<br></em>sms_df = sms_data. Copy() </pre><pre><em># Dropping the redundant looking columns (for this project)</em><br>to_drop = [&quot;Unnamed: 2&quot;,&quot;Unnamed: 3&quot;,&quot;Unnamed: 4&quot;]<br>sms_df = sms_df. Drop(sms_df[to_drop], axis=1)</pre><pre><em># Renaming the columns for better understanding </em><br>sms_df.rename(columns = {&quot;v1&quot;:&quot;Target&quot;, &quot;v2&quot;:&quot;Message&quot;}, inplace = True)<br>sms_df.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*TaFE1MO3Bs_Pv3UDndRZxA.png" /></figure><p>Now the dataset looks more clear and understandable.</p><h4><strong>Step3 : Exploratory Data Analysis</strong></h4><p>Will do the data exploration in few series of steps given below :</p><ul><li><strong>To check the Basic information about the data like number of rows and columns , data types and null values we can use a direct pandas function called info().</strong></li></ul><pre># using info method<br>sms_df.info()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*QdIm5csJ6uQz1H_xSD9c1Q.png" /><figcaption>sms_df.info()</figcaption></figure><p>The dataset consists of 5,572 messages in English. The data is designated as being ham or spam. Data frame has two columns. The first column is “Target” indicating the class of message as ham or spam and the second “Message” column is the string of text. There is no null values present in the dataset.</p><ul><li><strong>We can also get the statistical information about the data using describe() method.</strong></li></ul><pre><em># statistical info of dataset</em><br>sms_df.describe()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/1*IWJnz63OBVdrnSzQqEBN7w.png" /><figcaption>sms_df.describe()</figcaption></figure><p>Before exploring the distribution of the dataset and further analysis will first map the values(each category) of target variable with 0 and 1.(0-Ham,1-Spam)</p><pre><em># Mapping Values for labels </em> <br>sms_df[&#39;Target&#39;] = sms_df[&#39;Target&#39;].map({&#39;ham&#39;: 0, &#39;spam&#39;: 1}) sms_df.head()</pre><ul><li><strong>Now Let’s look at the Distribution of Labels</strong></li></ul><pre><em>#Palette<br></em>cols= [&quot;#E1F16A&quot;, &quot;salmon&quot;] <br>plt.figure(figsize=(8,8))<br>fg = sns.countplot(x= sms_df[&quot;Target&quot;], palette= cols)<br>fg.set_title(&quot;Countplot for spam Vs ham&quot;)<br>fg.set_xlabel(&quot;Classes(0:ham,1:spam)&quot;, color=&quot;#58508d&quot;)<br>fg.set_ylabel(&quot;Number of Data points&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*qbUpCNDfguM0zuKm1z4czQ.png" /></figure><p>From the above count plot, it is evident that the dataset is imbalanced with most the messages being Ham(not spam). So next will have to dive into a feature engineering.</p><h4><strong>Step4 : Feature Engineering</strong></h4><p><strong>Handle imbalanced dataset using oversampling</strong></p><p>To balance the dataset we are using oversampling technique .</p><p><strong>Oversampling</strong> in data analysis are techniques used to adjust the class distribution of a dataset(i.e. the ratio between the different classes/categories represented).</p><pre><em># Handling imbalanced dataset using Oversampling</em> <br>only_spam = sms_df[sms_df[&#39;Target&#39;]==1] print(&#39;Number of Spam records: <strong>{}</strong>&#39;.format(only_spam.shape[0])) print(&#39;Number of Ham records: <strong>{}</strong>&#39;.format(sms_df.shape[0]-only_spam.shape[0]))</pre><pre>count = int((sms_df.shape[0]-only_spam.shape[0])/only_spam.shape[0])<br><strong>for</strong> i <strong>in</strong> range(0, count-1):<br>    sms_df = pd.concat([sms_df, only_spam])<br><br>sms_df.shape</pre><p>Now will again check the distribution</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*1D-Y0_STt49fYyRtp2gZBQ.png" /></figure><p>Now from the above plot we can clearly say that our data is almost balanced.</p><p><strong>To understand more about the data will create some new features like :</strong></p><ul><li>word_count : Number of words in the text message</li><li>contains_number : do the the text message contains numbers</li><li>contains_currency_symbol : symbols like ‘€’, ‘$’, ‘¥’, ‘£’, ‘₹’ in the text message.</li></ul><p><strong>Distribution of word count for ham and spam messages</strong></p><pre><em># creating new feautre word_count</em></pre><pre>sms_df[&#39;word_count&#39;] = sms_df[&#39;Message&#39;].apply(<strong>lambda</strong> x: len(x.split()))</pre><pre>plt.figure(figsize=(12, 6))<br><br><em># 1-row, 2-column, go to the first subplot</em><br>plt.subplot(1, 2, 1)<br>g = sns.distplot(a=sms_df[sms_df[&#39;Target&#39;]==0].word_count,color=&#39;#E1F16A&#39;)<br>p = plt.title(&#39;Distribution of word_count for Ham messages&#39;)<br><br><em># 1-row, 2-column, go to the second subplot</em><br>plt.subplot(1, 2, 2)<br>g = sns.distplot(a=sms_df[sms_df[&#39;Target&#39;]==1].word_count, color=&#39;salmon&#39;)<br>p = plt.title(&#39;Distribution of word_count for Spam messages&#39;)<br><br>plt.tight_layout()<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XcrkR7Hx1hf8GgAWkyDmBQ.png" /></figure><p>It can be seen that mostly ham messages are shorter than spam messages as the distribution of words in the Spam messages fall in the range of 15–30 words, whereas majority of the Ham messages fall in the range of below 25 words.</p><p><strong>Lets have a look at how messages are related to currency symbols</strong></p><pre><em># Creating feature contains_currency_symbol</em><br><strong>def</strong> currency(x):<br>    currency_symbols = [&#39;€&#39;, &#39;$&#39;, &#39;¥&#39;, &#39;£&#39;, &#39;₹&#39;]<br>    <strong>for</strong> i <strong>in</strong> currency_symbols:<br>        <strong>if</strong> i <strong>in</strong> x:<br>            <strong>return</strong> 1<br>    <strong>return</strong> 0<br><br>sms_df[&#39;contains_currency_symbol&#39;]=sms_df[&#39;Message&#39;].apply(currency)<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*omwZYhBXr-ty3gayaKqbJg.png" /></figure><p>It can be seen that Almost 1/3 of Spam messages contain currency symbols, and currency symbols are rarely used in Ham messages which is quite acceptable because most of spams messages are intended for money.</p><p><strong>Now lets check for text messages containing number</strong></p><pre><em># Creating feature contains_number</em> <br><strong>def</strong> numbers(x):     <br>    <strong>for</strong> i <strong>in</strong> x:         <br>        <strong>if</strong> ord(i)&gt;=48 <strong>and</strong> ord(i)&lt;=57:             <br>            <strong>return</strong> 1     <br>     <strong>return</strong> 0  <br>sms_df[&#39;contains_number&#39;] = sms_df[&#39;Message&#39;].apply(numbers)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*zq7XTrjtiFXMe0UHDD4rMw.png" /></figure><p>From above plot we can say that (at least for this dataset)most of the Spam messages contain numbers, and majority of the Ham messages do not contain numbers.</p><h4><strong>Step5 : Data Pre-processing</strong></h4><p>The data cleaning process NLP is crucial. The computer doesn’t understand the text. For the computer, it is just a cluster of symbols. The process of converting data to something a computer can understand is referred to as pre-processing. In the context of this article, this involves processes and techniques to prepare our text data for our machine learning algorithm.</p><p>Lets have a look at a sample of texts before Pre-processing</p><pre>print(&quot;The First 5 Texts:<strong>\0</strong>&quot;,*sms_df[&quot;Message&quot;][:5], sep = &quot;<strong>\n</strong>&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wgnd1pjdyOyESY4ESg44vw.png" /><figcaption>Texts before Pre-processing</figcaption></figure><p><strong>Following are the steps used for pre-processing the data for NLP :</strong></p><p><strong>Cleaning text :</strong></p><ul><li>In the first step we extract only the alphabetic characters by this we are removing punctuation and numbers.</li><li>In the next step, we are converting all the characters into lowercase.</li></ul><p><strong>Tokenizing the messages :</strong> Tokenization is breaking complex data into smaller units called tokens. It can be done by splitting paragraphs into sentences and sentences into words.</p><p><strong>Removing the stop words</strong> <strong>:</strong> Stop words are frequently occurring words(such as few, is, an, etc). These words hold meaning in sentence structure, but do not contribute much to language processing in NLP. For the purpose of removing redundancy in our processing, we are removing those. NLTK library has a set of default stop words that we will be removing.</p><p><strong>Lemmatizing the words</strong> <strong>:</strong> Stemming and Lemmatization are Text Normalization (or sometimes called Word Normalization) techniques in the field of NLP.</p><p>Lemmatization is the process of arriving at a lemma of a word. What is a lemma, then? Lemma is the root from which a word is formed. For example, given the word went, the lemma would be ‘go’ since went is the past form of go.</p><p><em>Lets have a look on how will perform a steps for pre-processing mentioned above</em></p><p>First we need to import the following libraries :</p><pre><em># libraries for performing NLP </em><br><strong>import</strong> <strong>nltk</strong><br><strong>import</strong> <strong>re</strong><br>nltk.download(&#39;stopwords&#39;)<br>nltk.download(&#39;wordnet&#39;)<br><strong>from</strong> <strong>nltk.corpus</strong> <strong>import</strong> stopwords<br><strong>from</strong> <strong>nltk.stem</strong> <strong>import</strong> WordNetLemmatizer<br><strong>from</strong> <strong>sklearn.feature_extraction.text</strong> <strong>import</strong> TfidfVectorizer</pre><p>The following code snippet will perform the text pre-processing.</p><pre><em># Cleaning the messages</em><br>corpus = []<br>wnl = WordNetLemmatizer()<br><br><strong>for</strong> sms_string <strong>in</strong> list(sms_df.Message):<br><br>  <em># Cleaning special character from the sms</em><br>  message = re.sub(pattern=&#39;[^a-zA-Z]&#39;, repl=&#39; &#39;, string=sms_string)<br><br>  <em># Converting the entire sms into lower case</em><br>  message = message.lower()<br><br>  <em># Tokenizing the sms by words</em><br>  words = message.split()<br><br>  <em># Removing the stop words</em><br>  filtered_words = [word <strong>for</strong> word <strong>in</strong> words <strong>if</strong> word <strong>not</strong> <strong>in</strong> set(stopwords.words(&#39;english&#39;))]<br><br>  <em># Lemmatizing the words</em><br>  lemmatized_words = [wnl.lemmatize(word) <strong>for</strong> word <strong>in</strong> filtered_words]<br><br>  <em># Joining the lemmatized words</em><br>  message = &#39; &#39;.join(lemmatized_words)<br><br>  <em># Building a corpus of messages</em><br>  corpus.append(message)</pre><p>Let’s have a look at texts after cleaning</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f2qDB9-tvK2DckuwAenRBA.png" /><figcaption>Texts after pre-processing</figcaption></figure><h4><strong>Step6 : Vectorization</strong></h4><p>In NLP cleaned data needs to be converted into a numerical format where each word is represented by a matrix. This is also known as word embedding or Word vectorization. we will be using TfidfVectorizer() to vectorize the pre-processed data.</p><pre><em>#Changing text data in to numbers and Creating the Bag of Words model</em><br>tfidf = TfidfVectorizer(max_features=500)<br>vectors = tfidf.fit_transform(corpus).toarray()<br>feature_names = tfidf.get_feature_names()<br><br><em>#Let&#39;s have a look at our feature </em><br>vectors.dtype</pre><p>Now our next step is to start training our machine learning models.</p><p><em>Libraries required for model building and evaluation :</em></p><pre><strong>from</strong> <strong>sklearn.model_selection</strong> <strong>import</strong> train_test_split<br><strong>from</strong> <strong>sklearn.pipeline</strong> <strong>import</strong> Pipeline    <br><strong>from</strong> <strong>sklearn.naive_bayes</strong> <strong>import</strong> Multinomial<br><strong>from</strong> <strong>sklearn.ensemble</strong> <strong>import</strong> RandomForestClassifier<br><strong>from</strong> <strong>sklearn.tree</strong> <strong>import</strong> DecisionTreeClassifier<br><strong>from</strong> <strong>sklearn.svm</strong> <strong>import</strong> SVC<br><strong>from</strong> <strong>sklearn.model_selection</strong> <strong>import</strong> cross_val_score<br><strong>from</strong> <strong>sklearn.metrics</strong> <strong>import</strong> precision score, recall_score, plot_confusion_matrix, classification_report, accuracy_score, f1_score<br><strong>from</strong> <strong>sklearn</strong> <strong>import</strong> metrics</pre><h4><strong>Step7 : Building and training Models</strong></h4><p>we are going to use following Steps in model building :</p><ul><li><strong>Setting up features and target as X and y</strong></li></ul><pre><em># Extracting independent and dependent variables from the dataset</em><br>X = pd.DataFrame(vectors, columns=feature_names)<br>y = sms_df[&#39;Target&#39;]</pre><ul><li><strong>Splitting the testing and training sets</strong></li></ul><pre><em># Splitting the testing and training sets</em><br>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)</pre><ul><li><strong>Build a pipeline of model for four different classifiers.</strong></li></ul><p>We are using <em>Naïve Bayes</em> , <em>RandomForestClassifier,</em> <em>DecisionTreeClassifier,</em> <em>Support Vector Machines</em></p><pre><em>#Testing on the following classifiers</em><br>classifiers = [MultinomialNB(), <br>               RandomForestClassifier(),<br>               DecisionTreeClassifier(), <br>               SVC()]<br><strong>for</strong> cls <strong>in</strong> classifiers:<br>    cls.fit(X_train, y_train)<br><br><em># Dictionary of pipelines and model types for ease of reference</em><br>pipe_dict = {0: &quot;NaiveBayes&quot;, 1: &quot;RandomForest&quot;, 2: &quot;DecisionTree&quot;,3: &quot;SVC&quot;}</pre><ul><li><strong>Get the cross-validation on the training set for all the models for accuracy</strong></li></ul><pre><em># Cross-validation </em><br><strong>for</strong> i, model <strong>in</strong> enumerate(classifiers):<br>    cv_score = cross_val_score(model, X_train,y_train,scoring=&quot;accuracy&quot;, cv=10)<br>    print(&quot;<strong>%s</strong>: <strong>%f</strong> &quot; % (pipe_dict[i], cv_score.mean()))</pre><p>So we have trained the model now we will evaluate the model performance on the given test set.</p><h4><strong>Step8 : Model Evaluation</strong></h4><p>Now in this step will how all the model are performing and which model works well with the given data. we are using accuracy report and confusion matrix for model evaluation</p><p>Lets first have a look at Accuracy Report</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*p8KxbC8x-AQU2qXaIfm37w.png" /><figcaption>Accuracy Report</figcaption></figure><p>Accuracy report shows that Random Forest and SVC classifier almost got the same score.</p><p>Confusion Matrix</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7NnBS_dsewr16n7AQeLw3w.png" /></figure><p>With the help of confusion matrix we can say that SVC performed slightly better than the Random Forest classifier on the give data.</p><h4><strong>Step9 : Deploying model on Heroku with using Flask</strong></h4><p>Deploying a machine learning model means making the model available for end-users to make use of. In order to deploy any trained model, we need the following thing :</p><ul><li><strong>A Trained model : </strong>save the model into a file to be further loaded and used by the web service.</li><li><strong>A Web Service : </strong>that gives a purpose for your model to be used in practice. For our Spam SMS classifier model ,We’ll use Flask to develop this service.</li><li><strong>A cloud Service Provider :</strong> For this Project will be going to use Heroku for the deployment.</li></ul><p>Since the model will be deployed, it is saved into a pickle file (model.pkl) created by pickle, and this file will reflect in your project folder.</p><p>Pickle is a python module that enables python objects to be written to files on the disk and read back into the python program runtime.</p><pre># Creating a pickle file for the CountVectorizer<br>pickle.dump(cv, open(&#39;cv-transform.pkl&#39;, &#39;wb&#39;))</pre><pre># Creating a pickle file <br>filename = &#39;spam-sms-mnb-model.pkl&#39;<br>pickle.dump(classifier, open(filename, &#39;wb&#39;))</pre><pre># loading<br>classifier = pickle.load(open(filename, &#39;rb&#39;))<br>cv = pickle.load(open(&#39;cv-transform.pkl&#39;,&#39;rb&#39;))</pre><p><strong>Create the Webpage</strong></p><p>Will first create a web page using HTML and CSS which takes input from the users(In this case a text messages) and shows the output(predicts messages as spam or ham).</p><p>You can find code<a href="https://github.com/asthasharma98/SMS-Spam-Classifier-Deployment/tree/master/templates"> here</a>.</p><p>Flask makes it easy to write applications, and also gives a variety of choices for developing web applications.</p><p>First we need to install flask framework</p><pre>pip install flask </pre><p>Will create two files one named “app.py” file . This file is used to run the application and is engine of this app. It contains API that gets input from the user and computes a predicted value based on the model.</p><p>And another file named “sms_classifier_model.py” which contains code to build and train a Machine learning model.</p><pre># Importing essential libraries<br>from flask import Flask, render_template, request<br>import pickle</pre><p>Next will Create the Flask App</p><pre>app = Flask(__name__)</pre><p>Load the pickle</p><pre>classifier = pickle.load(open(filename, &#39;rb&#39;))<br>cv = pickle.load(open(&#39;cv-transform.pkl&#39;,&#39;rb&#39;))</pre><p>Create an app route to render the HTML template as the home page</p><pre>@app.route(&#39;/&#39;)<br>def home(): <br>    return render_template(&#39;main.html&#39;)</pre><p>Create an API that gets input from the user and computes a predicted value based on the model.</p><pre>@app.route(&#39;/predict&#39;,methods=[&#39;POST&#39;])<br>def predict():    <br>    if request.method == &#39;POST&#39;:     <br>        message = request.form[&#39;message&#39;]    <br>        data = [message]     <br>        vect = cv.transform(data).toarray()     <br>        my_prediction = classifier.predict(vect)     <br>    return render_template(&#39;result.html&#39;, prediction=my_prediction)</pre><p>Now, call the run function to start the Flask server.</p><pre>if __name__ == &#39;__main__&#39;:<br>         app.run(debug=True)</pre><p>This should return an output that shows that your app is running. Simply copy the URL and paste it into your browser to test the app.</p><h4>Step10 : Deployment on Heroku</h4><p>Heroku is a multi-language application platform that allows developers to deploy, and manage their applications. It is flexible and easy to use, offering developers the simplest path to getting their apps to market.</p><p>First Install Heroku CLI as this makes it easy to create and manage your Heroku apps directly from the terminal. You can download it from <a href="https://devcenter.heroku.com/articles/heroku-cli">here</a>.</p><p>Sign up and Log In to Heroku. Create a “Procfile” and “requirement.txt” file, which handles the configuration part in order to deploy the model into the Heroku server.</p><p><em>Follow the command below to create a Procfile</em> :</p><pre>web: gunicorn app:app</pre><p><em>The requirements file consists of the project dependencies and to install use the command given below:</em></p><pre>pip install -r requirements.txt</pre><p>Next commit your code to GitHub and connect GitHub to Heroku.</p><p>There are 2 ways to deploy your app. You could either choose automatic deploy or manual deploy. The automatic deployment will take place whenever you commit anything into your GitHub repository. By selecting the branch and clicking on deploy, build starts.</p><p>Once the model will be successfully deployed on the server your App will be created and you will get a URL.</p><p><strong>This is the link of my Web Application<em> : </em></strong><a href="https://sms-spam-predictor-nlp.herokuapp.com/"><strong><em>https://sms-spam-predictor-nlp.herokuapp.com/</em></strong></a></p><h4><strong>Conclusion</strong></h4><p>So we have successfully created a Spam SMS classifier Web Application.</p><p>This article covered all the steps for building and most importantly deploying a Spam SMS classifier machine learning model that could significantly help to reduce the chances of getting trapped by spam messages.</p><p><strong>You can refer to </strong><a href="https://github.com/asthasharma98/SMS-Spam-Classifier-Deployment"><strong>my GitHub repository</strong></a><strong> for this project.</strong></p><blockquote>Note : This was my first End-to-End Machine learning project and also my very first article on medium so please do share you feedback or suggestions so that I can improve.</blockquote><blockquote>I hope someone find this useful.</blockquote><p>Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b3488663e01" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>