<?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 Hendrix Peralta on Medium]]></title>
        <description><![CDATA[Stories by Hendrix Peralta on Medium]]></description>
        <link>https://medium.com/@hendrixperalta?source=rss-6752f2937e94------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*HRwgqQxy-5N49ZpbFssp3A.jpeg</url>
            <title>Stories by Hendrix Peralta on Medium</title>
            <link>https://medium.com/@hendrixperalta?source=rss-6752f2937e94------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 12:58:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hendrixperalta/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[Monitoring Development from Space: The Power of Remote Sensing]]></title>
            <link>https://medium.com/@hendrixperalta/monitoring-development-from-space-the-power-of-remote-sensing-f6abc6ca0c99?source=rss-6752f2937e94------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6abc6ca0c99</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[ridge-regression]]></category>
            <category><![CDATA[remote-sensing]]></category>
            <category><![CDATA[sustainable-development]]></category>
            <dc:creator><![CDATA[Hendrix Peralta]]></dc:creator>
            <pubDate>Mon, 21 Apr 2025 02:59:16 GMT</pubDate>
            <atom:updated>2025-04-21T02:59:16.787Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m5H-bRwx01wCKnGeUJljMA.png" /><figcaption>Figure 1. Nighttime Lights (NTL) in Bolivian municipalities</figcaption></figure><p>Adopting the Sustainable Development Goals (SDGs) in 2015 marked a global commitment to broader human rights and social dimensions in development frameworks. However, measuring progress towards these goals, particularly in developing countries like Bolivia, faces significant hurdles due to methodological gaps, inconsistent data collection, and limited public data availability.</p><p>Furthermore, this data is traditionally collected through national surveys and administrative documentation. However, this has proven to be a costly data collection method, with national surveys costing millions of dollars to be designed, performed, and analyzed.</p><p>Recognizing these challenges and building upon the understanding that development is a multidimensional concept encompassing political, social, and economic aspects. I analysed the predictive power of several remote sensing images on 15 of the Sustainable Goals for the 339 municipalities of Bolivia. Exploring the potential of integrating machine learning techniques with remote sensing data to monitor sustainable development and provide evidence-based policy recommendations.</p><h4>Methodology</h4><p>Ridge regression was the primary machine learning model used to predict SDG indexes at the municipal level, while Lasso and Elastic Net regressions were used for comparison.</p><p>The regression model uses the remote sensing data for the prediction of the SDG indexes as described in the following formula:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*9AtafmRGe0jy1j6LcV-gqA.png" /></figure><p>Where “<em>SDGI</em>” are the SDG indexes, “<em>i</em>” is the municipality identifier, “<em>d</em>” is the department identifier, “<em>β</em>” is the coefficient, “<em>Remote Sensing</em>” refers to each of the remote sensing data variables, “<em>α</em>” represents the regional fixed effects, while “<em>ε</em>” is the error term. This equation was used for each of the SDG dimensions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U8x5BLLHPywPx0NjIDGRTw.png" /><figcaption>Figure 2. Conceptual framework</figcaption></figure><h4>Data</h4><p>The labels were extracted from the Bolivian Municipal Atlas of Sustainable Development Goals (Andersen et al., 2020). This dataset includes SDG completion indices for 15 of the 17 SDGs for all 339 municipalities in Bolivia.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sXKPF6IlNu6UWkrzkIoCEw.png" /></figure><p>Meanwhile, the features were collected using publicly available remote sensing data from Google Earth Engine (GEE), the GEE Community, and Geoquery.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qz7FEPv-S0I8ApiwKg9wjw.png" /></figure><h4>Development Monitoring is Possible for Some Development Dimensions</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PVnwpCeNMvHV-SbqDRWrXw.png" /></figure><p>The Ridge regression models demonstrated that remote sensing data can effectively predict certain SDGs. SDGs 1 (No Poverty), 7 (Affordable and Clean Energy), 9 (Industry, Innovation and Infrastructure), 11 (Sustainable Cities and Communities), and 13 (Climate Action) achieved mean R² values above 60%. In particular, the model for SDG 1 had a good performance with a five-fold averaged R² of 70%. Coupled with that, the model predicting the overall Sustainable Development Index (SDI) also showed high predictive power (67%).</p><p>However, the same can not be said about all development dimensions. For instance, SDGs 10, 2, 6, and 8 showed mean R² in the 40% to 50% range. Moreover, at the lower end of the spectrum, SDGs 16, 5, 3, 17, and 4 all showed mean R² below 40%. Furthermore, SDG 15 Life on land has a negative R², indicating that the machine learning model could not grasp the source of variance in the index, and substituting the prediction with the dataset&#39;s mean would result in a better prediction.</p><p>To dive deeper into the analysis, the five-fold results were plotted to understand the variance of the results of each model. Here, SDGs 1, 9 and the SDI models show the lowest variance among the best-performing models. Specifically, SDG 9 had the lowest variance among this group. However, although the mean of the SDG 1 model is over 70%, the median is slightly below this threshold.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p-4TDdSAllUhSb1bTebVAQ.png" /><figcaption>Figure 3. Predictive power distribution of each model in 5 folds</figcaption></figure><h4>Socioeconomic-related features were relevant to SDG prediction.</h4><p>Taking into consideration that the regression coefficients in a Ridge regression model are biased by design to increase predictive power. I plotted the relationship between the best-performing models and the remote sensing variables alongside their coefficients.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KfofyhmFvCwHCh-uEUSoUA.png" /><figcaption>Figure 4. Relationship between remote sensing data and Sustainable development Goals</figcaption></figure><p>Based on this, it is evident that socioeconomic variables such as NTL, EGDP, Population, and population density are relevant in most models. Population density, in particular, showed large coefficients in all six models.</p><p>Conversely, the Land cover variables had the lowest impact on the best-performing models. Among all the remote sensing variables collected, only vegetation was relevant for one development dimension, SDG 11: Sustainable Cities and Communities. This could be attributed to the indexes comprising several indicators into them. An analysis of each of the indicators individually is needed to see their relation with these Land Cover variables.</p><h4>Monitoring of Development Policies Using Remote Sensing Data</h4><p>The results show that remote sensing data can be a powerful tool to monitor development at a low cost, and by integrating remote sensing datasets into their analysis, the Bolivian policy makers can assess the effectiveness of policies aimed at reducing poverty at the municipal level. Remote-sensing data can be extremely useful in monitoring areas with accessibility challenges.</p><p>Additionally, the models for SDGs 1: No Poverty, 7: Affordable and Clean Energy, and 9: Industry, Innovation, and Infrastructure demonstrated high predictive power. However, this was only verified for one year, 2012, the only year available in the Bolivian Development Atlas dataset. Consequently, the Bolivian government should promote the continuation of this dataset. By ensuring the availability of an up-to-date and comprehensive development dataset. The government could improve the accuracy of the prediction models in the future and perform long-term predictions.</p><h4>References</h4><p><em>Andersen, L., Canelas, S., and Penaranda, L. (2020). Atlas Municipales de los ODS Bolivia 2020.</em></p><p><em>Chen, J., Gao, M., Cheng, S., Hou, W., Song, M., Liu, X., and Liu, Y.(2022).Global 1 km × 1 km gridded revised real gross domestic product and electricity consumption during 1992–2019 based on calibrated night-time light data. Scientific Data, 9:202.</em></p><p><em>Chen, Z., Yu, B., Yang, C., Zhou, Y., Yao, S., Qian, X., Wang, C., Wu, B., and Wu, J.(2021). An extended time series (2000–2018) of global NPP-VIIRS-like nighttime light data from a cross-sensor calibration. Earth System Science Data, 13:889–906.</em></p><p><em>Friedl, M. and Sulla-Menashe, D. (2019). MCD12Q1 MODIS/Terra+Aqua Land Cover Type Yearly L3 Global 500m SIN Grid V006.</em></p><p><em>Goodman, S., Ben Yishay, A., Lv, Z., and Runfola, D. (2019). GeoQuery: Integrating HPC systems and public web-based geospatial data tools. Computers &amp; Geosciences, 122:103–112.</em></p><p><em>Pesaresi, M. and Politis, P. (2023). GHS-BUILT-V R2023A-GHS built-up volume grids derived from joint assessment of Sentinel 2, Landsat, and global DEM data, multitemporal (1975–2030). European Commission, Joint Research Centre (JRC) [Dataset].</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6abc6ca0c99" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Add Value to Your Geospatial Plots]]></title>
            <link>https://medium.com/@hendrixperalta/add-value-to-your-geospatial-figures-c0d382b33f9f?source=rss-6752f2937e94------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0d382b33f9f</guid>
            <category><![CDATA[matplotlib]]></category>
            <category><![CDATA[geopandas]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Hendrix Peralta]]></dc:creator>
            <pubDate>Tue, 27 Aug 2024 05:56:54 GMT</pubDate>
            <atom:updated>2024-08-27T15:24:35.332Z</atom:updated>
            <content:encoded><![CDATA[<p>Plot coordinate points and add multiple legends</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0MPez52n7ygY9mFuRMWA9g.png" /><figcaption>Figure 1. Distribution of NTL and SEZ locations. Source: Author</figcaption></figure><p>Imagine that we have a dataset with a country&#39;s Night Time Lights (NTL) and its Special Economic Zones (SEZ) location. Subsequently, we found a correlation between the SEZ and NTL and wanted to show it to our colleagues.</p><p>However, when creating this new Figure using geospatial data, we might think that the basic plotting function will produce something that looks like Figure 1. But then we realized that our graph looked more like Figure 2 and became disappointed.</p><pre>fig, ax = plt.subplots()<br><br># Plot GeoDataFrame<br>geo_municipalities.plot(<br>    column=&quot;ntl_2020&quot;,        # Column to plot<br>    scheme=&quot;natural_breaks&quot;,  # Data Classification scheme<br>    cmap=&quot;OrRd&quot;,              # Color map<br>    edgecolor=&quot;k&quot;,            <br>    legend=True,              # Show legend<br>    ax=ax                     <br>)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*XxzawjcY22APZ-ouHBHncQ.png" /><figcaption>Figure 2. Figure with the basic parameters. Source: Author</figcaption></figure><p>This article will explain the steps needed to improve your plots by transforming plots that look like Figure 2 into ones similar to Figure 1.</p><h3><strong>1. Plot parameters and cluster classification</strong></h3><p>Our first step will be to modify some of its parameters to make our Figure more appealing. In this case, we will eliminate the axis, reduce the plot line thickness, and add a title.</p><p>Additionally, we are going to change the classification scheme. I prefer the classification algorithm produced by GEODA over the built-in classification options. The reason is that the patterns shown in GEODA offer more information. We can install the pygoeda library to change the classification scheme and create our new natural brakes.</p><pre># Create new natural brakes using pygoeda<br>breaks = pygeoda.natural_breaks(6, geo_municipalities[&quot;ntl_2020&quot;])<br><br>fig, ax = plt.subplots()<br><br>geo_municipalities.plot(<br>        column = &quot;ntl_2020&quot;,<br>        scheme=&quot;UserDefined&quot;,  # Change the classification scheme<br>        classification_kwds={&quot;bins&quot;:breaks}, # Brakes creaded with pygoeda<br>        cmap=&quot;OrRd&quot;, <br>        edgecolor=&quot;k&quot;,<br>        linewidth=0.2, # Thinner line width <br>        legend=True,<br>        ax=ax)<br><br>ax.set_axis_off();<br>ax.set_title(&quot;NTL Distribution&quot;,<br>            pad=15,<br>            fontsize=10,<br>            fontdict={&quot;weight&quot;:&quot;bold&quot;});</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*6zmOlzT0fXYkRyV_T0DhRA.png" /><figcaption>Figure 3. Changed basic parameters and classification scheme. Source: Author</figcaption></figure><h3><strong>2. Add coordinate points to a map</strong></h3><p>The most important thing when combining two geospatial data into one graph is to confirm that their coordinates are the same. You can use the method .crs on both geopandas objects to do this.</p><pre>geo_municpalities.crs<br><br>output:<br><br>&lt;Geographic 2D CRS: GEOGCS[&quot;GCS_unknown&quot;,DATUM[&quot;WGS_1984&quot;,SPHEROID[&quot;WG ...&gt;<br>Name: GCS_unknown<br>Axis Info [ellipsoidal]:<br>- lon[east]: Longitude (Degree)<br>- lat[north]: Latitude (Degree)<br>Area of Use:<br>- undefined<br>Datum: World Geodetic System 1984<br>- Ellipsoid: WGS 84<br>- Prime Meridian: Greenwich</pre><p>After confirming that the coordinates are equal, you can plot the SEZ location data and assign it to the same axis as the NTL distribution graph.</p><pre>breaks = pygeoda.natural_breaks(6, geo_municipalities[&quot;ntl_2020&quot;])<br><br>fig, ax = plt.subplots()<br><br>geo_municipalities.plot(<br>        column = &quot;ntl_2020&quot;,<br>        scheme=&quot;UserDefined&quot;,  <br>        classification_kwds={&quot;bins&quot;:breaks},<br>        cmap=&quot;OrRd&quot;, <br>        edgecolor=&quot;k&quot;,<br>        linewidth=0.2,<br>        legend=True,<br>        ax=ax)<br><br># Coordinate points plot<br>sez_location_2020.plot(<br>            ax=ax,   # Assigning the second plot to the same axis<br>            color=&quot;yellow&quot;,<br>            marker=&quot;o&quot;,<br>            markersize=10)<br><br>ax.set_axis_off();<br>ax.set_title(&quot;NTL Distribution and SEZ location&quot;,<br>            pad=15,<br>            fontsize=10,<br>            fontdict={&quot;weight&quot;:&quot;bold&quot;});</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*fXvTbAgnIZ3T0glrs3tycA.png" /><figcaption>Figure 4. NTL distribution and SEZ opened between 2015 and 2020. Source: Author</figcaption></figure><h3><strong>3. Subplots and Overall Title</strong></h3><p>Now, we have a graph that shows us the NTL distribution for 2020 and the location of the SEZ opened in the 5 years from 2015 to 2020. However, seeing the changes in NTL over time would be more insightful. This way, we can see if there are any patterns in the data over time. To achieve this, we will create four subplots for 2005, 2010, 2015, and 2020.</p><p>To avoid repeating the same code for each plot, we will create a function that receives only the unique parameters of each plot. This way, we can make modifications in one place when we want to change other aspects of the plots that all of them share, such as title, legend, and maker sizes.</p><p>Additionally, to add an overall title on top of all your subplots, you can use the method .suptitle() and modify its parameters.</p><pre>breaks = pygeoda.natural_breaks(6, geo_municipalities[&quot;ntl_2020&quot;])<br><br># Recieves the unique parameters of each plot<br>def distributionPlusCoordinatePoints(geo_map, column, breaks, <br>                                      coordinates, title=None, <br>                                      period=None, ax=None):<br>    <br>    # geo_map = geoDataFrame for the cluster classification<br>    geo_map.plot(<br>        column = column,<br>        scheme=&quot;UserDefined&quot;,  <br>        classification_kwds={&quot;bins&quot;:breaks},<br>        cmap=&quot;OrRd&quot;, <br>        edgecolor=&quot;k&quot;,<br>        linewidth=0.2,<br>        legend=True,<br>        <br>        # Scales the legend<br>        legend_kwds={&quot;fontsize&quot;:30, <br>                    &quot;markerscale&quot;:3,<br>                    &quot;title&quot;:&quot;Night Time Lights&quot;,<br>                    &quot;title_fontsize&quot;:30}, #Scales the items inside the legend <br>        ax=ax,<br>    )<br><br>    # Coordinates = Coordinate point to plot on top of the map <br>    coordinates.plot(<br>        ax=ax,<br>        color=&quot;black&quot;,<br>        marker=&quot;o&quot;,<br>        markersize=190, # Scales the marker size<br>        label=year,<br>    )<br><br>    ax.set_axis_off();<br>    ax.set_title(title,<br>             pad=15,<br>             fontsize=40,<br>             fontdict={&quot;weight&quot;:&quot;bold&quot;});<br># ================= Function ends =================<br><br><br># Creates a 2x2 subplot array<br>fig, axes = plt.subplots(2, 2, figsize=(50, 40))<br>ax1, ax2, ax3, ax4 = axes.flat<br><br><br>distributionPlusCoordinatePoints(geo_municipalities, <br>                                   &quot;ntl_2005&quot;, <br>                                   breaks, <br>                                   coordinates=sez_location_2005,<br>                                   title=&quot;2005&quot;,<br>                                   ax=ax1<br>                                   )<br><br>distributionPlusCoordinatePoints(geo_municipalities, <br>                                   &quot;ntl_2010&quot;, <br>                                   breaks, <br>                                   coordinates=sez_location_2010,<br>                                   title=&quot;2010&quot;,<br>                                   ax=ax2<br>                                   )<br><br># Repeate for each of the subplots <br>distributionPlusCoordinatePoints(...)<br><br>distributionPlusCoordinatePoints(...)<br><br># creates an overall title <br>fig.suptitle(&quot;The Location of SEZ is Correlated With High NTL Observations&quot;,<br>                fontsize=70,<br>                fontdict={&quot;weight&quot;:&quot;bold&quot;});<br><br>plt.tight_layout()<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_5Nz-mqPOKkia8uAIaWRGQ.png" /><figcaption>Figure 5. Distribution of NTL and SEZ opened from 2005 to 2020. Source: Author</figcaption></figure><h3><strong>4. Add a second legend to your Plots</strong></h3><p>For the next step, we will change how we present the SEZ location information to finish our plot. Instead of only showing the SEZ that opened in a 5-year period, we will also show the previous SEZ and add a legend that clarifies in which period they were opened.</p><p>To do this, we will pass a list of coordinates to the distributionPlusCoordinatePoints() function and iterate on it to plot the sez location in each period.</p><p>Finally, we will add a second legend to the subplots to clarify the period in which the SEZ was opened. When we add the second legend, the first one will disappear, and we need to bring it back using the .add_artist() method.</p><pre>breaks = pygeoda.natural_breaks(6, geo_municipalities[&quot;ntl_2020&quot;])<br><br>def distributionPlusCoordinatePoints(geo_map, column, breaks, <br>                                      coordinates, title=None, <br>                                      period=None, ax=None):<br><br>    # Color to be used for the coordinated plot <br>    color_list = [&quot;#87CEEB&quot;, &quot;#1E90FF&quot;, &quot;#4169E1&quot;, &quot;#4682B4&quot;, &quot;#483D8B&quot;]<br>    # Labels for each of the coordinate points <br>    years = [2000, 2005, 2010, 2015, 2020]<br><br>    geo_map.plot(<br>        column = column,<br>        scheme=&quot;UserDefined&quot;,  <br>        classification_kwds={&quot;bins&quot;:breaks},<br>        cmap=&quot;OrRd&quot;, <br>        edgecolor=&quot;k&quot;,<br>        linewidth=0.2,<br>        legend=True,<br>        legend_kwds={&quot;fontsize&quot;:30, <br>                    &quot;markerscale&quot;:3,<br>                    &quot;title&quot;:&quot;Night Time Lights&quot;,<br>                    &quot;title_fontsize&quot;:30}, #Scales the items inside the legend <br>        ax=ax,<br>    )<br>    <br>    # Save the natural brakes legend in a variable<br>    leg1 = ax.get_legend()<br>    <br>    # Iterate on the sez location, color and label lists<br>    for coordinate, color, year in zip(coordinates,color_list, years):<br>        coordinate.plot(<br>            ax=ax,<br>            color=color, # assigns a different color to each period<br>            marker=&quot;o&quot;,<br>            markersize=170,<br>            label=year, # assigns a different label to each period<br><br>            # Change parameters the second legend<br>            legend_kwds={&quot;fontsize&quot;:30, <br>                    &quot;markerscale&quot;:2.5,<br>                    &quot;loc&quot;:&quot;lower right&quot;}<br>        )<br><br>    # Creates the second legend (the first legend is deleted) <br>    ax.legend(title=&#39;New SEZs (5 years period)&#39;, <br>                fontsize=30, <br>                title_fontsize=&#39;30&#39;,<br>                markerscale=2.5, <br>                loc=&#39;lower right&#39;, # location of the legend<br>                ncol=5)<br>    <br>    ax.add_artist(leg1) # adds the first legend to the plot<br>    <br>    ax.set_axis_off();<br>    ax.set_title(title,<br>             pad=15,<br>             fontsize=40,<br>             fontdict={&quot;weight&quot;:&quot;bold&quot;});<br># ================= Function ends =================<br><br><br>fig, axes = plt.subplots(2, 2, figsize=(50, 40))<br>ax1, ax2, ax3, ax4 = axes.flat <br><br>distributionPlusCoordinatePoints(geo_municipalities, <br>                                   &quot;ntl_2005&quot;, <br>                                   breaks, <br>                                   # Passes a list of coodinates points <br>                                   coordinates=[sez_location_2000, <br>                                                sez_location_2005],<br>                                   title=&quot;2005&quot;,<br>                                   ax=ax1<br>                                   )<br><br>distributionPlusCoordinatePoints(geo_municipalities, <br>                                   &quot;ntl_2010&quot;, <br>                                   breaks, <br>                                   coordinates=[sez_location_2000, <br>                                                sez_location_2005, <br>                                                sez_location_2010],<br>                                   title=&quot;2010&quot;,<br>                                   ax=ax2<br>                                   )<br><br># Repeat for each subplot <br>distributionPlusCoordinatePoints(...)<br><br>distributionPlusCoordinatePoints(...)<br><br>fig.suptitle(&quot;The Location of SEZ is Correlated With High NTL Observations&quot;,<br>                fontsize=70,<br>                fontdict={&quot;weight&quot;:&quot;bold&quot;});<br><br>plt.subplots_adjust(wspace=0.1)<br>plt.tight_layout()<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VQtwwondEVnb8LAMsQhcPQ.png" /><figcaption>Figure 6. Final plot. Source: Author</figcaption></figure><p>Geopandas Documentation: <a href="https://geopandas.org/en/stable/gallery/choropleths.html">Choropleth classification schemes from PySAL for use with GeoPandas — GeoPandas 1.0.1+0.g747d66e.dirty documentation</a></p><p>Geographic Data Science with Python (online book): <a href="https://geographicdata.science/book/notebooks/05_choropleth.html">Choropleth Mapping — Geographic Data Science with Python</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0d382b33f9f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Improve Your Data Analysis Workflow]]></title>
            <link>https://medium.com/@hendrixperalta/improve-your-data-analysis-workflow-070c2b871bae?source=rss-6752f2937e94------2</link>
            <guid isPermaLink="false">https://medium.com/p/070c2b871bae</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Hendrix Peralta]]></dc:creator>
            <pubDate>Sat, 24 Aug 2024 11:41:08 GMT</pubDate>
            <atom:updated>2024-08-26T02:50:16.359Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Replace notebooks with Python interactive files -&gt; profit.</strong></p><p>In the Data Science world, Notebooks are a staple tool for data cleaning, exploration, and analysis, especially for those who conduct their research using Python. However, I want to introduce Python Interactive Files today, which can substitute or complement notebooks depending on your workflow.</p><p>I started using <strong>Python Interactive</strong> files in my workflow to perform the analysis sections of my research. At first, I had my reserves and kept a notebook version of my files, but after getting used to the new workflow, I never looked back.</p><p>You can think of Python Interactive as a mix between a Python script and a notebook. Like a notebook, our code will be divided into cells. You can run all the cells together or each individually in any order. However, our results are shown in a console tab instead of below the code cell. This functionality is similar to RStudio or Stata. If you are used to the workflow of these tools, Python Interactives can be a good addition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a2tJqbec3C_CP0LlqVPNMw.png" /><figcaption>Figure 1: Python interactive window sections. Source: Author</figcaption></figure><p>After my experience with this new tool, I have encountered these main pros and cons.</p><p><strong><em>Pros:</em></strong></p><ul><li><em>Access to variables/data frames is faster through the console.</em></li></ul><p>A console tab showing your results will automatically appear when using a Python Interactive file. An essential feature of this tab is an input bar on the bottom side where you can code. On this input bar, you can see the contents of a data frame/variable by writing their name</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qExhVDgkz2qeIvn8s1engg.png" /><figcaption>Figure 2. Viewing the ridge_results df values using the interactive window. Source: Author</figcaption></figure><p>This functionality means that you can confirm the contents of your data frames faster, and since the code used in the input bar does not stay in your file, you end up with a cleaner file without bloat code.</p><p>Moreover, using the “variables” button gives you access to a list of all the variables created through your code, including data frames. If you access any of your data frames from the list, a new tab with the entire data frame will appear where you can perform filters and confirm its values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lzXkUbdo9LZcFCml_XJM7A.png" /><figcaption>Figure 3. Accessing the values of a DF. Source: Author</figcaption></figure><ul><li><em>The tabs allow us to see current/previous results, and the code makes analysis easier/faster to iterate.</em></li></ul><p>Using the input bar, you can also make calculations and create new data frame columns or assign data frames to fleeting variables to check later. This way, you can observe new and previous results as well as your current code, all in the same window. This is incredibly convenient for highly iterative work.</p><p>Adding those commands into the console tab instead of your main code will make your final code easier to understand and, generally, cleaner. A clean code can be beneficial when sharing your code with collaborators or reviewing it yourself after some time.</p><ul><li><em>You can implement tools exclusive to Python scripts, such as debugging tools, formatting, etc.</em></li></ul><p>If you use Python Interactive files, you can access programming tools available on your IDE. A simple example of this is the tool for changing the name of a variable everywhere you use it at once.</p><p>Sometimes, a variable name is less descriptive than I first thought or is too similar to another variable. In a notebook, I would have to change the variable’s name in each cell where I used it, which can lead to mistakes. That fact deterred me from changing the name of a variable on more than one occasion. Instead, if you use the IDE tool to change all instances of a variable simultaneously, you can avoid unnecessary debugging.</p><ul><li><em>Easy portability .py -&gt; .IPynb (notebook) /.IPynb -&gt;.py</em></li></ul><p>At any point, you can convert a Notebook file into an interactive Python file and vice versa. This conversion is useful if you want to publish a notebook version of your research online or share it with students or colleagues.</p><p><strong><em>Cons:</em></strong></p><ul><li><em>The markdown cells do not pop out in the .py file; they are only on the console.</em></li></ul><p>If you open your notebook using VS code and export it as a Python script, it will become a Python interactive file, and all your markdown cells will be carried over. You can also add new markdown cells to the Python Interactive file. To do it, you must add [Markdown] after the # %% delimitating the cell in the Python file.</p><p><em>ex:</em> # %% [Markdown]</p><p>However, these markdown cells are only rendered in the console, not the .py file. If you are used to identifying your code sections with markdown cells, it will take some time to get used to reading the comments instead. The pictures below show how the markdown cells look in the .py file and the interactive window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PaoXPTN8G8I4RGFcVkFEUA.png" /><figcaption>Figure 4. Markdown Cell in a Python Interactive file. Source: Author</figcaption></figure><p>In this video, I explain the UI and how I’m using Python Interactive files: <a href="https://www.loom.com/share/9a818233d67b4add834b536088feff69?sid=871ca309-863d-408f-a622-3b4d88145595">https://www.loom.com/share/9a818233d67b4add834b536088feff69?sid=871ca309-863d-408f-a622-3b4d88145595</a></p><p><strong>How to run an Interactive Python file:</strong> <a href="https://www.loom.com/share/1e26ca9298b1490c943cb5a5ff4ba3a5">https://www.loom.com/share/1e26ca9298b1490c943cb5a5ff4ba3a5</a></p><p><strong>Interactive Python Documentation:</strong> <a href="https://code.visualstudio.com/docs/python/jupyter-support-py">https://code.visualstudio.com/docs/python/jupyter-support-py</a></p><p><strong>Download VScode:</strong> <a href="https://code.visualstudio.com/download">https://code.visualstudio.com/download</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=070c2b871bae" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>