<?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 Ashish Kulkarni on Medium]]></title>
        <description><![CDATA[Stories by Ashish Kulkarni on Medium]]></description>
        <link>https://medium.com/@ashishkulkarnii?source=rss-44c2e9e2df3b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vuT001wT7LaavRO3YtQ5ng.jpeg</url>
            <title>Stories by Ashish Kulkarni on Medium</title>
            <link>https://medium.com/@ashishkulkarnii?source=rss-44c2e9e2df3b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 05:14:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ashishkulkarnii/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[Linear Regression Made Simple]]></title>
            <link>https://medium.com/analytics-vidhya/linear-regression-made-simple-d5315db78a14?source=rss-44c2e9e2df3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5315db78a14</guid>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[calculus]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <category><![CDATA[linear-regression]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Ashish Kulkarni]]></dc:creator>
            <pubDate>Sat, 24 Apr 2021 09:08:08 GMT</pubDate>
            <atom:updated>2022-02-21T15:37:09.142Z</atom:updated>
            <content:encoded><![CDATA[<h4>The Basic Mathematics Behind Machine Learning</h4><p>Many people, especially those new to the field, often show great interest in the field of machine learning, but shy away from the mathematics that govern it. I hope to demystify it for you by explaining, in simple terms, the math behind machine learning. Linear regression is one the most fundamental mathematical algorithms used in supervised learning.</p><blockquote><em>You may ask,</em> “What is linear regression?”</blockquote><p>Regression, in English, means a return to a less developed state. The technical definition doesn’t stray far. Regression is a method of analysis used to understand the relationship between two or more variables. This is a valuable tool in prediction and optimization.</p><p>Let’s start understanding the principles behind linear regression, and gradient descent, graphically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*paxK2DHCyFZkehm2Rka8Aw.jpeg" /><figcaption>Image by author</figcaption></figure><h3>Simple Linear Regression</h3><p>Let us assume, arbitrarily, we have a distribution of points as shown:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mERNIwhgRjucLJmqLPMsYg.png" /><figcaption>Image by author</figcaption></figure><p>Linear regression seeks out an approximation of this distribution — a line that best explains the given distribution, a line that best describes the pattern of the data. Let us call this the <em>best fit line</em>. Intuitively, linear regression explains this exact thing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pj2KPBiT68PxxOwrBvzwPg.png" /><figcaption>Image by author</figcaption></figure><p>We can algebraically represent the above line as <em>y = h(x)</em>, where:</p><blockquote><em>h(x) = </em>θ₀ + θ₁ <em>x</em></blockquote><p><em>h </em>stands for <em>hypothesis</em>, <em>θ </em>represents parameter, and <em>x </em>is a feature. The objective of performing linear regression on the data set is to find the optimum values of <em>θ₀</em> and <em>θ₁</em> such that <em>h(x</em>) is most suitable to explain the behavior of the data.</p><p>Above, we saw what is called <em>simple linear regression</em>, which involves only one <em>explanatory variable</em>. This method of linear regression has its use cases, but more often than not, we find ourselves needing to analyse more than one feature. This leads us to <em>multiple linear regression.</em></p><h3>Multiple Linear Regression</h3><p>Multiple linear regression is similar to simple linear regression, with the additional complexity of taking into consideration <em>n </em>different features, as opposed to just one. The equation for the best fit line (hypothesis function) now looks like this:</p><blockquote>h(x) = θ₀ + θ₁ x₁ + θ₂ x₂ + θ₃ x₃ + … + θₙ xₙ</blockquote><p>The <em>θ</em> terms represent parameters, also called weights, and it is quite easy to understand why. From the equation of <em>h(x)</em>, it is clear that the parameters determine the extent of influence of the features on the behavior of the system. We could also say <em>θᵢ </em>defines the importance of a particular feature <em>xᵢ </em>in the final output.</p><p>To better understand how we would apply multiple linear regression in the real world, let us take the famous example of the house pricing algorithm. Here, we use the features of the house (number of bedrooms, number of bathrooms, area, and location) to determine the price of a house. We could take other features into account as well, but for the sake of this example, let’s take these four.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3417ecc81b415921dca38b85052e719b/href">https://medium.com/media/3417ecc81b415921dca38b85052e719b/href</a></iframe><p>Using our equation for the line of best fit on the first house, we have:</p><blockquote>30 = θ₀ + 1 . θ₁ + 1 . θ₂ + 500 . θ₃ + 3 . θ₄</blockquote><p>Similarly, we can create an equation for all the houses and hence find the optimal parameters.</p><h4>Loss Function</h4><p>Let us, for the sake of simplicity, assume a system of only one explanatory variable. A system of two variables would require us to draw a 2-d plane, and three explanatory variables would require a hyperplane to represent it. A hyperplane is impossible to visualize, so let’s stick to one explanatory variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xfgCIXfyEC9DkSzHLtlP2A.png" /><figcaption>Image by author</figcaption></figure><p>We can clearly see our approximate best fit line is quite far from many of the points. Let’s call the vertical deviation of a point from the best fit line <em>e</em>. This <em>e </em>is the difference between predicted and actual values. Then, our goal is to minimize Σ<em>e</em>. To do this, let us introduce a function:</p><blockquote>J(θ) = Σ<em>e</em></blockquote><p><em>J(θ</em>) is called loss function, or error function. To further analyse and minimize the loss function, let’s expand <em>e.</em></p><p><em>e </em>is equal to the vertical distance between the actual point and a point on the estimated line of best fit. Since we do not want the distances to cancel out when we take its summation, we square this value.</p><blockquote><em>e</em>₁<em> = (h(x</em>₁<em>) - y</em>₁)² , e₂ = (h(x₂) - y₂)² and so on…</blockquote><p>Therefore, we have:</p><blockquote>J(θ) = (1/2m) Σ(h(xᵢ) - yᵢ)², where i goes from 0 to m, m is the total number of examples.</blockquote><p>The reason we take <em>1/m </em>is because our summation value will be unnecessarily large otherwise, and we take <em>1/2 </em>to help simplify computation, as you will see later. This is how we arrive at the loss function. This method of calculating error is called <em>mean squared error.</em></p><p>Extrapolating our loss function to account for multiple additional dimensions, we have:</p><blockquote>J(θ) = (1/2m) Σ(θ₀ + θ₁ x₁<em>ᵢ</em> + θ₂ x₂<em>ᵢ</em> + θ₃ x₃<em>ᵢ</em> + … + θₙ xₙ<em>ᵢ </em>- y<em>ᵢ</em>)², i: 0 ➡ m</blockquote><p>To find the optimal parameters, we employ a method known as <em>gradient descent</em>.</p><h4>Finding the Slope at a Point on the Curve</h4><p>To use gradient descent to find the optimal parameters, we need to know how to find the slope at each point on the curve. To understand this process graphically, let us again assume a case of simple linear regression, where <em>h(x) = θ₀ + θ₁ x</em>.</p><blockquote>J(θ) = (1/2m) Σ(θ₀ + θ₁ x₁ᵢ - yᵢ)², i: 0 ➡ m</blockquote><p>From the equation for <em>J(θ)</em>, we can tell the plot between <em>J(θ)</em> and θ₁ will be that of a parabola, since the equation of a parabola is <em>y = ax² + bx + c.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4w5oDsc59cgXQ04FyLlrcw.jpeg" /><figcaption>Image by author</figcaption></figure><p>Once again, it is clear why I chose to graphically represent only a case of simple linear regression, as anything more would have required beyond three dimensions.</p><p>It becomes apparent that to minimize <em>J(θ)</em>, we must find the local minima of the curve. Using basic calculus, to find the slope of the tangent at a particular point of a curve, we must differentiate the function and substitute the values corresponding to that particular point. Applying that knowledge here, using partial derivatives since <em>J(θ) </em>is a function of both <em>θ₀</em> and <em>θ₁</em>, we get:</p><blockquote><strong>∂</strong>J(θ) / <strong>∂</strong>θ₀ = (1/2m) 2 Σ(θ₀ + θ₁ x₁ᵢ - yᵢ)(1 + 0 – 0), i: 0 ➡ m</blockquote><blockquote>∂J(θ) / ∂θ₀ = (1/m) Σ(θ₀ + θ₁ x₁ᵢ - yᵢ), i: 0 ➡ m</blockquote><blockquote>∂J(θ) / ∂θ₀ = (1/m) Σ(h(xᵢ) - yᵢ), i: 0 ➡ m</blockquote><p>Now we understand why I introduced a <em>2</em> in the denominator while defining the loss function.</p><p>Partially differentiating <em>J(θ) </em>with respect to <em>θ₁</em>, we get:</p><blockquote>∂J(θ) / ∂θ₁ = (1/2m) 2 Σ(θ₀ + θ₁ x₁ᵢ - yᵢ)(0 + x₁ᵢ - 0), i: 0 ➡ m</blockquote><blockquote>∂J(θ) / ∂θ₁ = (1/m) Σ(θ₀ + θ₁ x₁ᵢ - yᵢ)(x₁ᵢ), i: 0 ➡ m</blockquote><blockquote>∂J(θ) / ∂θ₁ = (1/m) Σ(h(xᵢ) - yᵢ)(x₁ᵢ), i: 0 ➡ m</blockquote><p>We can introduce a feature <em>x₀</em> to <em>h(x)</em>, where <em>x₀ = 1.</em></p><blockquote>h(x) = θ₀ x₀ + θ₁ x₁ + θ₂ x₂ + θ₃ x₃ + … + θₙ xₙ, where x₀ = 1</blockquote><p>Then we can rewrite <em>∂J(θ)/∂θ₀ </em>as:</p><blockquote>∂J(θ) / ∂θ₀ = (1/m) Σ(h(xᵢ) - yᵢ)(x₀ᵢ), i: 0 ➡ m</blockquote><p>Observing <em>∂J(θ)/∂θ₀ and ∂J(θ)/∂θ₁</em>, we can make the generalization:</p><blockquote>∂J(θ) / ∂θₙ = (1/m) Σ(h(xᵢ) - yᵢ)(xₙᵢ), i: 0 ➡ m</blockquote><p>This is how we calculate the slope of the tangent at a point on the curve.</p><h4>Gradient Descent</h4><p>Gradient descent is an iterative optimization algorithm to find the local minima of a function. Let’s understand it in a step by step visualization.</p><p>Let us choose an arbitrary point on the curve, and find the slope of the tangent at that point. We already have the equation for it, above. The slope at that point tells us about which direction the minima is.</p><p>The minima is the point at which the value of <em>J(θ) </em>is minimum, which means at this point we will find our optimal parameter values.</p><p>If the slope at this point is negative, for instance, this tells us the minima is towards the right, and if the slope is positive, the minima is towards the left. In other words, the slope of the tangent points us towards the local minima.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9w0S515Md-vA8LH5tGlzFQ.jpeg" /><figcaption>Image by author</figcaption></figure><p>Theoretically, now that we know which way to move, by iterating in incremental steps in the right direction, we must eventually come close to the optimal solution.</p><blockquote><em>Now you may ask, </em>“How do we know by how much we must move every iteration?”</blockquote><p>This brings us to the final topic for this article, the <em>learning rate.</em></p><h4>Learning Rate</h4><p>Gradient descent uses a hyperparameter called learning rate, <em>α</em>, to control the size of each step we take towards the optimal solution. A learning rate too small would result in too many required epochs to reach the optimal solution, and learning rate too large would risk overshooting the minima and diverging.</p><p>The perfect <em>α </em>will start comparatively high, and become successively smaller as we approach the minima, so as to find the perfect balance between number of epochs and precision. This can be done by having an α proportional to the slope at the point. The larger the slope, the larger the step we take in the minima’s direction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*An4tZEyQAYgPAZl396JzWg.png" /><figcaption>Image by <a href="https://www.jeremyjordan.me/nn-learning-rate/">Jeremy Jordan</a></figcaption></figure><p>Mathematically, we incorporate learning rate into our approach towards the minima as follows:</p><blockquote>θₙ := θₙ - <em>α (</em>∂J(θₙ)/ ∂θₙ<em>), or</em></blockquote><blockquote>θₙ := θₙ - α (slope)</blockquote><h4>Gradient Descent Optimizations</h4><p>One of the problems with the concept of gradient descent arises when the error function doesn’t resemble a parabola and has multiple minimas. In this case, we always want to find the global minima of the function.</p><p>Gradient descent poses the risk of getting stuck in a local minima, depending on where we randomly initialise our weight (from where we start the gradient descent process).</p><p>One of the solutions to this would be running the algorithm several times with different initialised weights, hoping that one of these times, the minima found is global.</p><p>Another solution is by using Momentum, which is an optimization of gradient descent which can be visualised as us pushing the ball down a hill (the function). By principle, the ball would roll past local minima (assuming it starts at a high enough point) and if we incorporate air resistance the ball will eventually end up at the global minima.</p><p>If you read all the way, and found this useful, thanks! Feel free to leave suggestions or comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5315db78a14" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/linear-regression-made-simple-d5315db78a14">Linear Regression Made Simple</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Comprehensive Guide to Creating a Basic Reddit Bot [Part 3]]]></title>
            <link>https://medium.com/analytics-vidhya/a-comprehensive-guide-to-creating-a-basic-reddit-bot-part-3-351817cffae2?source=rss-44c2e9e2df3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/351817cffae2</guid>
            <category><![CDATA[reddit]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[analytics-vidhya]]></category>
            <category><![CDATA[bot-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Ashish Kulkarni]]></dc:creator>
            <pubDate>Wed, 21 Apr 2021 15:53:19 GMT</pubDate>
            <atom:updated>2021-08-27T18:25:09.326Z</atom:updated>
            <content:encoded><![CDATA[<h4>Reddit Bot Development 101</h4><ul><li><a href="https://medium.com/analytics-vidhya/a-comprehensive-guide-to-creating-a-basic-reddit-bot-part-1-15fb0e4cebcb">A Comprehensive Guide to Creating a Basic Reddit Bot [Part 1]</a></li><li><a href="https://medium.com/analytics-vidhya/a-comprehensive-guide-to-creating-a-basic-reddit-bot-part-2-85de2fd300cd">A Comprehensive Guide to Creating a Basic Reddit Bot [Part 2]</a></li></ul><p>In parts 1 and 2 of this series, we created a working bot that analysed post titles, searched them for keywords, and matched region names with their current COVID-19 stats. However, we didn’t handle two final problems:</p><ol><li>Our bot does not keep track of which posts it has replied to. So if we run our program in a loop, it’ll end up replying to the same posts multiple times.</li><li>The bot does not remain active all the time. It only replies when it’s run by us.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ia-UBfZll4nbEJib" /><figcaption>Photo by <a href="https://unsplash.com/@askkell?utm_source=medium&amp;utm_medium=referral">Andy Kelly</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Ensuring Only One Reply Per Post</h3><p>One foolproof way to make sure a post is only replied to once is by having our program create a text file, and writing the submission ID of each post we reply to to it. This way, the IDs are stored and can be accessed during the next execution as well. We can implement this method as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3022718751a0571dbb649db92eda2a4f/href">https://medium.com/media/3022718751a0571dbb649db92eda2a4f/href</a></iframe><p>Now, before looking through the post for a keyword, we add the following condition to check whether the current post’s ID is part of the list <em>IDs </em>or not:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5aa952e8b75ddec82f70c8670776602/href">https://medium.com/media/e5aa952e8b75ddec82f70c8670776602/href</a></iframe><p>And finally, if the current post satisfies all necessary conditions, once we perform our action on it, we write its ID to the text file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d10834201444d3df88a119b94dca860/href">https://medium.com/media/2d10834201444d3df88a119b94dca860/href</a></iframe><h3>Keeping Our Bot Active All the Time</h3><p>There are three main ways we could go about this.</p><ul><li>We can monitor the subreddit our bot has been deployed in for activity. Hence, our bot would only run when a new post has been made.</li><li>We can have our program be executed periodically using a task scheduler.</li><li>We can have our program run eternally, using a <em>sleep </em>function within the program as per our requirements.</li></ul><p>I chose the last option. I added a <em>while True</em> condition before the bulk of my program (leaving only function definitions outside it), and a <em>sleep </em>function at the end of the program, within the <em>while</em> function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb1aceb4d852c96348d61c4b734fd874/href">https://medium.com/media/eb1aceb4d852c96348d61c4b734fd874/href</a></iframe><h3>Handling the Problems in covibot</h3><p>Here’s how <a href="https://github.com/ashishkulkarnii/covibot">covibot</a> (from <a href="https://medium.com/analytics-vidhya/a-comprehensive-guide-to-creating-a-basic-reddit-bot-part-2-85de2fd300cd">Part 2</a>) looks with the two above issues sorted:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a378e34ad30177928e53f15ad014bee/href">https://medium.com/media/6a378e34ad30177928e53f15ad014bee/href</a></iframe><p>The above bot can be deployed to a server and permanently brought to life, or you can run it locally if you have the means. Heroku offers a number of free dyno hours which you can utilize, especially if this project is purely experimental.</p><p>If you read all three parts to my Reddit bot development guide, thank you!</p><p><a href="https://www.linkedin.com/in/ashishkulkarnii/">Ashish Kulkarni - Technical Writer - Analytics Vidhya | LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=351817cffae2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/a-comprehensive-guide-to-creating-a-basic-reddit-bot-part-3-351817cffae2">A Comprehensive Guide to Creating a Basic Reddit Bot [Part 3]</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Comprehensive Guide to Creating a Basic Reddit Bot [Part 2]]]></title>
            <link>https://medium.com/analytics-vidhya/a-comprehensive-guide-to-creating-a-basic-reddit-bot-part-2-85de2fd300cd?source=rss-44c2e9e2df3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/85de2fd300cd</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[reddit]]></category>
            <category><![CDATA[bots]]></category>
            <category><![CDATA[covid19]]></category>
            <dc:creator><![CDATA[Ashish Kulkarni]]></dc:creator>
            <pubDate>Wed, 10 Mar 2021 14:21:56 GMT</pubDate>
            <atom:updated>2021-08-25T13:58:17.422Z</atom:updated>
            <content:encoded><![CDATA[<h4>Reddit Bot Development 101</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ccJFSX-aNKyPp8M0" /><figcaption>Photo by <a href="https://unsplash.com/@agk42?utm_source=medium&amp;utm_medium=referral">Alex Knight</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In part one of this series, I showed you how to get our bot up and running. We understood how the bot accesses Reddit, and how it sees posts. However, we never got to the interactive part of the bot, which is unarguably its most important feature. So in this article, that’s what we’ll cover.</p><p>If you haven’t read Part 1 yet, I highly suggest you do so:</p><p><a href="https://medium.com/analytics-vidhya/a-comprehensive-guide-to-creating-a-basic-reddit-bot-part-1-15fb0e4cebcb">A Comprehensive Guide to Creating a Basic Reddit Bot [Part 1]</a></p><h3>Commenting With Our Bot</h3><p>This is honestly a breeze, since PRAW gives us all the tools we need. All we have to do is import PRAW, call our bot, add it to a subreddit (of our choice), look for a submission or multiple submissions (sorted by <em>hot, top, new, </em>or<em> rising</em>), and post a reply. We can do so like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d72d554e3fd0d1b1819cd89269d7cba8/href">https://medium.com/media/d72d554e3fd0d1b1819cd89269d7cba8/href</a></iframe><p>Once again, I’m using r/SpaceJam2021 as the subreddit for my testing. Don’t spam popular subreddits with your bot testing, it can be annoying to other users.</p><p><em>submission.reply(“”)</em> replies with the passed argument as the comment, and the line below it just gives us a confirmation of the post our bot replied to in the terminal.</p><h3>Commenting on Posts Satisfying a Condition</h3><p>Let’s take this one step further and add some conditions for the posts our bot should reply to. It’s impractical, in most scenarios, for a bot to comment on every single post.</p><p>So in the following program, I’ve instructed our bot to reply “I am a bot!” only to posts which contain the string “Are you a bot” in the title, ignoring case. By changing <em>limit</em>, you can change the number of posts you want to look through every execution.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a46286557e7335222876d576c0e833a/href">https://medium.com/media/5a46286557e7335222876d576c0e833a/href</a></iframe><h3>Accessing and Parsing Datasets for Desired Stats</h3><p>I mentioned in Part 1 that the goal of my project was to create a Reddit bot that provided statistics on COVID-19 cases for a particular geographical region. The reason I decided to create a bot instead of something more generic like an app, or webpage, was because I wanted to inform the unaware. I wanted to inform people who weren’t even looking for the information I was going to give them. No other implementation I thought of could effectively do this task.</p><p>So a major part of my bot, which isn’t necessarily relevant to your bot, is accessing datasets with the help of free online APIs.</p><p>The first step I took was to find a free API service that was willing to access reliable, well-maintained datasets that stored statistics on COVID-19 (active cases, deaths, etc.). I found <a href="https://apify.com/">Apify</a>, a free and trusted web scraping solution, which accesses various government/official websites for COVID-19 stats and turns this data into a publicly available API that’s refreshed every five minutes.</p><p>For instance, Apify accesses the <a href="https://mohfw.gov.in/">Ministry of Health and Family Welfare</a> for Indian COVID-19 stats and the <a href="https://www.cdc.gov/">Centers for Disease Control and Prevention</a> for those of the USA.</p><p>Apify’s datasets are JSON files, so they’re easy to parse using Python. <a href="https://api.apify.com/v2/key-value-stores/tVaYRsPHLjNdNBu7S/records/LATEST?disableRedirect=true">This</a> is how the World dataset looks, and <a href="https://api.apify.com/v2/key-value-stores/toDWvRj1JpTXiM8FF/records/LATEST?disableRedirect=true">this</a> is how that of India looks.</p><p>Since I always want to have the latest and greatest data, it’s pointless storing the data locally. So, we’re going to have to access the online datasets at runtime. Here’s the code I used to do that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce1a17a25b6045fc7e2d1d27bccf9d83/href">https://medium.com/media/ce1a17a25b6045fc7e2d1d27bccf9d83/href</a></iframe><p>There’s no need for getting into the weeds, but essentially <em>world_covid_stats</em> is now a dictionary that contains all the data Apify had on world COVID-19 stats at the time.</p><p>Since I’m from India, I decided to give a little more in-depth information about statistics within India. So I added this code to get state-wise information:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4126a85e4b9e94e66aad59da14e93b98/href">https://medium.com/media/4126a85e4b9e94e66aad59da14e93b98/href</a></iframe><p>The reason I used india_covid_stats[“regionData”] is because the JSON file was prefaced with data about India as a whole, and I wanted to skip parsing through it at runtime.</p><h3>Creating Our Final Bot</h3><p>So now that we have all the data we need, we can start finishing up our code. I wanted the bot to provide the information without being explicitly called, and this meant I’d have to account for all kinds of sentence formations by the user. I’m sure more advanced coders would settle on implementing an NLP model into the bot, but I decided to take a slightly easier route.</p><p>The bot looks through the title of Reddit posts for keywords such as <em>going</em>, <em>visiting</em>, <em>in</em>, etc. and if it happens to find any of these, it looks through both datasets for the name of an Indian state or the name of a country. If it finds one, it retrieves the corresponding data and leaves it in a comment.</p><p>For example, if a post says<em> I’m visiting Russia for a bit</em>, the bot will reply <em>Russia has 348160 current cases, be careful!</em></p><p>Here’s the code for my bot:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4417fe6a6df5abfc36401759821e7671/href">https://medium.com/media/4417fe6a6df5abfc36401759821e7671/href</a></iframe><p>If you’re interested in running covibot, head over to <a href="https://github.com/ashishkulkarnii/covibot">it’s repo</a>, and read the instructions in the README.md file.</p><p>We finally have a working Reddit bot that intelligently interacts with other platform users! You may think we’re done here, not quite. Here are a few flaws we’re yet to address:</p><ol><li>Our bot has to be invoked manually. It does not automatically reply to posts on our subreddit, rather, we have to run it every time we want it in action.</li><li>Our bot is not yet aware of which posts it has replied to, an which it hasn’t. So if you run it twice, and there were no new posts in the interval between the two times, you’re bound to see multiple comments by our bot.</li></ol><p>Here is Part 3 of this series, where we take care of these last two problems:</p><p><a href="https://medium.com/analytics-vidhya/a-comprehensive-guide-to-creating-a-basic-reddit-bot-part-3-351817cffae2">A Comprehensive Guide to Creating a Basic Reddit Bot [Part 3]</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85de2fd300cd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/a-comprehensive-guide-to-creating-a-basic-reddit-bot-part-2-85de2fd300cd">A Comprehensive Guide to Creating a Basic Reddit Bot [Part 2]</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Influence of the Golden Ratio on Art]]></title>
            <link>https://medium.com/math-simplified/the-influence-of-the-golden-ratio-on-art-c9dc3698a2c1?source=rss-44c2e9e2df3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9dc3698a2c1</guid>
            <category><![CDATA[phi]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[golden-ratio]]></category>
            <category><![CDATA[fibonacci]]></category>
            <category><![CDATA[art]]></category>
            <dc:creator><![CDATA[Ashish Kulkarni]]></dc:creator>
            <pubDate>Fri, 05 Mar 2021 07:16:46 GMT</pubDate>
            <atom:updated>2021-05-06T13:50:36.820Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Photograph of Aeonium tabuliforme by Max Ronnersjö" src="https://cdn-images-1.medium.com/max/1024/1*Av0BE5L9ia0B9BGiAx9clQ.jpeg" /><figcaption>Photograph of Aeonium tabuliforme by <a href="https://commons.wikimedia.org/wiki/User:Maxronnersjo">Max Ronnersjö</a></figcaption></figure><p>The golden ratio, phi, has always had a mystic aura around it. It is found naturally occurring in many forms, be it in the biological structure of flowers and shellfish, or even the spiral of our galaxy. So what is the golden ratio?</p><p>In simple terms, any two numbers are said to be in the golden ratio if their ratio is equal to the ratio of their sum to the greater of the two numbers. Mathematically, two numbers <em>a </em>and <em>b </em>are in golden ratio if <em>(a+b)/a = a/b, </em>for <em>a&gt;b&gt;0.</em></p><p>More interesting is the relation between the Fibonacci series and phi. The Fibonacci series is a series in which every subsequent number is the sum of the two preceding numbers, and starts as: 0, 1, 1, 2, 3, 5, 8, 13, … Interestingly, if we take the ratio of two adjacent Fibonacci numbers, we get increasingly closer to the value of phi, approximately 1.618.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80add317b04f3927d14d6daa79bb11f7/href">https://medium.com/media/80add317b04f3927d14d6daa79bb11f7/href</a></iframe><figure><img alt="The influence of phi in art is substantial, with artists like Leonardo da Vinci employing the golden proportion in his famous portrait, the Mona Lisa." src="https://cdn-images-1.medium.com/max/523/0*lvs9bFpx5KgvyUll" /><figcaption>Lines drawn with the Golden Ratio superimposed on ‘The Mona Lisa’ by Leonardo da Vinci</figcaption></figure><p>The influence of phi in art is substantial, with artists like Leonardo da Vinci employing the golden proportion in his famous portrait, the Mona Lisa.</p><figure><img alt="The Italian mathematician, Luca Pacioli published a series, the Divina Proportione, which discusses the role that phi played in aestheticizing architecture, calligraphy, and so on." src="https://cdn-images-1.medium.com/max/471/0*o-QQ0WXDZa4z7vvV" /><figcaption>Lines drawn with the Golden Ratio superimposed on a drawing of the Gate of the Temple of Jerusalem</figcaption></figure><p>The Italian mathematician, Luca Pacioli published a series, the Divina Proportione, which discusses the role that phi played in aestheticizing architecture, calligraphy, and so on.</p><p>The reach of the golden ratio extends to even music. One of the most popular examples of phi in music is Beethoven’s Symphony 5 in Cm, where the opening motifs occur at two specific spots, which can be mathematically traced back to the two golden section points from the beginning and end of the song respectively. However, Derek Haylock, the man who noticed this phenomenon, was forced to exclude the concluding 20 measures to make the theory fit.</p><p>Mathematicians and artists alike have credited many pleasing works of art to be related to the divine proportion, but these claims are disputed by many. Modern experts have debunked the theory that the golden ratio makes objects more aesthetic.</p><p>Even in nature, though many plant species adhere to the Fibonacci sequence in their seed or petal patterns, there are just as many species that don’t. So while phi is naturally occurring and abundant, its significance is largely overstated.</p><p>For example, the ratio of HD, 16:9, is <em>close </em>to phi. And yes, the Mona Lisa <em>does </em>have influences of phi in its design. But the introduction of phi in design has never been scientifically proven to make patterns more pleasing than those without it.</p><p>Designers today largely ignore the golden ratio in creating consumer products or logos. As Edmund Hariss, mathematician at University of Arkansas said, “It is a simple number in many ways, and as a result it does turn up in a wide variety of places… [But] it is certainly not the universal formula behind aesthetic beauty.”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9dc3698a2c1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/math-simplified/the-influence-of-the-golden-ratio-on-art-c9dc3698a2c1">The Influence of the Golden Ratio on Art</a> was originally published in <a href="https://medium.com/math-simplified">Math Simplified</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Use of Quantum Computing in the Field of Finance]]></title>
            <link>https://medium.com/the-quantum-happening/the-use-of-quantum-computing-in-the-field-of-finance-4a27e4a91fd8?source=rss-44c2e9e2df3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a27e4a91fd8</guid>
            <category><![CDATA[finance]]></category>
            <category><![CDATA[quantum-computing]]></category>
            <category><![CDATA[optimization]]></category>
            <dc:creator><![CDATA[Ashish Kulkarni]]></dc:creator>
            <pubDate>Thu, 04 Mar 2021 10:28:52 GMT</pubDate>
            <atom:updated>2021-05-05T11:05:17.074Z</atom:updated>
            <content:encoded><![CDATA[<p>Quantum computing is the process of computation based on quantum phenomena, such as superposition or entanglement. Quantum computers are well known for being able to factor large numbers, which is a task classical computers find almost impossible. Furthermore, results obtained from quantum calculations are probabilistic rather than deterministic, i.e., the output can vary even if all other factors remain unaltered. Hence, quantum computers are used for tasks such as advanced cryptography, simulation of quantum systems and their behaviour, and even a new branch of machine learning — quantum machine learning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wdr-r_RsWnOeNQx3" /><figcaption>Photo by <a href="https://unsplash.com/@lazycreekimages?utm_source=medium&amp;utm_medium=referral">Michael Dziedzic</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>However, most people are unaware of the potential applications of quantum computing in finance, so let’s discuss it in this article. IBM categorizes the use cases of quantum computing for financial services into three main categories: targeting and prediction, trading optimization, and risk profiling. Quantum computers should theoretically be much more superior than classical computers in customer targeting and prediction modeling as they are better at finding patterns and making predictions on data structures too complex to be operated on currently. When it comes to trade optimization, as we have all seen in the news recently, complexity in financial markets trading activity is on a rapid ascent. On top of the introduction of various inclusions to the valuation adjustments model for derivatives, we have been noticing market activity of late being influenced by multiple external factors, on top of the basic supply and demand principles. Quantum computing technology should help traders, especially those with large hedge positions, optimize portfolio diversification and more precisely simulate the outcomes of risk scenarios.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Df2ps9UnYrZ2XbFm" /><figcaption>Photo by <a href="https://unsplash.com/@sonance?utm_source=medium&amp;utm_medium=referral">Viktor Forgacs</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Of these various use cases, quantum optimization is of greatest importance, as optimization problems are at the core of most financial problems. The two main optimization problems faced by the finance industry are high-dimensional optimization problems and combinatorial optimization problems. High-dimensional optimization problems involve optimizing portfolios that are based on computationally intense models that process large amounts of data. Quantum computing could pave a way for faster and more accurate decision-making. Combinatorial optimization is implemented to enhance an algorithm by using mathematics to eliminate possibilities or to catalyze the searching process. The most prominent way to implement quantum optimization algorithms is using a process called quantum annealing.</p><p>Quantum annealing is the process of generating a partial search algorithm that provides a sufficiently optimal solution for finding the global minimum of a specified objective function, given an incomplete or imperfect set of candidate solutions, by a process using quantum fluctuations-based computation, rather than classical computation, to find an absolute minimum from a finite, but large, set of possible solutions.</p><p>Not all the market players believe quantum computing is a key differentiator for their business model, citing the fact that computational speed and agility are not crucial to serving a client. But, undoubtedly, quantum computing is increasingly gaining attention as it tackles complex problems, especially in the optimization area.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a27e4a91fd8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-quantum-happening/the-use-of-quantum-computing-in-the-field-of-finance-4a27e4a91fd8">The Use of Quantum Computing in the Field of Finance</a> was originally published in <a href="https://medium.com/the-quantum-happening">The Quantum Happening</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Comprehensive Guide to Creating a Basic Reddit Bot [Part 1]]]></title>
            <link>https://medium.com/analytics-vidhya/a-comprehensive-guide-to-creating-a-basic-reddit-bot-part-1-15fb0e4cebcb?source=rss-44c2e9e2df3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/15fb0e4cebcb</guid>
            <category><![CDATA[reddit-bot]]></category>
            <category><![CDATA[praw]]></category>
            <category><![CDATA[reddit]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Ashish Kulkarni]]></dc:creator>
            <pubDate>Wed, 03 Mar 2021 15:27:25 GMT</pubDate>
            <atom:updated>2021-05-21T03:07:30.511Z</atom:updated>
            <content:encoded><![CDATA[<h4>Reddit Bot Development 101</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*I3U9e95abZ-9tQsx" /><figcaption>Photo by <a href="https://unsplash.com/@brett_jordan?utm_source=medium&amp;utm_medium=referral">Brett Jordan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>For a coding competition I recently took part in, I was asked to create a product or concept that would benefit society, while still being innovative and accessible. After some consideration, I ended up with the idea of creating a Reddit bot that tells people COVID-19 statistics for a particular region the original poster intends to travel to. The catch is, I didn’t want the bot to be invoked consciously, rather, I wanted the bot to automatically detect the user’s destination, retrieve well-maintained data, and post it as a comment in an unobtrusive manner.</p><p>While I was doing research on how to create a bot as per my requirements, I didn’t find the information I needed at a single source. So in this article, I hope to fill that gap by explaining the exact step-by-step process I took in creating my bot, and hopefully this helps you out as well!</p><h3>The Software You’ll Need</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VwUbnG_ZXTPlERkn" /><figcaption>Photo by <a href="https://unsplash.com/@timothycdykes?utm_source=medium&amp;utm_medium=referral">Timothy Dykes</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this article, I’ll be looking at how to make a bot using <a href="https://www.python.org/">Python</a>, version 3.6 or higher to be specific, so make sure you have that installed on your computer.</p><p>The next thing you’ll be needing is PRAW — the Python Reddit API Wrapper. PRAW is a Python package that allows you to access Reddit’s APIs in the easiest way possible. It has been designed to follow all of Reddit’s API guidelines, so breaking the rules is a nonissue. Installing PRAW is also extremely easy; just type <em>pip install praw </em>into your Command Prompt Terminal. pip is the Python package installer. If you receive an error saying you don’t have pip installed, then learn how to install it <a href="https://pip.pypa.io/en/stable/installing/">here</a>.</p><h3>How Our Bot Sees a Reddit Page</h3><p>Now that we’ve got all the software we’ll need in place, let’s take a quick look at how the Reddit API really works. It’s quite simple, to be honest. Essentially, Reddit gives all the data on a Reddit page in the .json format, which you can parse in Python the way you would a dictionary.</p><p>I created the subreddit r/SpaceJam2021 for testing my bot; here’s how it looks to <a href="https://www.reddit.com/r/SpaceJam2021/new/">you</a>, and here’s how it looks to our <a href="https://www.reddit.com/r/SpaceJam2021/new/.json">bot</a>.</p><h3>Registering Our Bot on Reddit</h3><p>The next step in creating our bot is to register it on Reddit. We do this by creating a Reddit app. Sign into the account you would like to operate your bot out of (create a new account if you’d rather the bot remain separate from your personal account), and go to <a href="https://www.reddit.com/prefs/apps/">this page</a>. Click on <em>create an app </em>at the bottom of the page. Here you’ll be prompted to fill in a <em>name</em>, and a <em>redirect uri. </em>Choose the bullet point <em>script</em>, and leave the other text boxes blank (they’re optional). The <em>redirect uri</em> is irrelevant to our Reddit bot, so use a dummy URL like <a href="http://example.com/">example.com</a>.</p><p>The page it takes you to gives us the user ID (under the text <em>personal use script</em>) and the secret key. These two pieces of information will be useful for later.</p><h3>Updating the praw.ini File With Our Bot’s Details</h3><p>This part may be a little complicated, especially if your computer is cluttered. You’re gonna have to find your <em>Python</em> folder, navigate to the <em>Lib</em> folder, then the <em>site-packages</em> folder, and find the <em>praw</em> folder.</p><p>In the <em>praw</em> folder, you’ll see a file named <em>praw.ini. </em>We have to add our bot’s details to this file, but I would recommend avoiding changing the original <em>praw.ini</em> file, just in case we mess something up. So create a copy of <em>praw.ini</em>, and then open the original one.</p><p>Open <em>praw.ini</em> with notepad, and add the following lines at the bottom:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c63ae21c5aa359aede1a9efe6b8cd661/href">https://medium.com/media/c63ae21c5aa359aede1a9efe6b8cd661/href</a></iframe><p><em>bot1 </em>is just to differentiate our bot from existing/future bots of yours. Add client ID and client secret after the respective ‘=’ signs (in single or double quotes). <em>username</em> and <em>password</em> correspond to those of the account your bot is to operate out of, and <em>user_agent</em> is just a random name you can give your project. All the details you fill in here are sensitive, which is why we add it to <em>praw.ini</em> instead of the code itself.</p><p>On a side note, if you couldn’t find the praw folder, and since the File Explorer search is quite underwhelming, I recommend using <a href="http://www.wox.one/">Wox</a> for Windows.</p><h3>Testing Out Our Bot’s Ability to Read Posts</h3><p>The PRAW package has plenty of attributes, which you can find <a href="https://praw.readthedocs.io/en/latest/code_overview/praw_models.html">here</a>. But for testing the bot’s ability to read we need the following lines of code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6be25a9c319c84e5cab0646cbd93fd24/href">https://medium.com/media/6be25a9c319c84e5cab0646cbd93fd24/href</a></iframe><p>Let’s go through the lines one-by-one:</p><ul><li><em>import praw</em> imports the PRAW package to our code.</li><li><em>r = praw.Reddit(‘bot1’) </em>essentially gives<em> bot1</em> access to Reddit.</li><li>We use <em>r.subreddit(“SpaceJam2021”)</em> to indicate which subreddit our bot will be functioning in. You can replace <em>SpaceJam2021</em> with the subreddit of your choice.</li><li><em>limit = 5</em> means we will see only the first five posts of the page. We can use <em>hot, top, new, </em>or<em> rising</em> to sort the posts.</li></ul><p>You can try it out, and leave any findings or suggestions in the comments.</p><p>That’s all for this article. In the next one, I’ll explain how the interactive part of the bot works. Let me know if this was helpful!</p><p><a href="https://medium.com/analytics-vidhya/a-comprehensive-guide-to-creating-a-basic-reddit-bot-part-2-85de2fd300cd">A Comprehensive Guide to Creating a Basic Reddit Bot [Part 2]</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15fb0e4cebcb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/a-comprehensive-guide-to-creating-a-basic-reddit-bot-part-1-15fb0e4cebcb">A Comprehensive Guide to Creating a Basic Reddit Bot [Part 1]</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>