<?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 Sriramya Kannepalli on Medium]]></title>
        <description><![CDATA[Stories by Sriramya Kannepalli on Medium]]></description>
        <link>https://medium.com/@sriramya.kannepalli?source=rss-4b7f634619e5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*scJnYi_nQN5mL9FTHbVa7A.jpeg</url>
            <title>Stories by Sriramya Kannepalli on Medium</title>
            <link>https://medium.com/@sriramya.kannepalli?source=rss-4b7f634619e5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 24 May 2026 04:27:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sriramya.kannepalli/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[Invoke an Amazon SageMaker endpoint using AWS Lambda]]></title>
            <link>https://medium.com/analytics-vidhya/invoke-an-amazon-sagemaker-endpoint-using-aws-lambda-83ff1a9f5443?source=rss-4b7f634619e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/83ff1a9f5443</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[amazon-sagemaker]]></category>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Sriramya Kannepalli]]></dc:creator>
            <pubDate>Fri, 01 May 2020 01:48:19 GMT</pubDate>
            <atom:updated>2020-05-01T17:37:03.857Z</atom:updated>
            <content:encoded><![CDATA[<h4>Step-by-step guide for calling an Amazon SageMaker XGBoost regression model endpoint using API Gateway and AWS Lambda</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FWmfC7SvtZxsSNdF" /><figcaption>Photo by <a href="https://unsplash.com/@heyerlein?utm_source=medium&amp;utm_medium=referral">h heyerlein</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Assuming you are here because you already have a deployed SageMaker ML model endpoint, trying to understand the process of hosting it using AWS Lambda functions. If yes, then let’s get started..</p><p><strong>Note :</strong> If not, you can create a XGBoost SageMaker endpoint by reading my previous blog <a href="https://medium.com/@sriramya.kannepalli/random-forest-and-xgboost-on-amazon-sagemaker-and-aws-lambda-29abd9467795">Random Forest and XGBoost on Amazon SageMaker</a> and implement this jupyter notebook.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/867cae4bd72dce0a07f95847bdeda816/href">https://medium.com/media/867cae4bd72dce0a07f95847bdeda816/href</a></iframe><h3><strong>Where is my Endpoint ?</strong></h3><p>Now after training and deploying the model in SageMaker, you can copy the name of your deployed endpoint from SageMaker&gt;Inference&gt;endpoints from SageMaker Console. We will be using the endpoint name while defining the environment variables in AWS Lambda function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uzM1orMdBymMqQoKFYYh0w.png" /></figure><h3><strong>Creating AWS Lambda Function</strong></h3><p>Search for ‘Lambda’ in AWS console and click on ‘create function’ under functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*McEka_eHbLH-cQm92p0bzQ.png" /><figcaption>Screenshot — Create new Function in AWS Lambda</figcaption></figure><p>Select Runtime — Python 3.6 and add the below sample code in Function code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebff6f0e37989e8cc217958f8b9e8786/href">https://medium.com/media/ebff6f0e37989e8cc217958f8b9e8786/href</a></iframe><p>and click on ‘Save’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wAyNRhHbioZcPfrfWxRwgQ.png" /><figcaption>Sample lambda_function-Code in python</figcaption></figure><p>Click on edit Environment Variables &gt; Add environment variable and add</p><p>Key : ‘ENDPOINT_NAME’</p><p>Value: ‘&lt;Your-Endpoint-name&gt;’ and click ‘Save’.</p><p>If you are implementing the XGBoost model endpoint used in the above sample tutorial then your value string may be in format :</p><p>Value: ‘<a href="https://console.aws.amazon.com/sagemaker/home?region=us-east-1#/endpoints/xgboost-2020-04-30-22-01-11-369">xgboost-YEAR–MONTH–DATE–xx–xx–xx–</a>xxx’</p><h3>Defining IAM role</h3><p>Then scroll up and click on ‘Permissions’ tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LC0H7GgoH4vj2FqK69VVMw.png" /></figure><p>Click on Execution Role &gt; Role name</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d4pl_7TEIo6L6TvcadBGcg.png" /></figure><p>You well be redirected to IAM Console.</p><ol><li>Click on your policy under Policy Name.</li><li>Click on edit policy &gt; JSON</li><li>Add comma at the end of existing JSON string and include the following string at the end.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30de5ff3caaaf6470eded50b52f26e78/href">https://medium.com/media/30de5ff3caaaf6470eded50b52f26e78/href</a></iframe><p>4. Don’t forget to click ‘Review Policy’ and ‘Save Changes’.</p><p>This will give your Lambda function permission to invoke a SageMaker model endpoint.</p><h3><strong>API Gateway</strong></h3><p>Now search for API Gateway in AWS Console</p><ul><li>Click on ‘Import’ under REST API section.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-b8t_ZuA_ZE2E9YjkrjdOw.png" /></figure><ul><li>Select ‘New API’ under ‘Create new API’.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hZDbAZjlTSqQVzb342LNow.png" /></figure><ul><li>Enter ‘API name’ in Settings and click on ‘Create API’. You will be redirected to below screen —</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lB10JhsY1sww_W43tdzM7A.png" /></figure><ul><li>Click on ‘Create Resource’. Enter ‘Resource Name’ and click ‘Create Resource’. For e.g. I named my resource ‘housing-predictor’</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lh-XfbFAu35N-EiX9YMvBA.png" /></figure><ul><li>Click on ‘Actions’ and ‘Create Method’</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HlmBQDzF3G6PJDonpBq3-g.png" /></figure><ul><li>Select ‘POST’ method and click on ‘✔️ ’.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UGTjbuqMPu6br_dmD4k3gQ.png" /></figure><ul><li>Enter Lambda Function name and click on ‘save’.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YkpRBUyRitXoj99oKJ3DRA.png" /></figure><ul><li>Now go to ‘Actions’ and hit ‘Deploy API’.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*99sbhAmWQiIyNnXsqoCrHA.png" /></figure><ul><li>Select ‘New Stage’ and enter Stage Name. For e.g test or prod and click on ‘Deploy’.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XihM_bbobZ0_P0h5htPbFA.png" /></figure><ul><li>Now click on POST under Stages &gt; test and copy the Invoke URL ending with &lt;your-function-name&gt;</li></ul><p>Note: Your URL should end with &lt;your function-name&gt; and not ‘test’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3daoOTSh0I3IflDDQ-Koqg.png" /></figure><p>Now that we have the Lambda function, an API Gateway, and the test data(copy single data point from your test data), let’s test it using Postman, which is an HTTP client for testing web services. You can download the latest version of Postman <a href="https://www.getpostman.com/apps">here</a>.</p><p>Place the Invoke URL into Postman as shown in the following screenshot and choose POST as method. In the Body tab, place the test data as shown in the following screenshot. Choose the Send button and you will see the returned result as “1005792.625” for the case of the test data shown in XGBoost tutorial.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QM1M8u6N1j8qoaDn62V8KA.png" /></figure><p>Hurrah!! 🎊🎉🎊 You have created a model endpoint deployed and hosted by Amazon SageMaker. Then you called the endpoint using serverless architecture(an API Gateway and a Lambda function) that invoke the endpoint.</p><p>Now you know how to call a machine learning model endpoint hosted by Amazon SageMaker using AWS Lamda serverless Functions.. Congratulations !!! 👏👏👏</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hQtgBbFNsFPRHdi_" /><figcaption>Photo by <a href="https://unsplash.com/@kirbyphotography?utm_source=medium&amp;utm_medium=referral">Susan Quiles Photography</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83ff1a9f5443" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/invoke-an-amazon-sagemaker-endpoint-using-aws-lambda-83ff1a9f5443">Invoke an Amazon SageMaker endpoint using AWS Lambda</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Random Forest and XGBoost on Amazon SageMaker and AWS Lambda]]></title>
            <link>https://medium.com/analytics-vidhya/random-forest-and-xgboost-on-amazon-sagemaker-and-aws-lambda-29abd9467795?source=rss-4b7f634619e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/29abd9467795</guid>
            <category><![CDATA[amazon-sagemaker]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[random-forest]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[xgboost]]></category>
            <dc:creator><![CDATA[Sriramya Kannepalli]]></dc:creator>
            <pubDate>Thu, 30 Apr 2020 17:58:06 GMT</pubDate>
            <atom:updated>2020-05-01T17:37:18.745Z</atom:updated>
            <content:encoded><![CDATA[<h4>Step-by-Step process for implementing regression model using Random Forest and XGBoost on Amazon SageMaker and AWS Lambda Functions.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IZIaoV1UX2pietpQ" /><figcaption>Photo by <a href="https://unsplash.com/@ikukevk?utm_source=medium&amp;utm_medium=referral">Kevin Ku</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>I wrote this blog as a part of my virtual talk on<a href="https://www.meetup.com/minneapolis-wimlds/events/270064273/"> Deploying ML models using Amazon Sagemaker and Lambda functions</a> in <a href="https://www.meetup.com/minneapolis-wimlds">Minneapolis Women in Machine Learning &amp; Data Science</a>(WiMLDS). So, here we go -</p><p>The best way to learn how to use Amazon SageMaker is to create, train, and deploy a simple machine learning model on it, we will take a top down approach, we will directly login into AWS Console, start a SageMaker notebook instance, understand Decision Trees(building block of Random forest and XGBoost) and then train and deploy the endpoints to AWS Lambda.</p><h3><strong>Let’s get started..</strong></h3><ol><li>Log in into <a href="https://aws.amazon.com/">AWS Management Console</a></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LpircPJGwSBF8PWu0h7bvA.png" /></figure><p>2. Search for Amazon SageMaker in ‘Find Services’ and open SageMaker dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GV13hAdgC1HGtwA1fnz-fQ.png" /></figure><p>3. Click on Notebook instances and Create Notebook instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*xpj0Dwac9LHptqIdRZWpDQ.png" /></figure><p>4. Enter the Notebook instance name.</p><p>Select Notebook instance type ‘ml.t2.medium’ from the dropdown. We only plan to use this notebook instance as development environment and rely-on the on-demand environment to execute heavy lifting training and deployment jobs i.e. We will assign ‘ml.m4.xlarge’ instance in our training and deployment scripts. For info on other notebook instance types, please refer <a href="https://aws.amazon.com/sagemaker/pricing/">Amazon SageMaker Pricing.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1sgpiz4sApNLWm8I0zfKxQ.png" /></figure><p>5. Grant permissions to the notebook instance through IAM role, so that necessary AWS resources can be accessed from the notebook without the need to provide AWS credentials every time.</p><p>If you don’t have IAM role in place, Amazon SageMaker will automatically create a role for you with your permission.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nNLQD-S6895rYAIZiNpTyQ.png" /></figure><p>6. Click on ‘Create Notebook Instance’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*96GZZ-oS39CLigPJOedLHg.png" /></figure><p>7. It takes around 1–2 mins to change into ‘Active’ status from ‘Pending’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7PM48hu8POmWY-2gLwk4bA.png" /></figure><p>8. Now Click on ‘Open Jupyter’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*day5Sym8cmiW1arExWqGMg.png" /></figure><p>9. You can upload your own files from local using ‘upload’ similar to what you do in a normal Jupyter notebook interface.Remember these files are getting saved in the current ‘ml.t2.notebook’ instance and if you decide to delete the notebook instance after your work is done, you will loose the files too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D_zxZbOYLh4LKCX-axwM9g.png" /></figure><p>10. If you are new to SageMaker, you can always refer to the huge list of ‘SageMaker examples’ written by AWS SMEs as a start point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kWeMFlvbUmjePd9q_PoIVQ.png" /></figure><p>Now moving on to the <strong>Regression with Random Forest &amp; Amazon SageMaker XGBoost algorithm,</strong> to do this, you need the following:</p><ol><li><strong>A dataset</strong>. We will use <a href="https://www.kaggle.com/harlfoxem/housesalesprediction">Kaggle dataset : House sales predicition in King County, Seattle US</a>. This dataset contains sale prices of houses sold in King County, Seattle, between May 2014 and May 2015.It’s a great dataset for evaluating simple regression models.</li><li><strong>An algorithm</strong>. We will use the Random Forest algorithm in scikit-learn and XGBoost Algorithm provided by Amazon SageMaker to train the model using the housing dataset and predict the prices.</li></ol><p>You also need a few resources for storing your data and running the code in Amazon SageMaker:</p><ol><li>An <strong>Amazon Simple Storage Service (Amazon S3) bucket</strong> to store the training data and the model artifacts that Amazon SageMaker creates when it trains the model( don’t worry move on, we will assign this in our code below)</li><li>An <strong>Amazon SageMaker notebook</strong> instance to prepare and process data and to train and deploy a machine learning model (We already started a notebook instance above)</li><li>A <strong>Jupyter notebook</strong> to use with the notebook instance to prepare your training data and train and deploy the model (If are following along from the beginning, we have our Jupyter notebook open)</li></ol><p>We will be writing our code in Python 3 -</p><p><strong>Important: </strong>To train, deploy, and validate a model in Amazon SageMaker, you can use one of these methods.</p><ul><li>Amazon SageMaker Python SDK.</li><li>AWS SDK for Python (Boto 3).</li></ul><h3>Amazon Sagemaker Python SDK vs AWS SDK for Python(Boto 3)</h3><p>The Amazon SageMaker Python SDK abstracts several implementation details, and is easy to use. If you’re a first-time Amazon SageMaker user, aws recommends that you use it to train, deploy, and validate the model.</p><p>On the other hand, Boto 3 is the Amazon Web Services (AWS) SDK for Python. It enables Python developers to create, configure, and manage AWS services, such as EC2 and S3. Boto provides an easy to use, object-oriented API, as well as low-level access to AWS services.</p><p>Today we will learn how to create all of the resources that you need to train, and deploy a model using <strong>Amazon SageMaker Python SDK</strong>.</p><p>The steps include:</p><ol><li>Fetching the dataset.</li><li>Explore and Transform the Training Data so that it can be fed to Amazon SageMaker algorithms.</li><li>Feature Engineering and Data Visualizations.</li><li>Prepare the data.</li><li>Data Ingestion.</li><li>Train a Model.</li><li>Launching a training job with the Python SDK.</li><li>Deploy the Model to Amazon SageMaker.</li><li>Validate the Model.</li><li>Integrating Amazon SageMaker Endpoints into Internet-facing Applications.</li><li>Clean up</li></ol><p>Before we start working with the data let’s quickly understand —</p><p><strong><em>What is a Decision Tree and how Tree Ensembles form the basis for Random Forest and XG Boost?</em></strong></p><p>Let’s start with a decision tree :</p><h3>Decision Tree</h3><ul><li>A decision tree is built top-down from a root node and involves partitioning the data into subsets that contain instances with similar values (homogeneous).</li><li>Decision tree builds regression or classification models in the form of a tree structure.</li></ul><p>The process of repeatedly partitioning the data to obtain homogeneous groups is called recursive partitioning.</p><p>Step 1: Identify the binary question that splits data points into two groups that are most homogeneous.</p><p>Step 2: Repeat Step 1 for each leaf node, until a stopping criterion is reached.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/0*IyPDTZaghEvHr6sJ" /><figcaption><em>Source : Diego Lopez Yse (Apr 17, 2019). Decision tree. Retrieved from Medium: </em><a href="https://towardsdatascience.com/the-complete-guide-to-decision-trees-28a4e3c7be14"><em>https://towardsdatascience.com/the-complete-guide-to-decision-trees-28a4e3c7be14</em></a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/0*LHTqG1p6cymet8fG" /><figcaption><em>Source : Diego Lopez Yse (Apr 17, 2019). Decision tree. Retrieved from Medium: </em><a href="https://towardsdatascience.com/the-complete-guide-to-decision-trees-28a4e3c7be14"><em>https://towardsdatascience.com/the-complete-guide-to-decision-trees-28a4e3c7be14</em></a></figcaption></figure><h3>Fable of blind men and elephant</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hzKctBrL6go-W0I3.jpeg" /><figcaption><em>Source: Jinde Shubham.(Jul 3, 2018). Ensemble learning is Fable of blind men and elephant. Retrieved from Medium: </em><a href="https://becominghuman.ai/ensemble-learning-bagging-and-boosting-d20f38be9b1e"><em>https://becominghuman.ai/ensemble-learning-bagging-and-boosting-d20f38be9b1e</em></a></figcaption></figure><p>The main principle behind the ensemble model is that a group of weak learners come together to form a strong learner, thus increasing the accuracy of the model. In the above picture, four blind men are trying to predict an elephant by touching its parts. Though their predictions are right in their own perspective but they are weak learners in term of predicting an elephant. When these weak learners discuss together they can identify an elephant, hence forming an ensemble.</p><h3>Wisdom of the Crowd</h3><blockquote><em>“In an ensemble, predictions could be combined either by majority-voting or by taking averages. Below is an illustration of how an ensemble formed by majority-voting yields more accurate predictions than the individual models it is based on: ”</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/0*OTemhIJzbDEKKK_M" /><figcaption><em>Source : Annalyn Ng and Kenneth Soo (July 27, 2016). How a tree is created in a random forest. Retrieved from algobeans.com: </em><a href="https://algobeans.com/2016/07/27/decision-trees-tutorial/"><em>https://algobeans.com/2016/07/27/decision-trees-tutorial/</em></a></figcaption></figure><h3><strong>Bagging and Boosting:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/0*FY_3SjJ2YSz-zckV" /><figcaption><em>Source: Zulaikha Lateef(Jun 28,2019). Bagging and Boosting . Retrieved from Edureka.co :</em><a href="https://www.edureka.co/blog/boosting-machine-learning/"><em>https://www.edureka.co/blog/boosting-machine-learning/</em></a></figcaption></figure><h4>Bagging:</h4><blockquote><em>“ </em><strong><em>Refers to non-sequential learning</em></strong><em>.</em></blockquote><blockquote><em>- For T rounds, a random subset of samples is drawn (with replacement) from the training sample.</em></blockquote><blockquote><em>- Each of these draws are independent of the previous round’s draw but have the same distribution.</em></blockquote><blockquote><strong><em>- These randomly selected samples are then used to grow a decision tree (weak learner). The most popular class (or average prediction value in case of regression problems) is then chosen as the final prediction value.</em></strong></blockquote><blockquote><em>The bagging approach is also called bootstrapping.”</em></blockquote><h4>Boosting:</h4><blockquote><em>“ Boosting describes the combination of many weak learners into one very accurate prediction algorithm.</em></blockquote><blockquote><em>- A weak learner refers to a learning algorithm that only predicts slightly better than randomly.</em></blockquote><blockquote><em>- When looking at tree-based ensemble algorithms a single decision tree would be the weak learner and the combination of multiple of these would result in the AdaBoost algorithm, for example.</em></blockquote><blockquote><strong><em>- The boosting approach is a sequential algorithm that makes predictions for T rounds on the entire training sample and iteratively improves the performance of the boosting algorithm with the information from the prior round’s prediction accuracy.</em></strong><em> “</em></blockquote><p><em>Source: Julia Nikulski(Mar 16, 2020). Bagging and Boosting. Retrieved from Medium: https://towardsdatascience.com/the-ultimate-guide-to-adaboost-random-forests-and-xgboost-7f9327061c4f</em></p><h3>Random Forest</h3><p>Now, Random Forest is a combination of tree ensemble and bagging.</p><blockquote><em>“ A random forest is an example of an ensemble, which is a combination of predictions from different models. It also uses bagging. Bagging is used to create thousands of decision trees with minimal correlation. In bagging, a random subset of the training data is selected to train each tree. Furthermore, the model randomly restricts the variables which may be used at the splits of each tree. Hence, the trees grown are dissimilar, but they still retain certain predictive power.”</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/0*IYpwU8NX5JAWTGNf" /><figcaption><em>Source : Annalyn Ng and Kenneth Soo (July 27, 2016). Wisdom of crowd . Retrived from algobeans.com: </em><a href="https://algobeans.com/2016/07/27/decision-trees-tutorial/"><em>https://algobeans.com/2016/07/27/decision-trees-tutorial/</em></a></figcaption></figure><blockquote><em>“In the above example, there are 9 variables represented by 9 colors. </em><strong><em>At each split, a subset of variables is randomly sampled from the original 9. Within this subset, the algorithm chooses the best variable for the split.</em></strong><em> The size of the subset was set to the square root of the original number of variables. Hence, in our example, this number is 3.”</em></blockquote><p>Now with this understanding let’s move on to<em> </em><strong>Random Forest implementation on Amazon SageMaker Notebook Instance.</strong> For this you need to download the Jupyter notebook from <a href="https://github.com/SriramyaK/My-WiMLDS-Minneapolis-Talks/blob/master/Random%20Forest%20and%20XGBoost%20Final%20V%204.0%20-%2025042020.ipynb">here</a> and data from <a href="https://www.kaggle.com/harlfoxem/housesalesprediction">here</a>. Upload them into your SageMaker notebook instance as explained above and follow along.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee680fe5ec8ca94701bd7676730f4f24/href">https://medium.com/media/ee680fe5ec8ca94701bd7676730f4f24/href</a></iframe><h3>XGBoost Algorithm</h3><p>XGBoost (eXtreme Gradient Boosting) was introduced by Chen &amp; Guestrin in 2016.</p><p>It was developed mainly to <strong>increase speed and performance, while introducing regularization parameters to reduce overfitting.</strong></p><ul><li>To begin with, let us first learn about the model choice of XGBoost: decision tree ensembles. The tree ensemble model consists of a set of classification and regression trees (CART). Here’s a simple example of a CART that classifies whether someone will like a hypothetical computer game X.</li><li>We classify the members of a family into different leaves, and assign them the score on the corresponding leaf. A CART is a bit different from decision trees, in which the leaf only contains decision values. In CART, a real score is associated with each of the leaves, which gives us richer interpretations that go beyond classification. This also allows for a principled, unified approach to optimization.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TMDgawy-x0aMRI-BSjpbDw.png" /></figure><p>So Let’s get started with XGBoost implementation on Sagemaker —</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/867cae4bd72dce0a07f95847bdeda816/href">https://medium.com/media/867cae4bd72dce0a07f95847bdeda816/href</a></iframe><h3>Integrating Amazon SageMaker Endpoints into Internet-facing Applications</h3><p>In a production environment, you might have an internet-facing application sending requests to the endpoint for inference. The following high-level example shows how to integrate your model endpoint into your application.</p><p>For an example of how to use Amazon API Gateway and AWS Lambda to set up and deploy a web service that you can call from a client application -</p><ul><li>Create an IAM role that the AWS Lambda service principal can assume. Give the role permissions to call the Amazon SageMaker InvokeEndpoint API.</li><li>Create a Lambda function that calls the Amazon SageMaker InvokeEndpoint API.</li><li>Call the Lambda function from a mobile application.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/0*UPds7UwLoTSDWVyh.gif" /></figure><p>Starting from the client side,</p><ul><li>A client script calls an Amazon API Gateway API action and passes parameter values.</li><li>API Gateway is a layer that provides API to the client. In addition, it seals the backend so that AWS Lambda stays and executes in a protected private network.</li><li>API Gateway passes the parameter values to the Lambda function.</li><li>The Lambda function parses the value and sends it to the SageMaker model endpoint.</li><li>The model performs the prediction and returns the predicted value to AWS Lambda. The Lambda function parses the returned value and sends it back to API Gateway. API Gateway responds to the client with that value.</li></ul><h3>But, what is AWS Lambda ?</h3><ul><li>AWS Lambda is a compute service, serverless computing platform provided by Amazon as a part of AWS that lets you run code without provisioning or managing servers.</li><li>It is a computing service that runs code in response to events and automatically manages the computing resources required by that code.</li></ul><p>For integrating the endpoints created in this notebook with AWS Lambda please read my blog <a href="https://medium.com/@sriramya.kannepalli/invoke-an-amazon-sagemaker-endpoint-using-aws-lambda-83ff1a9f5443?source=your_stories_page---------------------------">Invoke an Amazon SageMaker endpoint using AWS Lambda</a>.</p><p>Final words on <a href="https://aws.amazon.com/sagemaker/pricing/">Amazon Sagemaker Pricing</a> -</p><p>Try Amazon SageMaker for two months, free!</p><blockquote>As part of the AWS Free Tier, you can get started with Amazon SageMaker for free. If you have never used Amazon SageMaker before, for the first two months, you are offered a monthly free tier of 250 hours of t2.medium or t3.medium notebook usage for building your models, plus 50 hours of m4.xlarge or m5.xlarge for training, plus 125 hours of m4.xlarge or m5.xlarge for deploying your machine learning models for real-time inferencing and batch transform with Amazon SageMaker. Your free tier starts from the first month when you create your first SageMaker resource.</blockquote><h3>References</h3><ol><li>Diego Lopez Yse(Apr 17, 2019). Decision tree. Retrieved from Medium: <a href="https://towardsdatascience.com/the-complete-guide-to-decision-trees-28a4e3c7be14">https://towardsdatascience.com/the-complete-guide-to-decision-trees-28a4e3c7be14</a></li><li>Jinde Shubham.(Jul 3, 2018). Ensemble learning is Fable of blind men and elephant. Retrieved from Medium :<a href="https://becominghuman.ai/ensemble-learning-bagging-and-boosting-d20f38be9b1e">https://becominghuman.ai/ensemble-learning-bagging-and-boosting-d20f38be9b1e</a></li><li>Tianqi Chen and Carlos Guestrin. 2016. XGBoost: A Scalable Tree Boosting System. In Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (KDD ’16). Association for Computing Machinery, New York, NY, USA, 785–794. DOI:<a href="https://doi.org/10.1145/2939672.2939785">https://doi.org/10.1145/2939672.2939785</a></li><li>Annalyn Ng and Kenneth Soo (July 27, 2016). How a tree is created in a random forest. Retrived from algobeans.com: <a href="https://algobeans.com/2016/07/27/decision-trees-tutorial/">https://algobeans.com/2016/07/27/decision-trees-tutorial/</a></li><li>AWS SageMaker Screenshots and figures. Retrieved from Amazon Web Services, Inc. : <a href="https://docs.aws.amazon.com/sagemaker/#amazon-sagemaker-overview">https://docs.aws.amazon.com/sagemaker/#amazon-sagemaker-overview</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29abd9467795" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/random-forest-and-xgboost-on-amazon-sagemaker-and-aws-lambda-29abd9467795">Random Forest and XGBoost on Amazon SageMaker and AWS Lambda</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick setup instructions for installing PyTorch and fastai on Raspberry Pi 4]]></title>
            <link>https://medium.com/analytics-vidhya/quick-setup-instructions-for-installing-pytorch-and-fastai-on-raspberry-pi-4-5ffbe45e0ae3?source=rss-4b7f634619e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ffbe45e0ae3</guid>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[fastai]]></category>
            <dc:creator><![CDATA[Sriramya Kannepalli]]></dc:creator>
            <pubDate>Sat, 04 Apr 2020 04:33:21 GMT</pubDate>
            <atom:updated>2020-04-04T15:00:19.145Z</atom:updated>
            <content:encoded><![CDATA[<h4>PyTorch and fastai on Raspberry Pi 4 Model B for doing deep learning tasks like image classification and object detection.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/0*S8KZSrx4Y00wrsGc.png" /><figcaption>source: <a href="https://www.raspberrypi.org/products/raspberry-pi-4-model-b/">https://www.raspberrypi.org/products/raspberry-pi-4-model-b/</a></figcaption></figure><p>Yes, like everyone who just started with Raspberry Pi to test their deep learning models, even I got too excited and curious to deploy my image classifier <a href="https://github.com/SriramyaK/Baby-Vibes-Pytorch-fastai-Raspberry-pi-4">Baby_Vibes</a> built with deep learning libraries PyTorch and fastai on my brand new Raspberry Pi 4 model B brought from <a href="https://www.amazon.com/CanaKit-Raspberry-Starter-32GB-Official/dp/B07VDGKN51">amazon.com</a></p><p>Before I could jump into working with my model inference, there was no clear documentation readily available for setting up Raspberry Pi 4 with Pytorch and Fastai on Python 3.7. However, I found this discussion link from <a href="https://forums.fast.ai/t/deployment-on-raspberry-pi/52935/2">fastai</a> forums very useful to get started.</p><p>Let’s quickly understand what are we dealing with —</p><p><strong>What is PyTorch?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*eKDmQyXgeaicq2YVaDruLw.png" /><figcaption>Source : <a href="https://pytorch.org/">https://pytorch.org/</a></figcaption></figure><blockquote>PyTorch is an open source machine learning library based on the Torch library, used for applications such as computer vision and natural language processing. It is primarily developed by Facebook’s AI Research lab. It is free and open-source software released under the Modified BSD license.</blockquote><p>There are several PyTorch online tutorials and YouTube videos available now but still to highlight my favorites : the <a href="https://pytorch.org/tutorials/">official PyTorch tutorials</a> and <a href="https://course.fast.ai/">fastai — Practical Deep Learning for Coders, v3</a></p><p><strong>What is Fast.ai?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/265/0*QT1RXdqreuz8Bf9U.png" /><figcaption>source: <a href="https://www.fast.ai/">https://www.fast.ai/</a></figcaption></figure><blockquote>fastai is a modern deep learning library, <a href="https://github.com/fastai/fastai">available from GitHub</a> as open source under the Apache 2 license, which can be installed directly using the conda or pip package managers. It includes <a href="https://docs.fast.ai/">complete documentation and tutorials</a>, and is the subject of the book <em>Deep Learning for Coders with fastai and PyTorch: AI Applications Without a PhD</em> (Howard and Gugger <a href="https://www.fast.ai/2020/02/13/fastai-A-Layered-API-for-Deep-Learning/#ref-dlbook">2020</a>).</blockquote><p><strong>And finally what is Raspberry Pi 4?</strong></p><blockquote>Your tiny, dual-display, desktop computer</blockquote><blockquote>…and robot brains, smart home hub, media centre, networked AI core, factory controller, and much more..</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PD2CkIgp6urj5RCt" /><figcaption>Raspberry Pi 4 Model B</figcaption></figure><p>Below are the libraries/packages we will be installing -</p><ol><li>Python 3.7</li><li>PyTorch dependencies</li><li>torch</li><li>torchvision</li><li>fast.ai</li><li>fast.ai dependencies</li></ol><p><strong>Note:</strong> If this is the first time you are switching on your Raspberry Pi, please refer <a href="https://www.youtube.com/watch?v=BpJCAafw2qE&amp;t=749s">Raspberry Pi 4 Getting Started video</a> and complete the initial boot up. Once your are done, open “Terminal” as shown below -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8Tw9kTOJ15TJsczQ" /><figcaption>Raspberry Pi 4 Model B Terminal Screen</figcaption></figure><p>Run the below command to get hold of the <strong>ARM processor configuration</strong> of our Pi required for searching compatible PyTorch wheel -</p><pre>uname -a</pre><p>If the output is<strong> armv7l GNU/Linux </strong>continue with the installation.</p><p><strong>Wait !!! What is ARM processor and how do they differ from Intel processors present in most of our desktop PCs ??</strong></p><blockquote><strong>ARM (Advanced RISC(Reduced Instruction Set Computing) Machines ) </strong>has been at the center of modern microprocessors and embedded design.</blockquote><blockquote>ARM processors<strong> </strong>are extensively used in consumer electronic devices such as smartphones, tablets, multimedia players and other mobile devices, such as wearables. Because of their reduced instruction set, they require fewer transistors, which enables a smaller die size for the integrated circuitry (IC).</blockquote><blockquote><strong>Intel processors</strong>, on the other hand, fit into a family called <strong>CISC which stands for Complex Instruction Set Computing.</strong></blockquote><blockquote>Unlike RISC computers, the instructions available on a CISC are more focused on performing complex tasks with large amounts of flexibility. Intel, for its part, has mainly produced processors aimed at high performance and high throughput environments, including desktop PCs, laptops, servers, and even supercomputers.</blockquote><p>If you are interested to know more read this — <a href="https://www.allaboutcircuits.com/news/understanding-the-differences-between-arm-and-x86-cores/">Understanding the Differences Between ARM and x86 Processing Cores</a>.</p><p>So that’s the reason why we cannot use a python package from our PC/Laptop/standard x86_64 machine directly into our Raspberry Pi since it will not be compatible with the processor architecture of Pi, instead python packages installed in Pi should be compiled for its specific architecture.</p><p>This being said there are two ways of installing PyTorch on Raspberry Pi:</p><ol><li>Building PyTorch from source: If you are interested in this , please refer to the amazing blog — <a href="https://nmilosev.svbtle.com/compling-arm-stuff-without-an-arm-board-build-pytorch-for-the-raspberry-pi">Building PyTorch for the Raspberry Pi boards</a></li><li>Using pre-built PyTorch wheels uploaded by some great people who did all the hard work for us.</li></ol><p>We will be going with the easy one, option 2 and using the pre-built PyTorch wheels uploaded by others compatible with <strong>armv7l GNU/Linux.</strong></p><p>So go ahead and download <a href="https://wintics-opensource.s3.eu-west-3.amazonaws.com/torch-1.3.0a0%2Bdeadc27-cp37-cp37m-linux_armv7l.whl">torch-1.3</a> and <a href="https://drive.google.com/uc?export=download&amp;id=1nhk7PKDUzcmGGwnx7PK7iW3__2fOJVl1">torchvision-0.4</a> wheel files and copy them to your pi with USB or directly download from the links using chromium browser in your Pi.</p><p>Python has two flavors, Python 2x and Python 3x. We will be working with Python3x for our installations.</p><p>In a terminal window, check for python 3.7 by typing :</p><pre>python3 --version</pre><p>If you get python version as 3.7, continue with the installation, if not then refer <a href="https://installvirtual.com/install-python-3-7-on-raspberry-pi/">How to install Python 3.7 on Raspberry Pi</a>. If you are new to virtual environments please refer <a href="https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/">this</a> and move on.</p><pre>sudo apt update &amp;&amp; sudo apt upgrade<br>mkdir project_folder<br>cd project_folder<br>python3 -m venv env<br>source env/bin/activate</pre><p>Install PyTorch dependencies first:</p><pre>sudo apt install libopenblas-dev libblas-dev m4 cmake cython python3-dev python3-yaml python3-setuptools python3-wheel python3-pillow python3-numpy</pre><p>Ensure torch and torchvision wheel files are saved in the project_folder and type in terminal:</p><pre>sudo apt install libatlas3-base</pre><pre>sudo pip3 install numpy</pre><pre>python3 -m pip install Pillow==6.1</pre><pre>pip3 install torch-1.3.0a0+deadc27-cp37-cp37m-linux_armv7l.whl</pre><pre>pip3 install torchvision-0.4.0a0+d31eafa-cp37-cp37m-linux_armv7l.whl</pre><pre>pip3 install fastai --no-deps</pre><p>To test if everything is installed correctly, log into your python terminal and run the commands:</p><pre>$ python3.7</pre><pre>&gt;&gt;&gt; import torch</pre><pre>&gt;&gt;&gt; import torchvision</pre><pre>&gt;&gt;&gt; import fastai</pre><p>If you get further errors while doing —</p><pre>from fastai.vision import *</pre><p>Create new text file in project_folder and copy below contents. Name it requirements.txt</p><pre>beautifulsoup4<br>bottleneck<br>fastprogress&gt;=0.2.1<br>matplotlib<br>numexpr<br>nvidia-ml-py3<br>packaging<br>pandas<br>pyyaml<br>requests<br>scipy</pre><p>Now type in terminal:</p><pre>pip3 install -r requirements.txt</pre><p>This should resolve your error and import torch, torchvision and fastai successfully for vision projects. We have skipped spacy dependency needed for the fastai text package, so for vision it should work. Refer <a href="https://forums.fast.ai/t/deployment-on-raspberry-pi/52935/3">fastai forums discussions.</a></p><p><strong>Final Note :</strong> You may get warnings if you used a different version of PyTorch for training your model file ‘export.pkl’ and installed a different version of PyTorch on pi. If you feel these warnings can be ignored, python has a warnings module in <a href="https://docs.python.org/3/library/warnings.html">sys-system specific parameters and functions</a> library and this is how you can handle it -</p><pre><strong>import</strong> <strong>sys</strong><br><br><strong>if</strong> <strong>not</strong> sys.warnoptions:<br>    <strong>import</strong> <strong>warnings</strong><br>    warnings.simplefilter(&quot;ignore&quot;)</pre><p>Add this code snippet to your inference.py or app.py file.</p><p>If you could come along up to here. Pheww.. Yes we did it !! we are all set to test our deep learning PyTorch fastai image classification model inference on Raspberry pi 4 Model b. Hurray!!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FMOWPkhRAUbR7i%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fexcited-applause-minions-MOWPkhRAUbR7i&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2FMOWPkhRAUbR7i%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="196" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9269748f7d375e66eeb341ae47e9dfd/href">https://medium.com/media/a9269748f7d375e66eeb341ae47e9dfd/href</a></iframe><p>If you want a sample code for testing, please clone Baby-Vibes <a href="https://github.com/SriramyaK/Baby-Vibes-Pytorch-fastai-Raspberry-pi-4">github</a> and start working.</p><p>Baby-Vibes uses Image classification to identify crying baby and pass a Voice command to Google Home to play their favorite cartoon for e.g. Tom and Jerry in this case, while we excuse us from every one and come to their rescue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1G6VecD1d44J8Qhhw85jMA.png" /></figure><p>If you are interested in learning Pytorch fastai Azure Web service deployment you can refer <a href="https://medium.com/analytics-vidhya/pytorch-web-service-deployment-using-azure-machine-learning-service-and-azure-web-apps-from-vs-code-a1ba75e43520">this article.</a></p><p>Happy Coding !!!😊😊😊</p><p>References:</p><ul><li><a href="https://discuss.pytorch.org/t/pytorch-1-3-wheels-for-raspberry-pi-python-3-7/58580">PyTorch 1.3 wheels for Raspberry Pi (Python 3.7)</a></li><li><a href="https://forums.fast.ai/t/deployment-on-raspberry-pi/52935/3">Deployment on Raspberry Pi</a></li><li><a href="https://github.com/nmilosev/pytorch-arm-builds">nmilosev/pytorch-arm-builds</a></li><li><a href="https://medium.com/secure-and-private-ai-writing-challenge/a-step-by-step-guide-to-installing-pytorch-in-raspberry-pi-a1491bb80531">A Step by Step guide to installing PyTorch in Raspberry Pi</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ffbe45e0ae3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/quick-setup-instructions-for-installing-pytorch-and-fastai-on-raspberry-pi-4-5ffbe45e0ae3">Quick setup instructions for installing PyTorch and fastai on Raspberry Pi 4</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PyTorch Web Service deployment using Azure Machine Learning Service and Azure Web Apps from VS Code]]></title>
            <link>https://medium.com/analytics-vidhya/pytorch-web-service-deployment-using-azure-machine-learning-service-and-azure-web-apps-from-vs-code-a1ba75e43520?source=rss-4b7f634619e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1ba75e43520</guid>
            <category><![CDATA[azure-container-service]]></category>
            <category><![CDATA[fastai]]></category>
            <category><![CDATA[azure-web-app]]></category>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[azure-machine-learning]]></category>
            <dc:creator><![CDATA[Sriramya Kannepalli]]></dc:creator>
            <pubDate>Fri, 20 Mar 2020 19:34:35 GMT</pubDate>
            <atom:updated>2020-03-21T15:00:53.976Z</atom:updated>
            <content:encoded><![CDATA[<p>This blog is mainly focused on deploying a PyTorch fastai deep learning Image Classification model to Azure Web apps/Azure Web Services using Azure machine learning SDK and VS Code in Linux.</p><figure><img alt="Image classifier to detect crying babies and play Tom and Jerry to make them happy!!" src="https://cdn-images-1.medium.com/max/1024/0*pmSA65aiPka5iUy3" /><figcaption>Photo by <a href="https://unsplash.com/@zoncoll?utm_source=medium&amp;utm_medium=referral">Valeria Zoncoll</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><ol><li>Data collection and prototyping in Google Colab</li><li>Training on Azure Machine Learning service.</li><li>Deployment in Azure Container Instances as Azure Web Service.</li><li>Consuming the web service from front end deployed as a Python flask Azure Web app.</li></ol><h4><strong>Data Collection and prototyping in Google Colab:</strong></h4><p>Check out fastai’s <a href="https://docs.fast.ai/vision.data.html#Building-your-own-dataset">build your own data set</a> module which contains a few helper functions to allow you to build your own dateset for image classification. In this project I downloaded Images of crying babies and happy babies from google images and quickly tested them in google colab for initial baseline. Check my <a href="https://github.com/SriramyaK/Baby_Vibes_Pytorch_Azure_Webservice/blob/master/Data_Collection_Google_Colab_prototyping.ipynb">Google colab notebook</a> .</p><h4><strong>Training on Azure Machine Learning:</strong></h4><p>Once our dateset and model parameters are base lined, I chose Microsoft Azure for training and deployment as a web app.</p><p>Prerequisites -</p><p>VS Code enabled with following extensions:</p><ul><li>Python</li><li>Azure Account</li><li>Azure CLI Tools -The Azure CLI provides commands for managing Azure resources.</li><li>Azure Machine Learning — The machine learning extension to the CLI provides commands for working with Azure Machine Learning resources.</li><li>Azure App Service</li><li>Azure Storage</li></ul><p><strong>Note:</strong> If you are new to VS Code, <a href="https://code.visualstudio.com/docs/python/python-tutorial">refer to this</a>.</p><ul><li>An Azure subscription. If you do not have one, try the <a href="https://aka.ms/AMLFree">free or paid version of Azure Machine Learning.</a></li><li>Git local</li></ul><p>We will be using the GitHub repository<strong> </strong><a href="https://github.com/SriramyaK/Baby_Vibes_Pytorch_Azure_Webservice"><strong>Baby Vibes</strong></a><strong> — Image classifier to detect crying babies and play Tom and Jerry for making them laugh</strong>.</p><p>Let’s get started -</p><p>Open ubuntu shell and type:</p><pre>&gt;&gt; mkdir Baby_Vibes<br>&gt;&gt; cd Baby_Vibes<br>&gt;&gt; git clone h<a href="https://github.com/SriramyaK/Baby_Vibes_Pytorch_Azure_Webservice">ttps://github.com/SriramyaK/Baby_Vibes_Pytorch_Azure_Webservice</a><br>&gt;&gt; code .</pre><p>Open new terminal from VS Code and type:</p><pre>&gt;&gt; conda env create -f myenv.yml<br>&gt;&gt; conda myenv/bin/activate</pre><ol><li>Login into Azure from VS Code Machine Learning space:</li><li>Click on “Create Workspace”</li></ol><ul><li>Input a name for Azure ML Workspace name</li><li>Select an Azure Subscription</li><li>Select a resource group or create a new resource group if you don’t have any.</li><li>Select a location</li><li>Select a workspace sku “Basic”</li></ul><p>You can also check out other ways of creating <a href="https://docs.microsoft.com/en-us/azure/machine-learning/how-to-manage-workspace"><strong>workspaces</strong></a>:</p><p>4. Open <a href="https://github.com/SriramyaK/Baby_Vibes_Pytorch_Azure_Webservice/blob/master/Baby_Vibes_train.ipynb">Baby_Vibes_train.ipynb</a>. Update your workspace name, subscription-id and resource group and select “Run all cells”.</p><p>5. After training is done successfully download ‘Babies.pkl’ from “VS Code &gt; Machine learning &gt; workspace &gt; Models &gt; Babies.pkl” and save it as ‘export.pkl’ in the project folder.</p><p>Why as ‘export.pkl’ only ? Check docs of <a href="https://github.com/fastai/fastai/blob/9a32a5f666d28283184e4b5b30edebfcb8ddb5f3/fastai/basic_train.py#L615">fast.ai</a></p><p>6. Now you can detach Machine Learning compute from “VS Code &gt; Machine Learning &gt; Subscription name &gt; workspace name &gt; compute &gt; gpu — compute” to save dollars and move onto deployment phase.</p><h4><strong>Deployment as Azure Web Service using Azure Containers:</strong></h4><ol><li>Open<strong> </strong><a href="https://github.com/SriramyaK/Baby_Vibes_Pytorch_Azure_Webservice/blob/master/deploy.ipynb"><strong>deploy.ipynb</strong></a><strong> </strong>update your workspace name, subscription-id and resource group and select “Run all cells”.</li></ol><p><strong>Checkpoints:</strong></p><ul><li>Ensure “export.pkl” and score_and_track.py are all in the current project folder.</li><li>We are deploying with the below azure container instance configuration. Check <a href="https://github.com/SriramyaK/Baby_Vibes_Pytorch_Azure_Webservice/blob/master/deploy.ipynb">deploy.ipynb</a></li></ul><pre>aciconfig = AciWebservice.deploy_configuration(cpu_cores=2, memory_gb=4,tags={‘data’: ‘Babies’, ‘method’:’transfer learning’, ‘framework’:’pytorch’},description=’Image classification of Baby Vibes’)</pre><p>which means we are using 2 cpus and 4gb memory for running our model inference. (Remember we removed our gpu compute after training the model!!!)</p><p>Make a note of your web service uri, we need it for Web app deployment</p><h4><strong>Consuming the web service from front end deployed as a Python flask Azure Web app:</strong></h4><ol><li>Mkdir flask_deploy</li><li>Cd flask_deploy</li><li>python3 -m venv env</li><li>Source env/bin/activate</li><li>Move the following files into flask_deploy folder and ensure your folder structure looks like this:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/0*9DQGIu7ASOcpuheg" /></figure><p>6. Click on Azure App service pane in VS Code and create a new Web App.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/0*i0uQehpOOoFihAEw" /></figure><p>7. Enter a globally unique name for the new web app, in our case ‘babyvibes1’.</p><p>8. Select runtime for our linux app i.e python 3.6</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5LSpTpSqTW15UZSG" /></figure><p>Once we get a message that new web app “BabyVibes1” is created we can go to<strong> </strong><a href="https://portal.azure.com/#home"><strong>Home</strong></a>&gt;<a href="https://portal.azure.com/#blade/HubsExtension/BrowseAll"><strong>All resources</strong></a>&gt;<a href="https://portal.azure.com/#@sriramyalakkarajugmail.onmicrosoft.com/resource/subscriptions/d74ca76c-0758-4302-8894-12939776ca14/resourceGroups/appsvc_linux_centralus/providers/Microsoft.Web/serverFarms/appsvc_linux_centralus/apps"><strong>appsvc_linux_centralus &gt;Apps </strong></a>&gt; <a href="https://portal.azure.com/#@sriramyalakkarajugmail.onmicrosoft.com/resource/subscriptions/d74ca76c-0758-4302-8894-12939776ca14/resourceGroups/appsvc_linux_centralus/providers/Microsoft.Web/sites/BabyVibes1/configuration"><strong>BabyVibes1 &gt; Configuration &gt; General Settings</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GBipMhgwQ6yQ4IZU" /></figure><p>Copy text from “startup.txt” saved in your current “flask-deploy” folder into the “Startup Command” field shown in the above screen.</p><p><em>Why are we doing this?</em></p><p>The reason is App Service uses <a href="https://gunicorn.org/">Gunicorn WSGI HTTP Server</a> to run an app, which looks for a file named application.py or app.py. Since our main module is in app.py file, we have to customize the startup command as shown below -</p><p>“gunicorn — bind=0.0.0.0 — timeout 600 app:app”</p><p>For more info read <a href="https://docs.microsoft.com/en-us/azure/python/tutorial-deploy-app-service-on-linux-04">azure docs</a></p><p>Our goal is to deploy our app from local git to Azure App Service that we created. To enable that, we first have to configure some deployment settings. Click “Deployment center”, and select “Local Git”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hpwlSLLFuYbENv3R" /></figure><p>Scroll down to see “local git” option</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GGfVZV52HeOwPqLP" /></figure><p>On the next step, select “Kudu” as the build server:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0uL5toOQmzhDcOje" /></figure><p>Click on “Continue”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EHSxMNpoFvRuFz62" /></figure><p>Click “Finish”, wait for notification and you will get <em>Git Clone Uri</em> like this:</p><p><a href="https://babyvibes1.scm.azurewebsites.net:443/babyvibes1.git"><em>https://babyvibes1.scm.azurewebsites.net:443/babyvibes1.git</em></a></p><p>Also, click “Deployment Credentials” to see your app credentials:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TT3jQotrdHUYTR2A" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/0*WgRUg3cLCk8_s3Dd" /></figure><p>Here you can see your app username and password, which you can change or create another user credentials for your deployment purposes.</p><p>Now we are ready for our deployment. Go to your local terminal and add Azure remote to your local Git repository. Replace &lt;deploymentLocalGitUrl-from-create-step&gt; with the URL of the Git remote that you get in the previous step i.e. <a href="https://babyvibes1.scm.azurewebsites.net:443/babyvibes1.git"><em>https://babyvibes1.scm.azurewebsites.net:443/babyvibes1.git</em></a></p><p><strong>Initiate git repository in the current folder:</strong></p><pre>&gt;&gt; git init<br>&gt;&gt; git add .gitignore<br>&gt;&gt; git commit -m “.gitignore added”<br>&gt;&gt; git add .<br>&gt;&gt; git commit -m “Code files added”<br>&gt;&gt; git remote add azure-baby <a href="https://babyvibes1.scm.azurewebsites.net:443/babyvibes1.git">https://babyvibes1.scm.azurewebsites.net:443/babyvibes1.git</a></pre><p>Now commit any changes to local git:</p><pre>&gt;&gt; git commit -a -m “first commit”</pre><p>And push to the “azure-baby” remote to deploy your app with the following command:</p><pre>&gt;&gt; git push azure-baby master</pre><p>When prompted for credentials by Git Credential Manager, make sure that you enter the credentials you created in Configure a deployment user, not the credentials you use to sign in to the Azure portal.</p><p>This command may take a few minutes to run. We can check the status of Web App “babyvibes1” in VS Code and do the final “Deploy to Web App” step -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CQfn-gx1YO1Pj14a" /></figure><p>Select the folder to zip and deploy i.e. in our case flask_deploy</p><p>We can see a pop up like this at the bottom left corner :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/0*SIE2OXLpjyXe9JjR" /></figure><p>Followed by successful deployment like -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/0*43b10Ku_hKnAV08l" /></figure><p>If deployment is successful you can see the below website page -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vTs_ynPRL9K_klA5" /><figcaption><a href="https://babyvibes.azurewebsites.net/">https://babyvibes.azurewebsites.net/</a></figcaption></figure><p>References:</p><ol><li><a href="https://medium.com/@nikovrdoljak/deploy-your-flask-app-on-azure-in-3-easy-steps-b2fe388a589e">https://medium.com/@nikovrdoljak/deploy-your-flask-app-on-azure-in-3-easy-steps-b2fe388a589e</a></li><li><a href="https://docs.microsoft.com/en-us/azure/python/">https://docs.microsoft.com/en-us/azure/python/</a></li><li><a href="https://docs.microsoft.com/en-us/azure/machine-learning/how-to-train-pytorch">https://docs.microsoft.com/en-us/azure/machine-learning/how-to-train-pytorch</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1ba75e43520" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/pytorch-web-service-deployment-using-azure-machine-learning-service-and-azure-web-apps-from-vs-code-a1ba75e43520">PyTorch Web Service deployment using Azure Machine Learning Service and Azure Web Apps from VS Code</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working on Jupyter notebooks in VS Code from virtual conda environment]]></title>
            <link>https://medium.com/analytics-vidhya/working-on-jupyter-notebooks-in-vs-code-from-virtual-conda-environment-f415726e329d?source=rss-4b7f634619e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f415726e329d</guid>
            <category><![CDATA[virtual-environment]]></category>
            <category><![CDATA[jupyter-notebook]]></category>
            <category><![CDATA[visual-studio-code]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Sriramya Kannepalli]]></dc:creator>
            <pubDate>Tue, 29 Oct 2019 00:41:48 GMT</pubDate>
            <atom:updated>2019-11-04T08:18:17.520Z</atom:updated>
            <content:encoded><![CDATA[<p>Now we can do native editing of Jupyter notebooks from Visual Studio Code, visualize interactive graphs and deploy data science projects from one place!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ckWxE4b3zxi1bgZoJFFxOw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@casparrubin?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Caspar Camille Rubin</a> on <a href="https://unsplash.com/s/photos/microsoft?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>When I came across this announcement by Microsoft regarding <a href="https://devblogs.microsoft.com/python/announcing-support-for-native-editing-of-jupyter-notebooks-in-vs-code/">Native Editing of Jupyter Notebooks in VS Code</a> I got excited to use this feature as you can now directly edit .ipynb files and get the interactivity of Jupyter notebooks with all of the power of VS Code.</p><p><strong>Why VS Code ?</strong></p><blockquote>“VS Code has a lot of built-in features like debugging, embedded Git control and GitHub, syntax highlighting, intelligent code completion, snippets, and code refactoring. It is very much customizable, allowing users to change the theme, keyboard shortcuts, preferences, and install plugins that add additional functionality. It also has a terminal embedded into it.” — <a href="https://www.datacamp.com/community/tutorials/top-python-ides-for-2019">Datacamp</a></blockquote><p>But while trying out this new feature, being new to VS Code and Anaconda Virtual environment, took some time for me to fix environmental issues. I would like to share my experience mainly for people like me who are used to doing data science in jupyter notebooks and want to start using VS Code native editing of jupyter notebooks.</p><p>Let’s get started:</p><ol><li>Install Anaconda from <a href="https://docs.anaconda.com/anaconda/install/">anaconda.com</a> (If you are confused between <a href="https://towardsdatascience.com/get-your-computer-ready-for-machine-learning-how-what-and-why-you-should-use-anaconda-miniconda-d213444f36d6">Anaconda vs Miniconda vs conda</a> go through the excellent blog by Daniel Bourke. If you already have Anaconda installed in your system you can start from step 3)</li><li>If you prefer using a command line interface (CLI), you can use conda to verify the installation using Anaconda Prompt on Windows or terminal.</li><li>To open Anaconda Prompt:</li></ol><p>Windows: Click Start, search or select Anaconda Prompt from the menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/0*9sHpEuXXDezwVAJ1" /><figcaption>Source: <a href="https://docs.anaconda.com/anaconda/install/">anaconda.com</a></figcaption></figure><p><strong>Note: </strong>Anaconda prompt comes with Anaconda installation and is different from the regular Windows powershell or command prompt). For detailed instructions check out official <a href="https://www.anaconda.com/distribution/">Anaconda website</a>.</p><p>4. a) If you want to create virtual conda environment/project folder&lt;my-proj&gt; in the base location:</p><pre>(base)C:\Users\&lt;user-name&gt;</pre><p>Type in Anaconda prompt :</p><pre>(base)C:\Users\&lt;user-name&gt; conda create -n my-proj python=3.7 pandas numpy matplotlib scikit-learn jupyter notebook</pre><p>With the above command we are asking <strong>conda</strong> to <strong>create</strong> a virtual environment by <strong>name my-proj</strong> with a specific version <a href="https://www.python.org/"><strong>python 3.7</strong></a><strong> </strong><a href="https://numpy.org/"><strong>numpy</strong></a><strong> </strong><a href="https://matplotlib.org/"><strong>matplotlib</strong></a><strong> </strong><a href="https://scikit-learn.org/stable/"><strong>scikit-learn</strong></a><strong> </strong>and<strong> </strong><a href="https://jupyter.org/"><strong>jupyter notebook</strong></a><strong> </strong>packages. You can edit the package names based on your project requirement.</p><p>Type in the below command to activate the virtual environment.</p><pre>(base) C:\Users\&lt;user-name&gt; conda activate my-proj</pre><pre>(my-proj) C:\Users\&lt;user-name&gt; code</pre><p>Additional libraries can be added with <em>‘conda install &lt;package-name&gt;’</em> or <em>‘pip install &lt;package-name&gt;’</em> commands.</p><p>5. Add your project folder &lt;my-proj&gt; to the VS Code project workspace.</p><p><strong><em>Note:</em></strong><em> Ensure </em><a href="https://code.visualstudio.com/download"><em>Visual Studio Code</em></a><em> is installed and Anaconda, Python and Jupyter extensions are enabled. </em><a href="https://code.visualstudio.com/docs/python/jupyter-support"><em>Jupyter Notebook support for visual studio code</em></a><em> gives complete details for accessing Jupyter Notebook from Visual Studio Code.This blog is mainly focussed on native editing of jupyter notebook from conda environment.</em></p><p>6. Open terminal from VS Code and ensure you are in in the virtual conda environment. If not activate environment once again —</p><pre>C:\Users\&lt;user-name&gt;\Anaconda3\envs\my-proj&gt; conda activate my-proj</pre><p>7. Select interpreter from available interpreters and ensure it is same as the virtual conda environment path that we created above followed by python.exe:</p><pre> C:\Users\&lt;user-name&gt;\&lt;my-proj&gt;\python.exe</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hl_-u4mY7lvkulYmLL-1Xg.png" /></figure><p><strong>8</strong>. In case you are getting errors, open <strong>.vscode</strong> folder created in<strong> </strong>our &lt;my-proj&gt; folder.Verify <strong>settings.json</strong> ‘python.pythonPath’ dictionary value set to</p><pre>“C:\\Users\\&lt;user-name&gt;\\&lt;my-proj&gt;\\python.exe” </pre><p>If not edit the path to the current virtual environment location followed by ‘python.exe’ and replace ‘\’ with ‘\\’.</p><p>9. Create a new jupyter notebook and start coding!!</p><p>or</p><p>Download <a href="https://scikit-learn.org/stable/auto_examples/datasets/plot_iris_dataset.html#sphx-glr-auto-examples-datasets-plot-iris-dataset-py">plot_iris_dataset.ipynb</a> and upload in &lt;my-proj&gt; folder to test the native editing of jupyter notebooks in Visual Studio Code. If everything works fine you will be able to see the below visualization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*1-XTBRsSjrdVX01F4Uj4sA.png" /></figure><h3><strong>Plot viewer</strong></h3><blockquote>The Plot Viewer gives you the ability to work more deeply with your plots. In the viewer you can pan, zoom, and navigate plots in the current session. You can also export plots to PDF, SVG, and PNG formats.</blockquote><blockquote>Within the Notebook Editor window, double-click any plot to open it in the viewer, or select the plot viewer button on the upper left corner of the plot (visible on hover) — <a href="https://code.visualstudio.com/docs/python/jupyter-support">code.visualstudio.com</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*Zmmpb2gFIAX4KAD0pe5ukA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/1*O9TW5SMahz0SObdVjQcR9g.png" /></figure><p><em>Disclaimer : It is taking around 2–3 min for starting jupyter server for the first time in virtual environment!!!</em></p><p>Thank you to the following for helping me understand Anaconda, miniconda and Virtual environments in Python and experimenting with Visual Studio Code.</p><ol><li><a href="https://kiwidamien.github.io/save-the-environment-with-conda-and-how-to-let-others-run-your-programs.html">Save the environment with conda (and how to let others run your programs)</a> — Daniel Martin</li><li><a href="https://towardsdatascience.com/get-your-computer-ready-for-machine-learning-how-what-and-why-you-should-use-anaconda-miniconda-d213444f36d6">Get your computer ready for machine learning: How, what and why you should use Anaconda, Miniconda and Conda</a> — Daniel Bourke</li><li><a href="https://stackoverflow.com/questions/37926940/how-to-specify-new-environment-location-for-conda-create">StackOverflow Thread</a></li><li><a href="https://code.visualstudio.com/docs/python/environments">Visual Studio docs</a></li><li><a href="https://devblogs.microsoft.com/dotnet/">Devblogs.microsoft.com</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f415726e329d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/working-on-jupyter-notebooks-in-vs-code-from-virtual-conda-environment-f415726e329d">Working on Jupyter notebooks in VS Code from virtual conda environment</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vizag Smart City to model itself on San Francisco]]></title>
            <link>https://medium.com/@sriramya.kannepalli/vizag-smart-city-to-model-itself-on-san-francisco-550aa627125b?source=rss-4b7f634619e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/550aa627125b</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[smart-cities]]></category>
            <category><![CDATA[k-means-clustering]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[Sriramya Kannepalli]]></dc:creator>
            <pubDate>Sat, 08 Jun 2019 13:08:03 GMT</pubDate>
            <atom:updated>2019-06-08T17:01:38.383Z</atom:updated>
            <content:encoded><![CDATA[<h3>K-Means Clustering And Segmentation Of Neighborhoods — Unsupervised Machine Learning Algorithm</h3><p><strong>Report based on Machine Learning/K-means Algorithm Neighborhoods segmentation and clustering</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VZnKeOjjctNFcP8zxftB3g.jpeg" /></figure><ol><li><strong>Introduction</strong></li><li><strong>Data collection and preprocessing</strong></li><li><strong>Methodology</strong></li><li><strong>Results</strong></li><li><strong>Discussion and Conclusion</strong></li></ol><p><strong>1.1 Description and Discussion of the Background</strong></p><p>Based on the article published in <a href="https://www.business-standard.com/article/current-affairs/intro-for-front-page-in-the-third-part-of-the-smart-cities-series-business-standard-writes-on-vishakapatnam-and-how-it-is-aiming-to-be-like-san-francisco-with-plenty-of-input-from-the-usvizag-aims-at-a-san-franciso-like-model-116061400791_1.html">Business-Standard.com</a> on 15th June 2016</p><p><strong><em>Can Vizag remodel itself as San Francisco? If yes, what is the current growth rate of both the cities? How are they interrelated with respect to geography and demographics?</em></strong></p><p>As a part of <a href="https://www.coursera.org/specializations/ibm-data-science-professional-certificate?utm_source=gg&amp;utm_medium=sem&amp;campaignid=1876641588&amp;utm_content=10-IBM-Data-Science-USCA&amp;adgroupid=69198829159&amp;device=c&amp;keyword=ibm%20data%20science%20professional%20certificate&amp;matchtype=p&amp;network=g&amp;devicemodel=&amp;adpostion=1t1&amp;creativeid=347392490808&amp;hide_mobile_promo&amp;gclid=CjwKCAjwue3nBRACEiwAkpZhmQFP4ZustCaL15QgmWZLPoQYqCzcP0iEKTsCKPVgaykg0Mwb7yqJhBoCKSUQAvD_BwE">IBM Data Science Professional Certificate Course</a>, I decided to explore the neighborhoods of Vizag, AP, India with the neighborhoods of San Francisco, US to understand the investment opportunities and the city overall growth and development at par with San Francisco using Clustering &amp; Segmentation techniques, ML (Machine Learning). Data Visualizations (using seaborn and matplotlib in Python) are created to explore GDP, Per Capita Income, climatic conditions, tourism and educational institutions of both the cities. All these data points will help us understand the rate of growth in Visakhapatnam and scope of development in different sectors.</p><p><strong>1.2.Problem</strong></p><p>Data that shows the current status of the 2 cities and identifies potential areas and different sectors of investment in Visakhapatnam. This is achieved by comparing the neighborhoods of Vizag and San Francisco and visualizing data for identifying patterns in their geographical and demographic similarities.</p><p><strong>1.3.Interest</strong></p><p>This project will highlight the investor opportunities with increased scope of attracting NRI (Non-Resident Indians) investments which can help Vizag to realize its ambitious economic growth goals while preserving and enhancing livability for the benefit of local citizens.[6].</p><p><strong>2. Data</strong></p><p><strong>2.1 Data Requirements</strong></p><p>Following datasets have been used in the project:</p><ul><li>Postal Codes of Visakhapatnam. Data has been scraped and cleaned from Yo!Vizag — City’s Exclusive Magazine and Portal [1] using Beautiful Soup and pandas libraries and saved in .csv format.</li><li>Foursquare API to get the most common venues of given boroughs of Visakhapatnam and San Francisco respectively.[2]</li><li>Visakhapatnam [3] and San Francisco Wikipedia Pages [4] have been scraped and cleaned for creating Word clouds.</li><li>Zip codes of San Francisco. Data has been downloaded in .csv format from <a href="https://datasf.org/">https://datasf.org/</a>and cleaned using pandas.</li><li><a href="https://en.wikipedia.org/wiki/Economy_of_Visakhapatnam">Economy of Visakhapatnam</a></li><li><a href="https://fred.stlouisfed.org/series/NGMP41860">Per Capita Income of San Francisco</a></li><li><a href="https://indiapopulation2019.com/population-of-visakhapatnam-2019.html">Population data of Visakhapatnam</a></li><li><a href="https://www.opendatanetwork.com/entity/1600000US0667000/San_Francisco_CA/demographics.population.count?year=2017">GDP data of San Francisco</a></li></ul><p><strong>2.2.Data Analysis:</strong></p><p>2 Cities will be analyzed in this project: Visakhapatnam and San Francisco.</p><p>I will be using the below datasets for analyzing Visakhapatnam.</p><p><strong>Data 1: </strong>Neighborhood has a total of 684 areas. Most notable areas of the city include urban areas like Dwaraka Nagar, Gajuwaka, Gopalapatnam, Jagadamba Centre, Maddilapalem, Madhurawada, Seethammadhara and semi-rural suburbs such as Simhachalam, Pendurthi, and Parwada.</p><p>Data has been scraped and cleaned from <a href="https://www.yovizag.com/visakhapatnam-vizag-pin-code/">Yo!Vizag — City’s Exclusive Magazine and Portal</a>– using Beautiful Soup and pandas libraries and saved in .csv format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*KsDqyA3Aa7vVfo4PFD1QPw.jpeg" /><figcaption>Code Link — <a href="https://gist.github.com/SriramyaK/662166d0fa646b4bacd918bb2b03be2d">https://gist.github.com/SriramyaK/662166d0fa646b4bacd918bb2b03be2d</a></figcaption></figure><p>We don’t have Geocodes data readily available— latitudinal/longitudinal coordinates required for plotting a folium map. I used <a href="https://geopy.readthedocs.io/en/stable/#module-geopy.geocoders">GeoPy</a> — geopy is a Python 2 and 3 client for several popular geocoding web services.</p><p>Geopy makes it easy for Python developers to locate the coordinates of addresses, cities, countries, and landmarks across the globe using third-party geocoders and other data sources to get the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*h0EbpEqClvh9HQ94uxlOJw.jpeg" /><figcaption>Code Link — <a href="https://gist.github.com/SriramyaK/ca9993d229e744ca23c1e1b492d49b1d">https://gist.github.com/SriramyaK/ca9993d229e744ca23c1e1b492d49b1d</a></figcaption></figure><p>San Francisco Data:</p><p>Data 2: SFO has total of 36 neighborhoods [4]. But due to limited data available we could analyze only 26 neighborhoods. Data has been downloaded in .csv format from <a href="https://datasf.org/">https://datasf.org/</a> and cleaned using pandas. Below are the 1st five neighborhoods:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/0*-4XLKzicqA36s76U.jpg" /></figure><p>Data 3: For the below analysis we will get data from Wikipedia:</p><ol><li>Visakhapatnam and San Francisco City Demographics.</li><li>Visakhapatnam Tourism and Attractions.</li><li>San Francisco Tourism and conventions.</li></ol><p>Data 4: Visakhapatnam and SFO geographical coordinates will be utilized as input for Foursquare API, that will be leveraged to extract information for each neighborhood respectively.</p><p>Data 5: Population, GDP, Per capita Income, Tourism, Educational Institutions and Weather data of Vizag and San Francisco.</p><p><strong>3. Methodology:</strong></p><p><strong>Analytic Approach:</strong></p><p>In this project, first part is clustering of Visakhapatnam using k means algorithm. Visakhapatnam has 648 pin codes/areas/postal codes, geocodes of only 326 locations have been included in the data analysis. We will explore the areas around central Visakhapatnam and compare it with the neighborhoods of San Francisco to understand the geographical similarities.</p><p>2nd part comprises of clustering of San Francisco. For San Francisco out of 36 neighborhoods venues of 27 neighborhoods have been explored in this project using Foursquare API.</p><p>3rd part includes data visualizations and comparison of available data of both the cities for insights to take investment decisions in Vizag. Word clouds created from the wiki pages of Vizag and SFO further add value to our discussion.</p><p><strong>Exploratory Data Analysis:</strong></p><p>Data 1: Visakhapatnam Geographical Coordinates Data.</p><p>We use geopy and folium libraries to create a map of Visakhapatnam city with neighborhoods imposed on it. 326 areas are plotted using their latitude and longitude values to obtain a high-level visualization of the neighborhoods.</p><p><strong>Fig: Visakhapatnam Neighborhood Visualization</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CKqtnYF78v58vIML.jpg" /></figure><p>Now let’s explore venues around Andhra University, one of the most prestigious and oldest university in Andhra Pradesh located in central Vizag. We selected this location as Andhra University is located on the uplands of Visakhapatnam, the university campus is scenic, with the <a href="https://en.wikipedia.org/wiki/Bay_of_Bengal">Bay of Bengal</a> on one side of it and on the other, the green <a href="https://en.wikipedia.org/wiki/Kailasagiri">Kailasagiri</a> hill range. This location is apt for our analysis as San Francisco was also chosen because of the geographical similarity.</p><p>Longitude and Latitude values of Andhra University, Sivajipalem Road, Sector 4, Pedda Waltair, Visakhapatnam, Andhra Pradesh, 530001, India are 17.7376312,83.3300513027767.</p><p>Now, let’s get the top 10 venues that are in Andhra university within a radius of 500 meters.</p><p>Foursquare API gave only 2 unique venues</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/0*LagcCBpa_kR8a2Kg.jpg" /></figure><p>.</p><p>Now we repeat the same steps for all the neighborhoods around Andhra university to get the most common venue categories. Snap shot of first 5 neighborhoods and their venue categories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/0*NTjGpGYEpuKxiZVM.jpg" /></figure><p>There are 39 unique categories of venues in the neighborhoods of Andhra University.</p><p>Now we repeat the same for all the neighborhoods in Visakhapatnam city. Let’s look at first 2 neighborhoods with the top 5 most common venues to get an idea. Refer here for <a href="https://github.com/SriramyaK/Machine-Learning/blob/master/IBM%20Final%20Applied%20Capstone%20Coursera%20Project.ipynb">Code</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*r8tS1tuIbIX1ab9EiEj6Cw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/0*fRp8Uu4GRRVa8vU2.jpg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/0*oFOM_vKa-YAgl9RO.jpg" /></figure><p>Now we run the k-means algorithm to cluster the neighborhoods into 4 clusters. The no. of clusters is decided by using Elbow method for optimal k. In our scenario the optimal no. of k Is 4.</p><p>Below horizontal Bar Chart shows the count of most common venues in each cluster. Based on the analysis, we can clearly see the presence of clothing Store/Shopping complex in every cluster which shows the amount of urbanization and development throughout every neighborhood of Visakhapatnam. Breakfast spots, food restaurants are other common venues in cluster 1 and 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/0*ZSmfYtyJjydgXIPV.png" /><figcaption>Horizontal Bar Chart using Matplotlib — <a href="https://gist.github.com/SriramyaK/dd6a590eff690d8c12b2930bb89d2ad0">https://gist.github.com/SriramyaK/dd6a590eff690d8c12b2930bb89d2ad0</a></figcaption></figure><p><strong>Fig. Clustering and segmentation of Visakhapatnam using k means algorithm –</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/0*D6iDTs8hmZY1fNA4.jpg" /></figure><p>Cluster 1 has the maximum no. of venues and development. There is a significant population increase in recent past. Below is the Bar chart depicting the population of both the cities in last 5 years.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/0*vXDEzX6ARx-lU4sN.png" /></figure><p>Let’s explore the data further.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/0*Wnj-QsolqTOMsBWI.jpg" /></figure><p>We can see the presence of Historic sites, harbor, fish markets and beach which gives us some idea on the geographical similarity between Vizag and SFO. Let’s Visualize this in word clouds with Tourism data of Vizag and San Francisco scraped from the travel website TripAdvisor. In case you are wondering what is Word cloud, you can refer to the <a href="https://www.datacamp.com/community/tutorials/wordcloud-python">Datacamp Tutorial</a>:</p><p><strong>Fig. Word cloud of San Francisco list of tourist Attractions:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/0*OJ3pe3xgBPhEr95K.png" /></figure><p><strong>Word Cloud of list of Visakhapatnam tourist attractions:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/0*_1CGHPvZy-uE4KWA.png" /></figure><p>Above word clouds signify the similarity in the two cities Museum, Park and Beach/Bay being the most common among them. Some other already existing natural tourist spots adding to the beauty of the city are waterfalls, caves, hills, wildlife and temples in Visakhapatnam.</p><p>But when we closely observe the word cloud of tourism of San Francisco, there are several untapped opportunities like Fisherman’s wharf, Pier 39, Twin Peaks, Big Bus Hop on Hop off tour etc. that can be implemented in Visakhapatnam due to similar geographical features and weather conditions.</p><p>Box plot of weather conditions of Visakhapatnam and San Francisco in a Year:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/0*wwH3lysyJ4Ct_bKy.png" /></figure><p>The hot and humid conditions of Visakhapatnam as compared to San Francisco clearly show huge scope for establishment of amusement water parks and recreational activities. <strong>Cruises, Sailing, Hiking trails and Water tours</strong> can create major spike in tourism and boost <strong>GDP </strong>of Visakhapatnam.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/0*AVeIEApXMdaMsI3Y.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/0*RyBPgR9aL4jhYnqg.png" /></figure><p>Though there is a significant difference in the GDP and Per Capita Income of Vizag and San Francisco, Visakhapatnam has managed to top the charts of urban population amongst all the 13 districts in Andhra Pradesh, India. According to data uploaded onto the CM’s Dashboard, the 2011 Census of India states that Visakhapatnam stood first in the state with 47.45% of urban populace.</p><p>The difference in GDP and Per Capita Income of the two cities signify the importance of technology and investments required for the city to remodel itself as San Francisco in the next 10 years.[1] Achieving the vision will require a “Smart City” approach to regional development and infrastructure planning and delivery. For further information please refer the below link — <a href="https://www.smartvizag.in/index.php/projects/">https://www.smartvizag.in/index.php/projects/</a></p><p>To Summarize, I created word cloud using seaborn libraries and web scraping Wikipedia page using beautiful soup.</p><p><strong>Fig. Word Cloud of Visakhapatnam Wikipedia Page</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/0*vpoDExWrxcimdDPr.png" /></figure><p>In this word cloud we can clearly see that Visakhapatnam has a coast, port, railway, naval base, university, stadium and is a metropolitan city with historic sites and international airport.</p><p>With this information we move on to the analysis of San Francisco and identify potential ideas for development.</p><p>Data 2: SFO Geographical Coordinates Data is downloaded in .csv format from <a href="https://datasf.org/">https://datasf.org/</a>and cleaned using pandas. We explored 27 neighborhoods of San Francisco in our analysis.</p><p>Below are the first 5 neighborhoods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/0*TZ0uWHTU0M7DpQ_e.jpg" /></figure><p><strong>Fig. SFO Neighborhood Visualization using Folium and geopy libraries.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/0*GIB5ddYcpoiXuMfe.jpg" /></figure><p>As we explore each neighborhood further for identifying similarities with Visakhapatnam, let’s start with venues around the neighborhood surrounded with Beach in SFO.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/0*zPz3XoJF3-6Uorlt.jpg" /></figure><p>Now, let’s get the top 100 venues that are in North Beach, SF, California within a radius of 500 meters.</p><p>Foursquare API gave 100 unique venues. Let’s explore the data –</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/0*bfEos8fG5733yCSM.jpg" /></figure><p>We will do the same analysis for all the neighborhoods of North Beach, SF and explore the venues returned by Foursquare API to understand the most common venue categories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/0*FKYOqqSxAhdUmVLG.jpg" /></figure><p>We repeat the same for all the neighborhoods of SF. There are 261 unique categories in SF. Now we run the k-means algorithm to cluster the neighborhoods into 4 clusters. The no. of clusters is decided by using Elbow method for optimal k. In our scenario the optimal no. of k Is 4.</p><p><strong>Fig.Clustering of neighborhoods of San Francisco using k means algorithm</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/0*v6qlkmtG16ZGqT86.jpg" /></figure><p>Below is the horizontal bar chart for most common venues in each cluster</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/0*y_j_Jd1_y_zfd8K2.png" /></figure><p>As we can see from the above analysis, neighborhoods in cluster 0 are highly developed with wide range of restaurants, dance studios, juice bars, coffee shops, event spaces etc. The venues in Vizag and San Francisco are largely different and unique in nature due to different levels of development/urbanization rates in both the cities.</p><p>But this analysis gives a high-level idea on the new categories of venues that can be invested in Visakhapatnam and tailored based on the needs of local population. Some categories like juice bars, dance studios, event places which currently are not present in the most common venue categories in Vizag leaves some scope for new investments.</p><p>Finally, we will look at the word cloud of San Francisco created from Wikipedia to explore further.</p><p><strong>Fig. Word cloud of San Francisco created from Wikipedia</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/0*fhGg2qOrZjelaVO_.png" /></figure><p>We can see the words military, Bay area, hill, Pacific Ocean, Ferry, waterfront, historic building etc. which show some similarity in the geographic and demographic data of Visakhapatnam and San Francisco.</p><p>Word cloud of Educational institutions and universities in San Francisco:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/0*bYC_QV5jyYWwgOZ0.png" /></figure><p>Despite its limited geographical space, San Francisco, California is home to a multitude of colleges and universities. <a href="https://en.m.wikipedia.org/wiki/San_Francisco_Conservatory_of_Music">San Francisco Conservatory of Music</a>, <a href="https://en.m.wikipedia.org/wiki/San_Francisco_School_of_Digital_Filmmaking">San Francisco School of Digital Filmmaking</a>, <a href="https://en.m.wikipedia.org/wiki/San_Francisco_Art_Institute">San Francisco Art Institute</a> and <a href="https://en.m.wikipedia.org/wiki/Art_Institute_of_California_-_San_Francisco">Art Institute of California — San Francisco</a>, a private campus which focuses on <a href="https://en.m.wikipedia.org/wiki/Video_game">video game</a> and design-based education (interior, fashion etc.) are some of the unique colleges and universities which can be further explored and established in Visakhapatnam.</p><p><strong>4. Results:</strong></p><p>Though we could show limited results in demographic and geographical factors from the given data set in the clustering and segmentation of the two cities and word clouds of the Wikipedia pages of Visakhapatnam and San Francisco, but we could bring out some business ideas on the new venue categories like dance studios, juice bars, coffee shops, event spaces and wide range of restaurants like sushi restaurant, Mediterranean restaurant etc. which can be tailored based on the priorities and interests of local population in Visakhapatnam. Tourism when developed in right way with advanced technologies and FDI can play major role boosting city’s economy to remodel itself as San Francisco in near future. Educational Institutions form one more area of potential development.</p><p><strong>5. Discussion and Conclusion:</strong></p><ol><li>Tourism has huge potential of development as a part of Smart city initiatives in Vizag. <strong>Cruises, Sailing, Hiking trails and Water tours</strong> can create major spike in tourism and boost <strong>GDP </strong>of Visakhapatnam.</li><li>Educational Institutions data can be explored further.</li><li>Business investor looking for real estate investment can further explore areas/neighborhoods in cluster 1 of Visakhapatnam as these are the areas having the highest development with restaurants, breakfast spots, shopping complex etc. as compared to the places in other clusters.</li><li>For people interested in coming up with startup ideas in the food sector of smart city — dance studios, juice bars, coffee shops, event spaces and wide range of restaurants like sushi restaurant, Mediterranean restaurant etc. are some of the new business ideas that can be experimented with based on further data analysis.</li><li>Individual investors looking for investment in residential plots can further explore areas in cluster 0 and cluster 2 of Visakhapatnam.</li></ol><p>For Code: <a href="https://github.com/SriramyaK/Machine-Learning/blob/master/IBM%20Final%20Applied%20Capstone%20Coursera%20Project.ipynb">Github</a></p><p><strong>References:</strong></p><ul><li>[1] <a href="https://www.yovizag.com/visakhapatnam-vizag-pin-code/">Yo!Vizag — City’s Exclusive Magazine and Portal</a></li><li>[2] <a href="https://developer.foursquare.com/">Foursquare API</a></li><li>[3] <a href="https://en.wikipedia.org/wiki/Visakhapatnam">Visakhapatnam Wikipedia page</a></li><li>[4] <a href="https://en.wikipedia.org/wiki/San_Francisco">San Francisco Wikipedia Page</a></li><li>[5] <a href="https://india.smartcitiescouncil.com/article/vizag-smart-city-model-itself-san-francisco">https://india.smartcitiescouncil.com/article/vizag-smart-city-model-itself-san-francisco</a></li><li>[6] <a href="https://www.smartvizag.in/">https://www.smartvizag.in/</a></li><li>[7] <a href="http://apedb.gov.in/about-visakhapatnam-district.html">http://apedb.gov.in/about-visakhapatnam-district.html</a></li><li>[8] <a href="https://www.opendatanetwork.com">https://www.opendatanetwork.com</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=550aa627125b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>