<?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 Akram Azarm on Medium]]></title>
        <description><![CDATA[Stories by Akram Azarm on Medium]]></description>
        <link>https://medium.com/@akram.arm.7?source=rss-910d57d894e6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*EoY4jojHM-BUfbqaNUtZUg.jpeg</url>
            <title>Stories by Akram Azarm on Medium</title>
            <link>https://medium.com/@akram.arm.7?source=rss-910d57d894e6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 17:40:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@akram.arm.7/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[Simple Linear Regression explained Simply!]]></title>
            <link>https://medium.com/@akram.arm.7/simple-linear-regression-explained-simply-23c1c9bf89b9?source=rss-910d57d894e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/23c1c9bf89b9</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[linear-regression]]></category>
            <category><![CDATA[supervised-learning]]></category>
            <dc:creator><![CDATA[Akram Azarm]]></dc:creator>
            <pubDate>Mon, 30 Dec 2019 20:58:25 GMT</pubDate>
            <atom:updated>2019-12-30T21:02:00.236Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Zhgnf7_VnVmsZZed" /><figcaption>Photo by <a href="https://unsplash.com/@chrisliverani?utm_source=medium&amp;utm_medium=referral">Chris Liverani</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This is a continuation of my previous blog where I tried to explain <a href="https://medium.com/@akram.arm.7/machine-learning-in-laymans-terms-b941b82a7833">Machine Learning in Layman’s Terms</a> and in this blog I will go about explaining how to implement a solution for a simple ML problem. I would highly recommend you to read my previous blog before reading this to get a good intuition for this topic.</p><p>The problem we are trying to solve in this project is to predict the salary of an employee based on the number of years of experience he or she has in the banking industry. This is an example of a Regression problem as we are trying to predict a real or a continuous value. We will be using Python as our programming language and the <a href="https://scikit-learn.org/stable/">sci-kit learn</a> library to take care of the complex logic needed to train the <em>model</em> and predict. The Python script for this project can be found on <a href="https://gist.github.com/aka4rKO/59df7d6ca3117777c71baaa34013f005">Github</a>.</p><h4>Step 1: Data Gathering</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*5tftSCJTn-Jz1SRtVi4cIg.png" /><figcaption>Dataset containing 30 observations that we are going to use for our sample project.</figcaption></figure><p>The above <em>dataset</em> has 2 columns; <strong>YearsExperience </strong>is the independent variable(feature) which we will be using to predict the <strong>Salary </strong>which is the dependent variable(label). Also since the <em>dataset</em> is labelled its evident that this problem can be solved using Supervised Learning.</p><h4>Step 2: Data pre-processing</h4><p>The data in this <em>dataset</em> is already prepared in a way the model can understand therefore this step can be skipped. However in cases like the <em>dataset</em> having missing data attributes or non-numeric values it has to be prepared before it can be used on a model.</p><pre># Simple Linear Regression</pre><pre># Importing the libraries<br>import numpy as np<br>import matplotlib.pyplot as plt<br>import pandas as pd</pre><pre># Importing the dataset<br>dataset = pd.read_csv(&#39;Salary_Data.csv&#39;)<br>X = dataset.iloc[:, :-1].values<br>y = dataset.iloc[:, 1].values</pre><p>The lines above imports the required libraries and separates the <em>dataset</em> into <strong><em>X</em></strong> which is the matrix containing the independent variables and <strong><em>y</em></strong> which is a vector containing the dependent variables.</p><h4>Step 3: Choosing a model</h4><p>Now that we know this problem can be solved using Supervised Learning we have to select a model that will fit the <em>dataset</em> in order to get better predictions. Choosing a model mostly relies on the <em>dataset</em> therefore we need to analyze the data and see if we can find a pattern in it. For this purpose we will be plotting the data on to a scatter plot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*Sg-xa4j39kcVFS6YMTW8Tw.png" /></figure><p>In the scatter plot above we can see a Linear pattern(the Salary increases with the number of Years of Experience). Therefore what we need is a Linear Regression model.</p><h4>Step 4: Training the model using the datasets available</h4><p>Now that we have decided which model we are going to use we need to train it. Before training the model the <em>dataset</em> must be separated into a train set(for training) and a test set(for testing). We will allocate 1/3 of the <em>dataset</em> for testing and the rest for training. <br>Basically what the training process does is that it finds the best fit for the model, in this case it fits a Linear function(<strong>y = mx + c</strong>) that will satisfy all the training observations as shown in the image below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*bchBdnrLZQdu3vFjLnSgoQ.png" /></figure><h4>Step 4.1: Training the model(under the hood)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*TlZNojrL7ijqw9XWHiJ1BQ.png" /></figure><p>The ultimate goal of the training process is to find the optimum values for the <strong>m</strong>(slope of the Linear function) and <strong>c</strong>(intercept of the <em>y-axis</em>). The way it determines the 2 values is by iteratively applying values for <strong>m</strong> and <strong>c </strong>and calculating the cost of all the observations using the cost function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*jjB3Tl80rWeJztbEsNsnBQ.png" /></figure><p>and when the cost is <strong>0</strong> or the closest it can get to<strong> 0</strong>, the values used for <strong>m</strong> and <strong>c</strong> are determined as the optimum values for the <em>model</em>.</p><p>There is a more efficient and effective way to get values for <strong>m</strong> and <strong>c</strong> during each iteration using an algorithm called <strong><em>Gradient Descent</em></strong> to learn more about this algorithm check <a href="https://www.youtube.com/watch?v=sDv4f4s2SB8">this video</a> out.</p><p>When a new observation is introduced to the trained model with the number of years, it projects it on to the fitted line and then projects it to the Y axis to find the predicted salary.</p><pre># Splitting the dataset into the Training set and Test set<br>from sklearn.model_selection import train_test_split<br>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 1/3, random_state = 0)</pre><pre># Fitting Simple Linear Regression to the Training set<br>from sklearn.linear_model import LinearRegression<br>regressor = LinearRegression()<br>regressor.fit(X_train, y_train)</pre><p>The lines above splits the <em>dataset</em> into train and test sets. After splitting, the train set is fitted on to the <em>LinearRegression</em> model of the <em>sklearn</em> library.</p><h4>Step 5: Evaluating the model</h4><p>Since the model is trained now it can be used on the test set to check the accuracy.</p><pre># Predicting the Test set results<br>y_pred = regressor.predict(X_test)</pre><p>The line above uses the trained model to predict the test set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*VF6rkIokRySaUfYVRMbrZg.png" /></figure><h4>Step 6: Prediction</h4><p>Here is where the magic happens! You can use the model we trained to predict Salaries of any employee in the banking industry whose data were not included in the <em>dataset</em>.</p><pre># Predicting a new observation<br>random_prediction = regressor.predict([[10]])</pre><p>The line above is used to predict the salary of a random employee with <strong>10</strong> years of experience in the banking industry.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/113/1*tm7fFYapxo5wSovJYsd4xw.png" /><figcaption>Predicted result</figcaption></figure><p>🙌 <strong>CONGRATULATIONS!!!</strong> 🙌 You just taught a machine to predict salaries.</p><p><strong>Recommendation:<br></strong><a href="https://www.udemy.com/course/machinelearning/">https://www.udemy.com/course/machinelearning/</a><br><a href="https://www.coursera.org/learn/machine-learning">https://www.coursera.org/learn/machine-learning</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23c1c9bf89b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Machine Learning in Layman’s Terms.]]></title>
            <link>https://medium.com/@akram.arm.7/machine-learning-in-laymans-terms-b941b82a7833?source=rss-910d57d894e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/b941b82a7833</guid>
            <category><![CDATA[unsupervised-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[supervised-learning]]></category>
            <category><![CDATA[semi-supervised-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Akram Azarm]]></dc:creator>
            <pubDate>Sat, 23 Nov 2019 15:22:25 GMT</pubDate>
            <atom:updated>2019-11-23T15:35:41.409Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2bWyEzzT6_MJ2NnD" /><figcaption>Photo by <a href="https://unsplash.com/@franckinjapan?utm_source=medium&amp;utm_medium=referral">Franck V.</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3><strong>What is Machine Learning?</strong></h3><p>Humans learn from <em>past experiences</em> and make sure they are better prepared when they come across a similar situation in the future. In the other hand machines follow instructions given by humans to perform certain operations, but what if there is a way for machines to teach themselves to learn when humans provide <em>past experiences</em> as instructions to overcome similar situations from the past?</p><p>Yes, there is a way and it is called <strong>Machine Learning</strong>.<br><strong>NOTE:</strong> <strong>Machine Learning </strong>is NOT a technology it’s a concept.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ob0KwCB_bAQsJ-PuUPmSKQ.jpeg" /></figure><p><strong>Technology, </strong>is a way of implementing a concept.<br><strong>Concept, </strong>is an abstract idea.</p><p>Eg: In web development front-end is a <strong>Concept<em> </em></strong>and Angular is a <strong>Technology<em>.</em></strong></p><p>To save keystrokes, I use the terms “ML” and “Machine Learning” interchangeably. 😃</p><h3>How Machine Learning works in terms of…</h3><h4>Humans</h4><p>Lets take a scenario of a person named James who has never eaten a pizza. James decided to go to the nearest Pizza Hut and ordered a medium sized pizza. Half way through eating the pizza he understood(learnt) that a medium sized pizza was too much for him as by that time he was already full.<br>The next day James decided to go to Pizza Hut but this time he knew from his <em>past experience</em> that a medium sized pizza is too much and this time he ordered a small pizza which was enough to eat to his fill.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*cH4m0kVsZRmo9810lECGLA.png" /></figure><p>James didn’t have any prior experience eating a pizza so he didn’t have any idea how much pizza he needed on the 1st day but the next day with the help of his <em>brain</em> he learnt the right amount of pizza he needed.</p><h4>Typical Computer Programs</h4><p>Lets take a simple program which outputs the type of a coin when a coin is presented to the program. Here we will be considering the weight as the feature of the coin to differentiate and identify the type of coin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*D9saNH39H7v3aaRwIqVxpA.png" /><figcaption>A rupee weighs 3 grams, an euro weighs 7 grams and a dirham weighs 4 grams.</figcaption></figure><p>Imagine you were given a 1000 coins which contains rupees, euros and dirhams and were asked to separate them into 3 different containers.<br>The typical steps taken to solve this challenge using programming would be:</p><ol><li>Get all the coins to one place</li><li>Represent the coins in a way a program can understand using a <em>Coin class</em></li><li>Write a suitable <em>method/function</em> to separate the coins with a proper algorithm</li><li>Test if your <em>method/function</em> outputs the expected value for each coin</li><li>Modify the algorithm to get the desired output when it doesn’t</li><li>Use your <em>method/function</em> on a new set of coins and see it work on coins it was never tested on</li></ol><p><strong>NOTE: </strong>This is NOT exactly how Machine Learning works but this is only for explaining purposes.</p><h3>How Machine Learning works.</h3><p>For anything to be learnt there needs to be data, in ML these are called <em>datasets</em>(sets of data, the more the data; the better the prediction). Data alone is not enough we need something called a <em>model</em> which basically is an algorithm which is used to predict based on the data provided.<br>Machines don’t process like the human brain, they have to follow a certain process in order to learn by itself.<br>A typical ML project would consist of the following steps;</p><ol><li>Data gathering</li><li>Data pre-processing(preparing the data in a way a machine can understand)</li><li>Choosing a <em>model</em>(an algorithm that will fit the <em>dataset</em>)</li><li>Training the <em>model</em> using the <em>datasets</em> available</li><li>Evaluating the <em>model</em></li><li>Prediction</li></ol><h4>Mapping terminologies</h4><p>The table below is used to map the relationship between the terms that were used in the examples(humans and typical computer programs) to the terms used in Machine Learning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*D2KOuNX5TvAWPOnxMoZb4w.png" /></figure><p>ML is a sub field of <strong><em>Artificial Intelligence</em></strong> which is then again categorized as follows: (in other words the following are the different ways a Machine can learn)</p><ol><li>Supervised Learning</li><li>Unsupervised Learning</li><li>Semi-supervised Learning</li><li>Reinforcement Learning(Not in the scope of this blog)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*UPWox-QOLXCsx2e0DmhWpw.png" /><figcaption>The ellipsis represents that there are other sub-categories of Artificial Intelligence that are not included in this diagram.</figcaption></figure><p><strong>NOTE: <em>Artificial Intelligence</em></strong><em> </em>is not in the scope of this blog, it is a much broader topic.</p><h3>Types of Machine Learning.</h3><p>These are the different ways a machine can learn. The way they differ mainly depends on the representation of the <em>dataset</em>. Selecting a type of ML <em>model</em> depends on the problem you are trying to solve but they also can be used interchangeably.</p><h4>Supervised Learning</h4><p>In Supervised Learning the machine is taught how to predict, using a <em>labelled</em><strong> </strong><em>dataset</em>. <br>First the ML <em>model</em> is trained using 80% of the <em>labelled dataset </em>also known as train set and then the trained <em>model</em> is used on new data(data that is not <em>labelled</em>) for prediction. Here by <em>labelled</em> I mean the expected output of the prediction is also included in the <em>dataset</em> so that the <em>model</em> can cross check if it has predicted correctly when testing it with the remaining 20% of the <em>labelled</em><strong><em> </em></strong><em>dataset </em>also known as test set(generally only 80% of the whole <em>dataset</em> is used to train the <em>model</em> and the rest 20% is used to test the accuracy of the <em>model</em> before it can be used on completely new data).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*nbOBjRK0GqUyXqlNQhEZjw.png" /></figure><p>The above is a <em>labelled dataset</em> of images which contains handwritten numbers with its corresponding label which says what number the image represents.</p><h4>Unsupervised Learning</h4><p>In Unsupervised Learning the machine learns all by itself. It learns based on certain patterns found in the <em>dataset </em>and then groups them if they logically belong to any pattern of data found in the <em>dataset</em>. This technique is called <em>clustering.<br></em>Unsupervised learning approach can be unpredictable as the machine figures out how to solve a problem on its own. On the plus side Unsupervised Learning can help to see another dimension of which a normal human being cannot see but it might also create clutter instead of order as it might have clusters of data that do not make any sense.<br>Eg: If we try to classify the handwritten numbers from the above example without the <em>dataset</em> being <em>labelled</em> it might categorize the <strong>number 7 </strong>into two different clusters which does not make any sense.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*7YY5WV9kCRBeQr7aBDYZ9g.jpeg" /></figure><p>The <strong>number 7</strong> written without and with a dash might get categorized into two different clusters as it is not explicitly <em>labelled</em>. Therefore an Unsupervised Learning <em>model</em> would not help to solve this type of a problem.</p><p>Unsupervised Learning is usually used to solve <em>clustering</em> and <em>dimensionality</em><strong><em> </em></strong><em>reduction</em> problems. Recommending something to someone is a problem that can be solved using <em>clustering</em>.</p><p>Eg: Recommending products to people on e-commerce sites. The purchase patterns of different people differ and they cannot be <em>labelled</em> as “will buy” and “wont buy”. One cannot come to a conclusion saying a particular person will buy a particular product according to his purchase pattern history as there are so many factors that a person would consider before purchasing an item like season, weather, age, mood etc.<br>Recommending a product can be unpredictable which is why an Unsupervised Learning <em>clustering</em> algorithm(<em>model</em>) could help in identifying a rare dimension that a normal person cannot see which will help to provide better recommendations to the customers.</p><blockquote>Some time ago, Wal-Mart decided to combine the data from its loyalty card system with that from its point of sale systems. The former provided Wal-Mart with demographic data about its customers, the latter told it where, when and what those customers bought. Once combined, the data was mined extensively and many correlations appeared. Some of these were obvious; people who buy gin are also likely to buy tonic. They often also buy lemons. However, one correlation stood out like a sore thumb because it was so unexpected.<br>On Friday afternoons, young American males who buy diapers (nappies) also have a predisposition to buy beer. No one had predicted that result, so no one would ever have even asked the question in the first place.</blockquote><p>Unsupervised Learning could help to find such weird but practical correlations between things that do not make any sense to human. <br>It will help to see the world from another dimension.</p><h4>Semi-supervised Learning</h4><p>Semi-supervised Learning sits in-between Supervised and Unsupervised Learning. This method can be applied in a situation where only a part of the <em>dataset</em> is <em>labelled</em> and the rest is not <em>labelled</em>. How it works is that the <em>labelled</em> <em>dataset</em> is first trained on a <em>model</em> and then the trained <em>model</em> is used to predict the <em>un-labelled</em> data in the <em>dataset</em>. Now that the whole <em>dataset</em> is <em>labelled</em> it can follow the Supervised Learning technique from here onward. This method is called <em>Pseudo-Labeling</em> and is one of the techniques used to solve Semi-supervised Learning problems.</p><p>Now that you know what Machine Learning is wait for my next blog in which I will take you through an implementation of ML in “Layman’s Terms” 😉</p><p><strong>References:<br></strong><a href="https://www.theregister.co.uk/2006/08/15/beer_diapers/">https://www.theregister.co.uk/2006/08/15/beer_diapers/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b941b82a7833" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>