<?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 Irvan Elmahendra on Medium]]></title>
        <description><![CDATA[Stories by Irvan Elmahendra on Medium]]></description>
        <link>https://medium.com/@elmahendra.irvan?source=rss-36dfc44e940f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*tvLlOKrM2SLjGSvw</url>
            <title>Stories by Irvan Elmahendra on Medium</title>
            <link>https://medium.com/@elmahendra.irvan?source=rss-36dfc44e940f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 11:09:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@elmahendra.irvan/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[Machine Learning Algorithm: Artificial Neural Networks (ANN) Explained]]></title>
            <link>https://medium.com/@elmahendra.irvan/machine-learning-algorithm-artificial-neural-networks-ann-explained-b0bc90912e4b?source=rss-36dfc44e940f------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0bc90912e4b</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-neural-network]]></category>
            <category><![CDATA[feed-forward-networks]]></category>
            <category><![CDATA[backpropagation]]></category>
            <dc:creator><![CDATA[Irvan Elmahendra]]></dc:creator>
            <pubDate>Wed, 03 Apr 2024 12:19:35 GMT</pubDate>
            <atom:updated>2024-04-03T12:19:35.126Z</atom:updated>
            <content:encoded><![CDATA[<p>Artificial Neural Networks (ANN) serve as a fundamental component in the field of artificial intelligence, offering a way for computers to process information in a manner reminiscent of the human brain. These networks are designed to recognize patterns, make predictions, and solve problems by learning from data. This guide will introduce you to the basics of how ANNs function, their structure, and the principles behind their operation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*AyWYpiALkA6tqMudaxJyCA.png" /></figure><p>ANN is divided into three layers:</p><ul><li><strong>Input Layer</strong>: The input layer does not perform any calculations. It simply holds the data that will be sent to the hidden layer for processing.</li><li><strong>Hidden Layer</strong>: The hidden layer is responsible for processing the data received from the input layer. This processing involves calculations that transform the input data.</li><li><strong>Output Layer</strong>: The output layer presents the final outcome of the data processed by the hidden layer, effectively representing the ANN’s predictions or decisions.</li></ul><p>In its simplest configuration, an ANN includes just one input layer, one hidden layer, and one output layer. This basic structure can efficiently illustrate the core concepts of neural networks, such as data processing flow and the learning mechanism through the adjustment of weights and biases across the network.</p><p>For connections and calculations within the network, every connection from an input node to a hidden node and from a hidden node to an output node is characterized by two key elements: a <strong>weight</strong> and a <strong>bias</strong>. Each connection has a weight (denoted as<strong> w1</strong>, <strong>w2</strong>, …, <strong>wn</strong> for connections to the hidden layer and <strong>w′1</strong>, <strong>w′2</strong>, …, <strong>w′n</strong> for connections to the output layer), which scales the input value. In addition to the weights, each node in both the hidden and output layers is associated with a bias value (denoted as <strong>b</strong> for hidden nodes and <strong>by</strong> for output nodes).</p><h4>How The Networks Learn?</h4><p>The learning process in artificial neural networks (ANNs) is fascinating, enabling these networks to progressively improve their performance on tasks such as classification, regression, and more. This process hinges on two primary mechanisms: <strong>Feedforward</strong> and <strong>Backpropagation</strong>. Together, these mechanisms allow ANNs to adjust their internal parameters (weights and biases) in response to the input data, enhancing their ability to make accurate predictions or decisions.</p><p><strong>Feed-Forward</strong></p><p>The journey of learning starts with feedforward, the phase where the input data traverses through the network from the input layer, through any hidden layers, to the output layer. For simplicity, let’s consider an ANN with 1 input node (denoted as <strong><em>X</em></strong>), 2 hidden nodes (denoted as <strong><em>h</em>1</strong>​ and <strong><em>h</em>2</strong>​), and 1 output node (denoted as <strong><em>Y</em></strong>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*PXSMbEMw1hofkY0u5gS5Rg.png" /></figure><p>The computation for each hidden node includes a linear combination of the input and its respective weight, plus the bias. The result of this linear operation is then passed through an activation function <strong><em>f</em></strong> (such as ReLU, sigmoid, or tanh) to introduce non-linearity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*qubvARJShHXRbz3ikdng9w.png" /></figure><p>The output <strong><em>Y</em></strong> is computed based on the outputs of the hidden nodes <strong><em>h</em>1​</strong> and <strong>ℎ2</strong>​, with associated weights, and a bias <strong><em>by</em></strong> for the output node. The computation involves summing the products of each hidden node’s output with its respective weight, adding the output bias, and applying another activation function for the output layer <em>g.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*V4brEMIdkRCcble2tOb-gw.png" /></figure><p>That value of Y will be use as a resource to update the weights in the backpropagation phase.</p><p><strong>Backpropagation</strong></p><p>In backpropagation, the error is calculated (from the feedforward Y value) and propagated back through the network to update the weights and biases. First, we need to calculate the error using the Mean Squared Error formula, where T is the target (actual value).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/167/1*VJO09v-TtaV2zodbMOKu3g.png" /></figure><p>To adjust the weights and minimize the error, backpropagation calculates how much each weight contributes to the output error. This involves computing the gradient of the error with respect to each weight in the network. With the gradients calculated, each weight is updated to minimize the error, adjusting in the direction opposite to the gradient by a factor of the learning rate (<strong>α</strong>). The learning rate basically determine how big of a step that your networks update the weight values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/188/1*Cocy36SN5vfLC7hsBWe5Hg.png" /></figure><p>Similarly, a comparable update process applies to the biases, using their respective gradients.</p><p>The cycle of feedforward — backpropagation is repeated across many epochs, or passes through the dataset. Each epoch refines the model’s weights and biases to minimize the error between the predicted outputs and the actual targets in the training data. Once the training phase is deemed complete (after a predefined number of epochs), the model is ready to make predictions. This is done through the feedforward process which we’ve already discussed, where new and unseen inputs are fed into the model, processed through the same network architecture (with the finely tuned weights and biases).</p><p>In summary, this article has outlined the fundamental architecture and operational mechanisms of Artificial Neural Networks, emphasizing the critical roles of feedforward computation and backpropagation in the model’s ability to learn from data and subsequently make predictions, thereby highlighting the importance of these processes for advancing and applying efficient machine learning models.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0bc90912e4b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Geographic visualization in python using Pyplot and GeoPandas.]]></title>
            <link>https://medium.com/@elmahendra.irvan/geographic-visualization-in-python-using-pyplot-and-geopandas-696081c796b8?source=rss-36dfc44e940f------2</link>
            <guid isPermaLink="false">https://medium.com/p/696081c796b8</guid>
            <category><![CDATA[geographical-data]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[geopandas]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Irvan Elmahendra]]></dc:creator>
            <pubDate>Thu, 07 Mar 2024 04:41:16 GMT</pubDate>
            <atom:updated>2024-03-07T04:41:16.137Z</atom:updated>
            <content:encoded><![CDATA[<p>Geographic data, with its unique blend of spatial information and numerical insights, offers a rich canvas for exploration and storytelling. In this piece, our focus will be on transforming a dataset of taxi trips across New York into a visual map, highlighting the frequency of trips across different zones. Before we dive into the mechanics of Pyplot and GeoPandas, let’s first acquaint ourselves with the dataset(df)that we use as a base of the map visualization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*gexNXKRYydkBcWUCxum5Cw.png" /><figcaption>NY Taxi Trips Dataset</figcaption></figure><p>Our analysis is built upon a dataset that captures the dynamics of taxi trips in the city. This dataset is structured around three core attributes:</p><ul><li>PUzoneNAME: This column represents the ‘Pick-Up Zone Name,’ identifying the specific area in the city where each taxi trip originated. The zoning framework for these names is created by the New York Taxi and Limousine Commission (NY TLC), providing us with meticulously defined geographical markers.</li><li>TripCount : Reflecting the ‘Total Number of Trips’ from each pick-up zone, this column quantifies the activity within each area. A higher trip count indicates a zone bustling with movement, serving as a hub of transportation and interaction.</li><li>PUgeometry : This column contains the ‘Geographic Information’ for each pick-up zone. It maps out the spatial boundaries that define each area, converting abstract zone names into concrete, visual shapes. This geometric data is pivotal for our map visualization, as it allows us to plot each zone accurately on the map, giving physical context to our analysis.</li></ul><p>It’s crucial to ensure that our data is in the right format for geographical analysis. Specifically, we need to verify that the PUgeometry column, which contains the geographic information of each pick-up zone. The ideal format for this column is a ‘geometry’ data type, which enables GeoPandas to effectively create and manipulate geospatial data. To perform this check, we can use the .info() method on our DataFrame.</p><pre>df.info()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/428/1*6sTk9bAPiR8W3sTQ_0dLOg.png" /><figcaption>Data type of each column</figcaption></figure><p>The next thing we need to do, is importing the library that is needed to create a geographical visualization. Geopandas is used for handling and plotting the geospatial data, and the Pyplot module is a part of the Matplotlib library, which is a plotting library that GeoPandas uses under the hood for its plotting capabilities.</p><pre>import geopandas as gpd<br>import matplotlib.pyplot as plt</pre><p>To build the geographic visual, we first create a GeoDataFrame named gdf from our main data frame df . The geometry parameter is set to the name of the column in df that contains the geometric data representing each zone. This step transforms our standard DataFrame into a GeoDataFrame, which is specifically designed to handle spatial data.</p><pre>gdf = gpd.GeoDataFrame(df, geometry=&#39;geometry&#39;)</pre><p>Next, we utilize Matplotlib’s pyplot (plt) to create a figure and axes object, setting the size of our plot with figsize=(10, 10). We then call the .plot() method on our GeoDataFrame, specifying several key arguments:</p><ul><li>ax=ax directs the plot output to the axes object we created, allowing for further customization</li><li>column=&#39;TripCount&#39; tells the plot function to use the TripCount column to determine the color intensity for each zone; zones with higher trip counts will appear in a darker shade.</li><li>cmap=&#39;Blues&#39; selects the color map for our plot.</li><li>edgecolor=&#39;k&#39; sets the boundary color of each zone to black (&#39;k&#39;), enhancing the visual distinction between zones.</li><li>legend=True adds a legend to the plot.</li></ul><pre>fig, ax = plt.subplots(figsize=(10, 10))<br>gdf.plot(ax=ax, column=&#39;TripCount&#39;, cmap=&#39;Blues&#39;, edgecolor=&#39;k&#39;, legend=True)</pre><p>Finally, we set the title of our plot to ‘Map of Taxi Trip Zones by Trip Count’ using ax.set_title() , and plt.show() to display the plot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*l520ytt_i_5q0OXR8nBnZw.png" /><figcaption>Map of taxi trip pick-up location count in New York</figcaption></figure><p>The visualization above represents taxi trip frequencies across different zones in New York. The map uses varying shades of blue to depict the density of taxi pickup locations, with darker hues indicating areas of higher trip concentration and lighter shades representing zones with fewer trips. This color gradient allows us to quickly identify zones that are hotspots for taxi pickups, suggesting areas of high demand.</p><p>That visualization may provide useful information but the audience might want to know some of the location name that has high amount of trips (demand). This not only draws attention to these key areas but also provides a clearer understanding of the specific locations that are most frequented by taxi users.</p><pre>top_zones = grouped_df.sort_values(by=&#39;TripCount&#39;, ascending=False).head(5)<br><br># Plotting<br>fig, ax = plt.subplots(figsize=(10, 10))<br>gdf.plot(ax=ax, column=&#39;TripCount&#39;, cmap=&#39;Blues&#39;, edgecolor=&#39;k&#39;, legend=True, legend_kwds={&#39;label&#39;: &quot;Number of Trips&quot;})<br><br># Label the top 5 zones<br>for idx, row in top_zones.iterrows():<br>    <br>    xy = row[&#39;PUgeometry&#39;].centroid.coords[0]<br>    ax.annotate(text=row[&#39;PUzoneNAME&#39;], xy=xy, ha=&#39;center&#39;, fontsize=6, fontweight=&#39;bold&#39;)<br><br>ax.set_title(&#39;Map of Taxi Trip Zones by Trip Count&#39;)<br>plt.show()</pre><p>To achieve the labeling of the zones, we need to make a modification from the previous mentioned code snippets.</p><ul><li>First, we need to create a variable that contains the top 5 most crowded zone (topzone).</li><li>For each of the top 5 zones, we calculate the centroid of the polygon representing the zone’s geographical area (row[&#39;PUgeometry&#39;].centroid) to determine the optimal placement for the zone&#39;s name label.</li><li>ax.annotate method is used to add text annotations to the map. For each of the top zones, it places a label at the coordinates specified by xy (the centroid of the zone)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*wf8zb61a8f3X340y2iT-fQ.png" /><figcaption>Labeled Zones with the most taxi trip pick-up locations</figcaption></figure><p>In conclusion, integrating a geographic information with taxi trip data offers a unique lens through which we can explore urban mobility patterns. Such visualizations not only serve as powerful tools for storytelling but also provide valuable insights for city planners, transportation companies, and policymakers aiming to understand and improve urban transportation networks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=696081c796b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimizing Queue Operation Using Pythons “Deque”.]]></title>
            <link>https://medium.com/@elmahendra.irvan/optimizing-queue-operation-using-pythons-deque-e2abed402d39?source=rss-36dfc44e940f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2abed402d39</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[deque]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Irvan Elmahendra]]></dc:creator>
            <pubDate>Wed, 31 Jan 2024 07:54:57 GMT</pubDate>
            <atom:updated>2024-01-31T07:54:57.993Z</atom:updated>
            <content:encoded><![CDATA[<p>The <strong>deque</strong>, an abbreviation for ‘Double Ended Queue,’ represents a collection data type that is frequently overlooked by many Python programmers, despite its efficiency and practicality. While the commonly used ‘List’ offers versatility and a wider range of applications, the deque excels in efficiency and quicker processing times, especially in handling both ends of a data collection. This makes it the superior choice, particularly in scenarios where efficient management of queue and stack operations is crucial. Before we go any further, Let’s explore where the deque stands within Python . Python’s collections library hosts various specialized data structures, among them are chainMap, Counter, OderedDict, DefaultDict, NamedTuple and the Deque itself. To incorporate deque functionalities into your code, simply import it using the following line.</p><pre>from collections import deque</pre><p>Essentially, a deque shines in situations demanding frequent append or pop operations at both ends of a sequence, providing superior performance compared to lists when managing a large number of elements. To make a deque, we just need to use the `deque() command and put a List inside of it.</p><pre>my_deque = deque([4, 5, 6, 7])</pre><p>While methods like pop, append(), and extend() exist in both regular lists and deques, our focus will center on exploring the additional methods unique to deque. Deque offers a number of unique methods available, among them are appendleft(x), popleft(),extendleft(iterable), and rotate(n). The appendleft(x) and popleft() methods specifically add and remove elements from the left (front) side of the deque, respectively. Below is a simple Python code snippet showcasing the implementation of these methods on a previously created deque:</p><pre># appendleft(x)<br># x = value that will be appened<br><br>#add elements to the left side of the deque<br>my_deque.appendleft(3) <br>my_deque.appendleft(2)<br>my_deque.appendleft(1)<br><br># Display deque and removed elements<br>print(my_deque)<br><br># Output:<br># deque([1, 2, 3, 4, 5, 6])</pre><pre># popleft()<br><br>#remove elements from the left side of the deque<br>my_deque.popleft()<br>my_deque.popleft()<br><br>print(my_deque)<br># Output:<br># deque([3, 4, 5, 6])</pre><p>As can be seen, the code above is adding the value 3, 2, and 1 by performing the appendleft() method three times, each time appending the respective value to the left side of the deque. The second block of code performs the popleft() method two times so the value 1 and 2 will be removed from the deque as its positioned on the left-most side of the deque, resulting the updated deque ([3, 4, 5, 6]).</p><p>The next method that is unique to deque is the extendleft(iterable) method. This method allows for the addition of multiple elements from an iterable to the left (front) side of the deque. This method is quite handy when you want to efficiently insert multiple elements at the beginning of the deque. Below is a simple code snippet demonstrating the usage of extendleft() add elements from an iterable at the front of a deque. Notice that the first element that got appended to the deque is the first index of the iterable (‘Jamie’), resulting the new updated deque [‘Nick’, ‘Jamie’, ‘Alex’, ‘Matt’].</p><pre># extendleft(iterable)<br><br>member = deque([&#39;Alex&#39;, &#39;Matt&#39;])<br><br>addition = [&#39;Jamie&#39;, &#39;Nick&#39;]<br><br>member.extendleft(addition)<br><br># Output:<br># deque([&#39;Nick&#39;, &#39;Jamie&#39;, &#39;Alex&#39;, &#39;Matt&#39;])</pre><p>Lastly, the rotate(n) method. This method allows the rotation of elements within the deque. When assigned with a positive value n, the method rotates the deque n steps to the right, while a negative value n rotates it to the left. This method is useful in scenarios where reordering elements or shifting their positions within the deque is necessary. Below is a Python code implementing the usage of rotate() to demonstrate the rotation of elements within a deque:</p><pre>numbers = deque([1, 2, 3, 4, 5])<br><br># Rotate the deque to the right by 2 steps<br>numbers.rotate(2)<br>print(numbers)  <br><br># Output: <br># deque([4, 5, 1, 2, 3])<br><br># Rotate the deque to the left by 3 steps<br>numbers.rotate(-3)<br>print(numbers)  <br><br># Output: <br># deque([2, 3, 4, 5, 1])</pre><p>While the unique methods such as appendleft(), popleft(), extendleft(iterable), and rotate(n) offer specialized functionalities, there&#39;s another feature within deques that proves notably beneficial, and may potentially save some lines in your code: the <strong>maxlen</strong> parameter. The <strong>maxlen </strong>(max length)<strong> </strong>parameter creates a restriction for the deques length, and will automatically discard the elements when the maximum capacity is reached. Below is the simple code that uses <strong>maxlen </strong>parameter to limit the length of the deque, and adds another element when the deque is at the maximum capacity of 3. As elements are added to the deque and it reaches its maximum length, the oldest element is automatically discarded when a new element is appended.</p><pre># Creating a deque with a maximum length of 3<br>limited = deque(maxlen=3)<br><br># Adding elements to the deque<br>limited.append(1)<br>limited.append(2)<br>limited.append(3)<br>print(limited)  <br><br># Output: <br># deque([1, 2, 3])<br><br># Adding another element (4)<br>limited_deque.append(4)<br>print(limited)  <br><br># Output: <br># deque([2, 3, 4])</pre><p>We previously discuss the supperiority of deque when it comes to handling both ends of a data collection. Lets make a quick experiment that will showcase the performance of deque compares to a regular list. This experiment involves appending and popping elements (a total of 300.000 elements) to both ends of a collection. The ‘timeit’ library is used to measure the time it takes for the both deque and list process the elements that are being appended and popped.</p><pre>from collections import deque<br>import timeit<br><br>def compare():<br>    <br>    def deque_operations():<br>        my_deque = deque()<br>        for i in range(100000): # Appends elements from 0 to 99,999 at the right end of the deque <br>            my_deque.append(i)<br>        for i in range(50000): # Pops 50,000 elements from the right end of the deque <br>            my_deque.pop()<br>        for i in range(100000): # Appends elements from 0 to 99,999 at the left end of the deque <br>            my_deque.appendleft(i)<br>        for i in range(50000): # Pops 50,000 elements from the left end of the deque <br>            my_deque.popleft()<br><br>    def list_operations():<br>        my_list = []<br>        for i in range(100000): # Appends elements from 0 to 99,999 at the right end of the list <br>            my_list.append(i)<br>        for i in range(50000): # Pops 50,000 elements from the right end of the list<br>            my_list.pop()<br>        for i in range(100000): # Inserts elements from 0 to 99,999 at the beginning of the list<br>            my_list.insert(0, i) <br>        for i in range(50000): # Pops 50,000 elements from the beginning of the list <br>            my_list.pop(0)<br><br>    # Measure time taken for the operation<br>    time_deque = timeit.timeit(deque_operations, number=1)<br>    time_list = timeit.timeit(list_operations, number=1)<br><br>    print(&quot;deque operations time:&quot;, time_deque)<br>    print(&quot;list operations time:&quot;, time_list)<br><br>compare()<br><br># Output:<br># deque operations time: 0.01229740001144819<br># list operations time: 12.113316899980418</pre><p>The experiment clearly demonstrates the significant performance difference between the deque and the regular list when it comes to handling operations at both ends of a collection. While the deque took a mere 0.012 seconds to perform the operations, the list consumed notably more time, approximately 12.113 seconds, for similar operations. The efficiency, versatility, and specialized functionalities offered by the deque, such as appendleft(), popleft(), extendleft(iterable), rotate(n), and the adaptable maxlen parameter, makes it a really handy tool to optimize your queue/stack operations and improve the performance of your program. Python programmers seeking optimal performance and practical handling of queue and stack operations should consider the deque as their choice of collection.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2abed402d39" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>