<?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 Alberto Nieto on Medium]]></title>
        <description><![CDATA[Stories by Alberto Nieto on Medium]]></description>
        <link>https://medium.com/@alberto.e.nieto?source=rss-769b0a9b3002------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bG7CQZ9clNWDwaWIjn1uAQ.jpeg</url>
            <title>Stories by Alberto Nieto on Medium</title>
            <link>https://medium.com/@alberto.e.nieto?source=rss-769b0a9b3002------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 10:26:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alberto.e.nieto/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[Using Forest-based Classification & Regression to Model and Estimate House Values]]></title>
            <link>https://medium.com/geoai/using-forest-based-classification-regression-to-model-and-estimate-house-values-5a0e26682c42?source=rss-769b0a9b3002------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a0e26682c42</guid>
            <category><![CDATA[predictions]]></category>
            <category><![CDATA[spatial-analysis]]></category>
            <category><![CDATA[regression]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[gis]]></category>
            <dc:creator><![CDATA[Alberto Nieto]]></dc:creator>
            <pubDate>Sat, 27 Oct 2018 19:41:12 GMT</pubDate>
            <atom:updated>2019-07-02T18:29:05.471Z</atom:updated>
            <content:encoded><![CDATA[<h3>Using Forest-based Classification &amp; Regression in GIS to Model and Estimate House Values</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vSL6wttXhZ1pzwS418Pdjw.jpeg" /></figure><p>The <a href="https://pro.arcgis.com/en/pro-app/">ArcGIS Pro 2.2</a> release has an exciting new machine learning tool that can help make predictions. It’s called <a href="https://pro.arcgis.com/en/pro-app/tool-reference/spatial-statistics/forestbasedclassificationregression.htm"><strong><em>Forest-based Classification and Regression</em></strong></a>, and it lets analysts effectively design, test, and deploy predictive models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/0*0Q2NW8EQxy6uvjGd.png" /></figure><p>Forest-based Classification and Regression applies Leo Breiman’s random forest algorithm, a popular supervised machine learning method used in classification and prediction. The tool allows analysts to easily incorporate tabular attributes, distance-based features, and explanatory rasters to build predictive models and expands predictive modeling to become accessible and possible for all GIS users.</p><p>To show off what’s possible with Forest-based Classification and Regression, we tackled a popular problem in the data science community: predicting home sale values. Let’s take a look at a basic exercise to build a model that incorporates spatial factors to help improve the prediction of home sale prices in California.</p><p><strong>Predicting House Prices in California</strong></p><p>We’ll start by using the popular <a href="https://www.kaggle.com/harrywang/housing#housing.csv">California Housing Dataset</a> from Kaggle, containing tracts in California with a series of aggregate attributes for the homes in each tract.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*20HpNVtfiJNV4rc645UbDw.png" /></figure><p>It’s tough to do anything meaningful just by looking at the above table, so let’s make a map of each tract, symbolized by average home sale value at each location:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*9KPepocP9Ux2vmKvMpGQNQ.png" /><figcaption>Home Sale Values by Tracts in California</figcaption></figure><p>In this map, each point signifies the centroid of a tract in California. The color range represents the average home sale value of all homes in the tract. Blue represents low sales values, yellow represents medium sales value, and red represents the highest values.</p><p>Just from viewing this map, do you notice any general pattern?</p><p>You may notice that higher-priced homes are situated near the largest metropolitan areas. You may also notice that higher-priced homes are situated near the coastline. A quick exploratory chart in ArcGIS Pro helps us explore these patterns:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*igz7SL-Rus7g7JiNi8zWDA.png" /><figcaption>Distribution of Median House Value by Ocean Proximity</figcaption></figure><p>Let’s view the rest of the data in the provided table. Each record contains a few basic data points for all the homes in the tract:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YwsoevZw5c83Vu8ga-fB1w.png" /></figure><p>The median house value for each tract is our variable to predict, and these attributes are likely important in helping estimate each value.</p><p>We’ll start by following the example provided by Aurélien Geron in his book <a href="http://shop.oreilly.com/product/0636920052289.do"><em>Hands-On Machine Learning with Scikit-Learn and TensorFlow</em></a>, where <a href="https://github.com/ageron/handson-ml/blob/master/02_end_to_end_machine_learning_project.ipynb">a random forest model</a> was built using primarily non-spatial factors (i.e. the attributes in the table shown above). We’ll compare this model to a second model where we start to bring in other GIS layers to assess how each tract’s proximity to locations of interest may help the model improve when estimating median house values.</p><p><strong>Non-spatial Model</strong></p><p>Our first model will follow the lead of the Hands-On Machine Learning with Scikit-Learn and TensorFlow example, using the following characteristics for each tract record:</p><ul><li>Median Income</li><li>Housing Median Age</li><li>Total Rooms</li><li>Total Bedrooms</li><li>Population</li><li>Households</li><li>Ocean Proximity</li></ul><p>Let’s open the Forest-based Classification and Regression tool and get started:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*c6cQzFDq5FBcoloRY3j9nQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*NeU4O7aXVdOZJgiflcr6hw.png" /></figure><p>The first parameter designates the type of run you want to execute. For this basic exploration we want to assess model diagnostics (i.e. predictive performance) and monitor changes as we introduce and test combinations of factors. For this reason, let’s leave this parameter at “Train only”.</p><p>We will specify the input training features, passing our GIS layer of tracts in California, our variable to predict, using the “median_house_value” attribute, and then specify which attributes will be used for the model in the “Explanatory Training Variables” parameter section by selecting each corresponding column in your input data. When complete, your geoprocessing tool inputs should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*Hic0cjay5F3B7g2DDkpShQ.png" /></figure><p>Once you execute the model, the tool builds a forest that establishes a relationship between explanatory variables and the designated variable to predict. For more information on how this tool works, please be sure to read <a href="https://pro.arcgis.com/en/pro-app/tool-reference/spatial-statistics/how-forest-works.htm">this</a>.</p><p>Once the tool finishes its run, you should receive a detailed diagnostic of your model performance:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/419/1*pIPkz0JvtXRgOcnbBWC9Ng.png" /></figure><p>The assessment of top variable importance provides a general sense of which factors helped the model (median income and ocean proximity mattered a great deal). For now, let’s make note of our R-Squared value: 0.706 (this may differ slightly when you execute).</p><p>Please note: To create a model that does not change in every run, a seed can be set in the Random Number Generator environment setting. There will still be randomness in the model, but that randomness will be consistent between runs.</p><p><strong>Spatial Model</strong></p><p>Now that we tried the original approach of estimating home sale values that primarily uses non-spatial factors, let’s explore how the model changes as we introduce distance-based training features. The goal is to compute the distances between each tract and a series of potentially important features that relate to home prices. For our simple exploratory exercise, we’ve brought point feature classes of golf courses, schools, hospitals, recreational areas, and cemeteries. We will also bring in a polyline feature class of the California coastline.</p><p>To calculate all those distances, you could conceive of a script to iterate on each record and run some proximity functions to determine the distances between each geometry record… or you could simply open the Forest-based Classification and Regression tool and drag and drop each feature class into the <strong>Explanatory Training Distance Features</strong> parameter:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3YZ3YoFJ-p-Tck9Inr5IOg.gif" /></figure><p>Once you have each distance feature loaded, we can run the tool. Our parameters at this point looked like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*hTcz6ZjhiXHriEyM1TSyzg.png" /></figure><p>Feel free to experiment with your own potential explanatory training factors! A brief example: Can you find a dataset of public transit station locations, bring it into your ArcGIS Pro Project, and load the locations to the Explanatory Training Distance Features parameter? How does this factor change your model?</p><p>Once the tool runs, we can evaluate our diagnostics and compare with the original model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*EVm45Ru3I0ZOMx_L_TmCCg.png" /></figure><p>The new regression diagnostics land at an R-Squared of 0.763. Interestingly, a basic model with mostly distance-based factors performed a bit better than the original model that mostly considered the non-spatial characteristics of the homes (number of bathrooms, etc.). If anything — this is data-driven proof of the location, location, location adage!</p><p>The run of the tool will also provide the model outputs across your input data:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*sW0G1ozn2-zUXJO3kTwKFg.png" /></figure><p>This isn’t inherently useful on its own since we are basically predicting on records with known values, but it’s useful to see how distance-based features change the model performance. Better yet, its extremely useful to be able to incorporate existing additional GIS data into the model’s considerations for proximity in such a fast and intuitive way.</p><p>Note: An additional important aspect of Forest-based Classification and Regression is the way in which the effects of multicollinearity in candidate explanatory factors does not prevent you creating effective models. To understand how random forest mitigates for issues with multicollinearity, I encourage you to explore further in <a href="https://pro.arcgis.com/en/pro-app/tool-reference/spatial-statistics/how-forest-works.htm">the tool documentation</a> and in additional <a href="https://www.stat.berkeley.edu/~breiman/randomforest2001.pdf">random forest documentation</a>.</p><p><strong>Conclusion and Resources</strong></p><p>Performing analysis to predict any event or value is sure to be an exploratory, iterative, messy, and time-consuming exercise. To support these workflows, we need tools that help us quickly incorporate spatial data, support testing, let us quickly evaluate results, and allow us to repeat until we reach a satisfactory result.</p><p>Forest-based Classification and Regression extends the utility of the powerful random forests machine learning algorithm by incorporating the ability to consider not just attribute data in your models, but also distance-based training features and explanatory rasters to leverage location in your analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pir3LNrOGAe1DmqNWiAHsg.png" /></figure><p><strong>Resources</strong></p><p><a href="https://pro.arcgis.com/en/pro-app/tool-reference/spatial-statistics/forestbasedclassificationregression.htm">Forest-based Classification and Regression Tool Documentation</a></p><p><a href="https://pro.arcgis.com/en/pro-app/tool-reference/spatial-statistics/how-forest-works.htm">How Forest-based Classification and Regression Works</a></p><p><a href="https://spatialstats.github.io/">Spatial Statistics Resources</a></p><p><a href="https://youtu.be/KCkGif6wSMo">Use of Forest-based Classification and Regression in Asthma Hospitalization Case Prediction</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a0e26682c42" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geoai/using-forest-based-classification-regression-to-model-and-estimate-house-values-5a0e26682c42">Using Forest-based Classification &amp; Regression to Model and Estimate House Values</a> was originally published in <a href="https://medium.com/geoai">GeoAI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Three Ways to Get Jupyter Notebooks and the ArcGIS API for Python]]></title>
            <link>https://medium.com/@alberto.e.nieto/three-ways-to-get-jupyter-notebooks-and-the-arcgis-api-for-python-a601a77e46be?source=rss-769b0a9b3002------2</link>
            <guid isPermaLink="false">https://medium.com/p/a601a77e46be</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[quick-tips]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[jupyter-notebook]]></category>
            <dc:creator><![CDATA[Alberto Nieto]]></dc:creator>
            <pubDate>Thu, 06 Jul 2017 01:00:38 GMT</pubDate>
            <atom:updated>2017-07-06T01:33:22.625Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ua24640jBE0YB-dvtt2pRw.jpeg" /></figure><p>Jupyter Notebooks have become a crucial tool in the Python and Data Science communities over the past years. Their seamless integration with some of the most <a href="http://pandas.pydata.org/">important Python libraries</a> and their interesting structure that encourages efficient prototyping and visualization have made Jupyter Notebooks one of my favorite tools as a Python user.</p><p>With the new <a href="https://developers.arcgis.com/python/">ArcGIS API for Python</a>, GIS users can now also use this tool and integrate all of its benefits with a distributed GIS. <a href="https://medium.com/arcgis-api-for-python-developers-corner/three-reasons-to-use-jupyter-notebooks-and-the-python-api-for-arcgis-4493ce0cb1ae">The possibilities are quite exciting!</a></p><blockquote>… but how do I get a Jupyter Notebook running on my machine?</blockquote><p>If you’re ready to start exploring, there’s a few paths you can take to install and open your first notebook. The following are three easy, recommended ways to get Jupyter Notebooks running on your system:</p><h4>1. Try the API in a live sandbox</h4><p>The simplest and quickest way to start writing your first Jupyter Notebook is to use the live ArcGIS API for Python sandbox at <a href="https://notebooks.esri.com/">notebooks.esri.com</a>. This approach doesn’t install anything on your system and operates nicely as a test environment to let you get started with your first notebook.</p><p>Once you navigate there, you will see a simple page with a few tabs, icons, and items. Opening your first notebook is as easy as selecting the <strong>“New▼” </strong>button and selecting <strong>“Python 3” </strong>from the drop-down menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QNqys8arP_YkF6arPPLqHQ.gif" /><figcaption>Voila! You’re ready to start writing.</figcaption></figure><p>This option is very useful to start writing notebooks from any system that has an internet connection. With this approach, nothing installs locally and you can get started in just seconds.</p><p>However, this live sandbox environment does not save your user session and will reset if you reload your browser page, which raises an important caveat to keep in mind when trying this approach:</p><p><strong>If you wish to save your notebook beyond a single session, you will need to download the notebook to your system.</strong></p><p>Thankfully, saving a notebook is easy as pie. Select the <em>File</em> tab, then <em>Download as</em>, then <em>Notebook (.ipynb)</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*k6aQ4qk2Eg2hx33x6qyJSQ.gif" /></figure><blockquote>Hot tip: You may have noticed the other options when selecting a download format, including as a <em>Python (.py)</em> file and <em>HTML (.html).</em></blockquote><blockquote>I find the option to download as a <em>Python (.py)</em> file useful when enough progress is made in the testing and prototyping stage of writing code and you are ready to take the scripted process or functionality into production. Downloading as an <em>HTML (.html) </em>file is also very useful when embedding a static snapshot of your notebook into another webpage.</blockquote><p>Once you test a few notebooks using the live sandbox and get a feeling for how the entire tool operates, I recommend that you take the next steps to install the tool locally with one of the following options:</p><h4>2. Install using the ArcGIS Pro Python Package Manager</h4><p>If you have <a href="https://pro.arcgis.com/en/pro-app/">ArcGIS Pro</a> 1.4 or later installed, you can use its Python Package Manager to install and manage the ArcGIS Python API, making the procedure extremely simple and GUI-driven.</p><p>From ArcGIS Pro, select the <em>Project</em> tab at the top-left of the application, select <em>Python</em> from the menu options in the left, then select <em>Add Packages</em> and enter “arcgis” to find the ArcGIS API for Python:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6w3MC__asdSY0x991UdMhQ.gif" /><figcaption>Installing Using the Python Package Manager in ArcGIS Pro</figcaption></figure><p>The package manager installs everything it needs and also allows you to manage updates or uninstalls (who would do such a thing?) of the API through the interface.</p><blockquote>Another hot tip: Take a second to explore other Python packages available through this Package Manager and test out a few, such as the <a href="https://r-arcgis.github.io/">r-arcgisbinding</a> package.</blockquote><h4>3. Install Jupyter Notebooks and the API Using Anaconda</h4><p>The ArcGIS API for Python can also be installed using <a href="https://conda.io/docs/intro.html">conda</a>, a package manager that comes as part of the <a href="https://www.continuum.io/downloads">Anaconda for Python</a> distribution (just make sure you get the Python 3x installer).</p><p>Anaconda is a fairly heavy distribution but the benefits are significant: with one installation you receive access to more than <a href="https://docs.continuum.io/anaconda/packages/pkg-docs">100 of the most-used Python packages for data science</a> and a wealth of other capabilities to use with your Jupyter Notebooks. For instance, the <a href="http://docs.python-requests.org/en/latest/index.html"><em>requests module</em></a> that comes with Anaconda is an excellent way to work with Python and HTTP requests.</p><p>Once you have Anaconda for Python 3x installed, you gain access to Jupyter Notebooks. Finalizing the installation for the ArcGIS API for Python is then as easy as entering the following in a terminal or command prompt:</p><blockquote>conda install -c esri arcgis</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*LQyPQzXj0h4_YxOIv1jFNQ.gif" /></figure><p>Once the package is fully installed the fun begins!</p><h4>Opening your First Notebook Using a Local Installation</h4><p>Once you have Jupyter Notebooks and the ArcGIS API for Python locally installed in your system, creating your first notebook is as simple as opening up a new terminal or command prompt and entering the following command:</p><blockquote>jupyter notebook</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*bRArxfyJfSAP6XPTdCcP2w.gif" /></figure><p>Any jupyter notebooks you create after this point are saved at the location where the terminal or command prompt opened your jupyter notebook, so remember to change directories (<em>cd</em>) to the location where you want to save your notebooks!</p><blockquote>Final hot tip: If you’re using Windows and don’t often use the command prompt, a quick way to open up a command prompt window in a specified path is to select the address bar at the top of the Windows Explorer window and enter “cmd”.</blockquote><p>Now that you have installed Jupyter Notebooks and the ArcGIS API for Python and opened up your first notebook, it’s time to test by creating your first reference to a GIS and your first map.</p><p>Create a new cell and enter the following Python code:</p><blockquote>from arcgis.gis import GIS</blockquote><blockquote>my_gis = GIS()</blockquote><blockquote>my_gis.map()</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*29zIvyo2jScKIRiYj1fK_Q.gif" /></figure><p>A dynamic, controllable map loads beneath the cell. Save this notebook as “Hello Map” and frame it on a wall or stick it to your fridge. We are now ready to go explore!</p><p>With installation and your first notebook out of the way, you are ready to test, prototype, map, analyze and create with all the potential that the tool provides.</p><p><a href="https://medium.com/arcgis-api-for-python-developers-corner/a-few-tips-to-get-you-started-with-jupyter-notebook-8f9b172d98cb">A few tips are recommended as you start getting acquainted</a> with this tool, and an <a href="https://developers.arcgis.com/python/guide/overview-of-the-arcgis-api-for-python/">excellent, detailed guide is available</a> as part of the ArcGIS API for Python documentation. You may also take a look at the <a href="https://developers.arcgis.com/python/sample-notebooks/">sample notebooks</a> to get started with robust GIS integration.</p><p>Once you’ve created a few notebooks to handle basic workflows, come back and we’ll discuss a few approaches to start integrating functionality between the API, Pandas, and other interesting approaches that benefit from the functionality in Jupyter Notebooks and the ArcGIS API for Python. Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a601a77e46be" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Five Tips To Get You Started With Jupyter Notebook]]></title>
            <link>https://medium.com/@alberto.e.nieto/a-few-tips-to-get-you-started-with-jupyter-notebook-8f9b172d98cb?source=rss-769b0a9b3002------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f9b172d98cb</guid>
            <category><![CDATA[gis]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[quick-tips]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[beginner]]></category>
            <dc:creator><![CDATA[Alberto Nieto]]></dc:creator>
            <pubDate>Fri, 30 Jun 2017 19:30:26 GMT</pubDate>
            <atom:updated>2017-07-02T03:26:28.227Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UNuTe8H-7jJFl2qs_7DkQA.jpeg" /><figcaption>Photo by <a href="http://unsplash.com/photos/VkwRmha1_tI?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Tim Arterbury</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p><a href="https://medium.com/@alberto.e.nieto/three-reasons-to-use-jupyter-notebooks-and-the-python-api-for-arcgis-4493ce0cb1ae">We’ve discussed a few reasons to use Jupyter Notebooks as a GIS user</a>. From visualization of your data to the recent integration with the ArcGIS platform, Jupyter Notebooks are quickly becoming a crucial component of GIS and data science workflows.</p><p>In spite of these benefits, coming up to speed and getting comfortable with Jupyter Notebooks can be a daunting task for a new user. There is nuance to the way Jupyter Notebooks operate that can take some time to comprehend.</p><p>If I’ve piqued your curiosity and you’ve taken the steps to install Jupyter Notebooks to help in your GIS workflows, the following tips may be helpful as your start exploring this tool.</p><h4>1. Don’t Put Your Entire Code in a Single Cell</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z11frwBHY_gIN7H3yIb2TA.jpeg" /></figure><p>The most immediate difference between Jupyter Notebook and traditional Python Integrated Development Environments (IDEs) is that code is segmented into sections named cells.</p><p>My first recommendation is that you avoid the mistake I did on my first few notebooks: I entered my entire script into a single cell and treated Jupyter Notebook like a regular Python IDE.</p><p>Here’s an example where a script calculates a longitude and latitude for every record in a table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qdYJPjKB-NYSazDKiSNUxQ.png" /><figcaption>The entire script is placed into a single cell. Yuck!</figcaption></figure><p>Doing this erodes many of the benefits that this tool provides!</p><p>Consider instead where your process contains logical breaks and create a cell for each component of your process. Not only is this more <a href="https://zen-of-python.info/">visually compelling and easier to understand</a> but it allows you to test each step of your process independently without re-executing the entire script.</p><p>Here’s the same script from above, separated into individual code cells for each step of the process to calculate longitude and latitude:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z07Mnu8LvU80BtH5lSFfYQ.png" /><figcaption>Ah, much better.</figcaption></figure><p>Splitting the script into cells allows you to test each component and ensure every step is acting in the way you expect. Additionally, you can document each component with a markdown cell, which takes me to the next tip…</p><h4>2. There are different types of cells</h4><p>In the example above, the comment lines above each item are a different type of cell; these are named “Markdown” cells.</p><p>Markdown cells are useful to help document your Notebook or to write detailed “readme” descriptions within your notebook.</p><p>All cells start as “Code” cells by default, but take a moment to explore the different types of cells available to you:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*PT4jQX_Ms6PQ70B4mArINA.gif" /><figcaption>You can designate cell types through the Jupyter Notebook interface</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HYgC00y-5jcEJ8m5TDGI2w.gif" /><figcaption>Markdown cells are an excellent way to document your scripted process.</figcaption></figure><h4>3. Executing Cells (shift + enter)</h4><p>If you’ve taken steps to segment your code into separate cells, you may come across another mistake I did on my first notebooks: forgetting to execute all cells to run the entire process.</p><p>The following example highlights a common mistake I did in my first notebook:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kp_R0kuPrEhqIcSjDRD1JQ.gif" /></figure><p>Coming from using traditional Python IDEs where the code executes from start to end, I simply executed the cell that I finished writing, but forgot to execute the first cell which imports the ‘os’ module, triggering the error.</p><p>My advice:</p><p><strong><em>Get used to pressing Shift + Enter when you are done writing a cell to execute it.</em></strong></p><p>The Shift+Enter keyboard shortcut executes your cell and creates a new cell below to continue to your work. The smooth flow that it provides has resulted in this shortcut becoming my most frequently-used keyboard shortcut in the entire tool.</p><p>Here’s another stab at the simple workflow above using this method:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nHd2Qr8ZzjjSO7vV4bgOPw.gif" /></figure><p>Another way to manually execute all cells in your notebook is the “Run All” command in the “Cell” tab of the toolbar:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sn-Y2wFJZGCYgsBCQs0wHg.gif" /></figure><h4>4. Explore Interactive Mapping Options!</h4><p>Did you notice the map in the example above? That’s the <a href="https://developers.arcgis.com/python/">ArcGIS API for Python</a> in action!</p><p>I briefly mentioned some of its benefits in the previous post, but let’s take a few steps to start exploring it.</p><p>The “Hello World” equivalent in the ArcGIS API for Python is the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*29zIvyo2jScKIRiYj1fK_Q.gif" /></figure><p><a href="https://developers.arcgis.com/python/guide/">The documentation does an excellent job of getting you started</a>, but you can also explore some of its capabilities from within your notebook. This takes me to my final tip…</p><h4><strong>5. To explore new modules, use questions and TAB auto-complete</strong></h4><p>Most Python IDEs allow you to view code documentation and provide auto-complete functionality in some form.</p><p>Jupyter Notebook provides access to code documentation in an intuitive way: you can literally ask questions from your code to get answers about the functions and methods you can use. Use the “?” character following any Python object and code documentation is loaded into the active notebook.</p><p>Let me provide an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fEUA_0cNT5pPP6fidlusmw.gif" /></figure><p>Please do keep in mind: the feature depends on the amount of documentation available in the code you are referencing, so not every module will provide you a detailed explanation of how it works. Even so, it doesn’t hurt to ask!</p><blockquote><strong><em>Using TAB auto-completion</em></strong></blockquote><p>Another interesting approach you can take to explore new modules or functions is to use Jupyter Notebook’s TAB auto-completion.</p><p>The way you use this is by entering the Python object, then a period, then TAB. All the available functions and methods are then shown in an interactive menu to let you explore and select the relevant one.</p><p>Here’s an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9lI3058B8P4mJroLhtlIBA.gif" /></figure><p>These are a few basic tips to help you hit the ground running as you start using Jupyter Notebook in your workflows.</p><p>If you’re attending this year’s <a href="http://www.esri.com/about/events/uc">Esri User Conference</a>, my colleagues, Atma Mani and Rohit Singh will be presenting an <a href="https://userconference2017.schedule.esri.com/schedule/700965594">introduction session on the ArcGIS API for Python and its integration with Jupyter Notebook.</a></p><p>Meanwhile, in this blog we’ll be gradually covering more advanced approaches to using this tool and exploring how it can integrate into a distributed GIS.</p><p>Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f9b172d98cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Three Reasons to use Jupyter Notebooks as a GIS User]]></title>
            <link>https://medium.com/@alberto.e.nieto/three-reasons-to-use-jupyter-notebooks-and-the-python-api-for-arcgis-4493ce0cb1ae?source=rss-769b0a9b3002------2</link>
            <guid isPermaLink="false">https://medium.com/p/4493ce0cb1ae</guid>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[jupyter-notebook]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Alberto Nieto]]></dc:creator>
            <pubDate>Mon, 12 Jun 2017 22:25:50 GMT</pubDate>
            <atom:updated>2017-07-02T03:27:14.355Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j3p7gsUlkbDl7Z4k6kJyiw.jpeg" /></figure><p>Jupyter Notebook is a powerful tool that allows Python users to create and share documents containing live code, visualizations, explanatory text, and equations.</p><p>The term “notebook” is very applicable, since the tool allows you to write snippets of self-contained executable code (named “cells”), note each procedure, and even visualize data you are working with at any step of the way.</p><blockquote>Why should I use a Jupyter Notebook?</blockquote><p>Jupyter Notebooks have gained tremendous popularity in the Python data science community over the past years for a variety of reasons. As a GIS user, I have personally found Jupyter Notebooks to be extremely useful for the following three reasons:</p><h4><strong>1. Prototyping of Python Workflows</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5qlJpN7BVtRMnWF0uNRofA.jpeg" /></figure><p>Jupyter Notebooks are extremely useful when you do not have a defined final process and are still in the prototyping phase of your scripted workflow. This is mainly thanks to the feature where code is written into independent cells, which can each execute independently from the rest of the code. This allows a Python user to quickly test a specific step in a sequential workflow without re-executing code from the beginning of the script.</p><p>Many Integrated Development Environments (IDEs) allow you to do this in several ways, but I’ve found Jupyter Notebook’s concept of a “code cell” to be the most intuitive approach for prototyping logic and sequential code.</p><h4><strong>2. Visualizing Pandas Dataframes</strong></h4><p><a href="http://pandas.pydata.org/">Pandas (Python Data Analysis Library)</a> provides high-performing and easy-to-use data structures that allow you to work with large amounts of data extremely fast. The core data object is a Dataframe, which is essentially an in-memory table that allows powerful indexing operations.</p><p>Jupyter Notebook allows you to visualize these tables at any point in your notebook. This is extremely useful because you can view the state of your data (and the effect of all the actions your code is performing on your data) as each step of your logic executes. This capability reinforces the use of Jupyter Notebook in a prototyping workflow when you are attempting to confirm that your workflow is doing what it needs to do at each step of the way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HHYlAx2Zb3AR2RAD0feuIw.png" /><figcaption>Showing a Dataframe in a code cell can go a long way to understanding how your code operates.</figcaption></figure><blockquote>So why are Pandas Dataframes such a big deal?</blockquote><p>As a GIS user, the first foray into working with Python and GIS data management typically uses some mix of arcpy’s “CalculateField”, “SearchCursors”, and “UpdateCursors”. Most of the examples teach you to use these operations and they are all completely functional, but they suffer from the same process-intensive issue: they all need to iterate upon every record of your data to perform a data management operation.</p><p>In other words: Imagine that you are a director of a movie in production, and you find out that to change the lighting in a scene, you need to watch the movie from the very beginning… for every change. This would take forever!</p><p>Operating on a Pandas Dataframe solves for this with powerful indexing that allows effective querying and array-wide operations. You essentially find the specific scene of the movie that you need to fix, and skip to that scene. Once my GIS data analysis workflows started integrating Pandas Dataframes into heavy data operations, I saw exponential improvements in performance.</p><p>Visualizing these Dataframes and seeing the effects of my code in each dataset became a crucial component of working efficiently.</p><h4><strong>3. Integration with ArcGIS</strong></h4><p>The newest (and most exciting) reason is the integration of Jupyter Notebooks with the ArcGIS Platform. My two main production tools had long been the ArcGIS Platform and Jupyter Notebook. When Esri announced that the <a href="https://developers.arcgis.com/python/">ArcGIS API for Python</a> would provide support for geographic visualizations, organization administration, and even access to the most powerful analytical capabilities of the platform within Jupyter Notebooks, I literally could not stop smiling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o2t_FJj4PAQvP0Za1icVig.png" /><figcaption>Seeing this for the first time made me pump my fist in the air.</figcaption></figure><p>The new <a href="https://developers.arcgis.com/python/">ArcGIS API for Python</a> renders each Jupyter Notebook an extension of your distributed GIS. Among several other capabilities, you can:</p><ul><li><a href="https://developers.arcgis.com/python/sample-notebooks/clone-portal-users-groups-and-content/">Set up a notebook</a> that will connect to your Portal and provide you detailed reports on each user’s content, groups, and statistics, and perform backups of all the content in a Portal based on user group. Free yourself from administration tasks to explore and analyze.</li><li><a href="https://developers.arcgis.com/python/sample-notebooks/chennai-floods-analysis/">Create integrated maps and data operations</a> that are connected to code cells in your notebook. All the prototyping benefits mentioned above are now part of your spatial analysis workflow.</li><li><a href="https://developers.arcgis.com/python/sample-notebooks/analyze-new-york-city-taxi-data/">Leverage GeoAnalytics tools and other geoprocessing operations</a> on data workflows that you are already working with in your Jupyter Notebook. The most powerful new tools are already incorporated into the API.</li></ul><p>Even with all these benefits, coming up to speed with Jupyter Notebooks as a GIS user can be a daunting task. Stay tuned for a few tips on how to navigate and operate Jupyter Notebooks…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4493ce0cb1ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>