<?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 Aviraj Singh Ranawat on Medium]]></title>
        <description><![CDATA[Stories by Aviraj Singh Ranawat on Medium]]></description>
        <link>https://medium.com/@aviraj-ranawat-is?source=rss-1a81c25c2985------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*FZto4ZvA2OoPkf-F</url>
            <title>Stories by Aviraj Singh Ranawat on Medium</title>
            <link>https://medium.com/@aviraj-ranawat-is?source=rss-1a81c25c2985------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 15:52:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aviraj-ranawat-is/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[Logistic Regression]]></title>
            <link>https://aviraj-ranawat-is.medium.com/logistic-regression-9a22a3153e76?source=rss-1a81c25c2985------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a22a3153e76</guid>
            <dc:creator><![CDATA[Aviraj Singh Ranawat]]></dc:creator>
            <pubDate>Fri, 02 Oct 2020 13:34:42 GMT</pubDate>
            <atom:updated>2020-10-02T13:34:42.838Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*A7cFvNfKRSDPDPIajlY9Yw.jpeg" /></figure><p>So the before you move onto the complete details of understanding Logistic Regression and what we are dealing with here.</p><p>I would recommend you to go to the following link:</p><p><a href="https://medium.com/@aviraj.ranawat.is/how-to-perform-linear-regression-based-on-given-data-set-3e76f298a8ae">https://medium.com/@aviraj.ranawat.is/how-to-perform-linear-regression-based-on-given-data-set-3e76f298a8ae</a></p><p>Logistic regression is a supervised learning classification algorithm used to predict the probability of a target variable.</p><p>The nature of the target or dependent variable is forked into two, which means there would be only two possible classes.</p><p>To understand it in complete clarity, if you have a coin of whichever currency, it has a side we would call “Heads” and the other which we call “Tails”. So here as well, instead of heads or tails, we have 1s and 0s.</p><p>Logistic/Logistical Regression like Linear Regression(if you have refered the link above), has many applications, Facial Recognition, Object Identification, Identifying spam mails, and the example that we had dealt in the workshop that I had attended, we were learning about Handwriting recognition.</p><p>So hand writing recognition does sound very simple when you try to plot your solution in your mind. But there are some big deal of specifications that you would have to take care of first.</p><p>So firstly, we are supposed to have a very large data set of the set of the texts’ handwriting you would want to detect. So in the workshop we were basically learning how we can detect numbers between 1 to 4.</p><p>And for that we were informed that to make this data set they needed to keep many things in mind.</p><p>For doing image recognition, it isn’t really how they show in the movies.</p><p>In text/number recognition, we need to first make sure that our image is of a fixed dimension, a fixed matrix!</p><p>So we change the resolution in the paint application 28x28 wherein we are supposed to write the number between 1 to 4 and bring that into our Machine Learning model.</p><p>In the model there onwards we are basically splitting the entire 2-D array into every single bit, so the multiplication of 28 with itself, is 784.</p><p>We will have to bring in 784 different data samples, 784 different features to consider. And each feature would have two values white(255:255:255) and black(0:0:0). The numbers 255 and 0 stand for the RGB values as the code for both the colours respectively.</p><p>Now with our data set that has been made on paint and brought into the dataset is being refered using Logistic regression and through that we are able to predict which number it is with certainity.</p><p>Mathematically, a logistic regression model predicts P(Y=1) as a function of X. The logistic function returns the predicted decision. This is known as the sigmoid function.</p><p>Logistic function of z:</p><p>g(z) = 1/(1+e^-z) ; 0&lt;= g(z)&lt;=1</p><p>To implement Logistic Regression, once again we would have to follow the same steps as we has seen in the previous blog of mine, links to that is given above. So just to bring out the jist of that, we need to follow the given steps like how we had done for Linear Regression.</p><p>The steps are as follows:</p><ul><li>Data Preprocessing</li><li>Putting logistic regression formula into our model</li><li>Training our model</li><li>Finding out its training accuracy</li><li>Predicting the output based on input</li></ul><p>The implementation in practicality is given in the linear regression, with some lines of code which is definitely more fun to have a look at. In reference to that, this is quite similar!</p><p>Hope you’ve had fun!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a22a3153e76" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to perform Linear Regression based on given Data Set?]]></title>
            <link>https://aviraj-ranawat-is.medium.com/how-to-perform-linear-regression-based-on-given-data-set-3e76f298a8ae?source=rss-1a81c25c2985------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e76f298a8ae</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[workshop]]></category>
            <category><![CDATA[linear-regression]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Aviraj Singh Ranawat]]></dc:creator>
            <pubDate>Fri, 02 Oct 2020 11:00:55 GMT</pubDate>
            <atom:updated>2021-06-29T19:09:10.749Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to perform Linear Regression ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Npd77_nhXMQePxy_VsOGnQ.jpeg" /></figure><p>Hello everyone this is the very first blog of mine, and also the very first one in the field of Computer Science.</p><p>My name is Aviraj Singh Ranawat, I am a 3rd year student pursuing my B.Tech degree in SRM University. I have a keen interest towards Computer Science as a child but never really had the passion to get deeper into concepts.<br>So basically I had heard about Lema Labs, which to my knowledge is based in IIT(Indian Institute of Technology) Madras, Chennai, Tamil Nadu, India.</p><p>You can visit them here, if you want to explore your interests over there.<br><a href="https://www.lemalabs.com/">https://www.lemalabs.com/</a></p><p>So to understand how to perform Linear Regression we will have a look at this through a problem. And for that we have the data set of Chennai’s houses.</p><p>To understand the very base of Linear Regression we will perform linear Regression on one variable (Univariate Linear Regression). And then later move onto Linear Regression performed on multiple variables.</p><p>Linear regression is studied as a model for understanding the relationship between input and output numerical variables. And now using algorithms, can be used in the field of Machine Learning for prediction of house prices, company sales predictions, etc.</p><p>Before we understand more into Linear Regression, let us take a step back and understand how did we really achieve Linear Regression in the field of Machine Learning.</p><p>So, let us first understand what is artificial intelligence or moreover, how would you call a machine or software artificially intelligent?</p><p>Any machine that can apply logic, can evaluate different options and can make decisions on its own is considered to be artificially intelligent.</p><p>Machine Learning here is a branch of artificial intelligence, which takes decision based on given data. Machine Learning is rather understood by the following ideology: Performance on task improves based on previous data or experience.</p><p>Machine Learning here is of three types:</p><ul><li>Supervised Learning</li><li>Unsupervised Learning</li><li>Reinforced/Reinforcement Learning</li></ul><ol><li>Supervised Learning: It is like how we are being taught something.</li></ol><p>Let’s say if we are a (Machine Learning)model, and our problem is with learning alphabets, you are taught by an external source, i.e., a teacher.</p><p>Similarly in Supervised learning, with the given data, the machine learning model is being told what to do and based on that the machine learning model trains itself in every iteration.</p><p>2. Unsupervised Learning: It is like how we are given something to understand.</p><p>Let us consider once again that we are a (Machine Learning)model. But this time we aren’t taught by any sort of external source, and we are still given the data.</p><p>A simple example is solving a jigsaw puzzle, we wouldn’t know the output really, but we combine each piece with some similarity and pattern recognition and solve the entire puzzle.</p><p>Similarly in in unsupervised learning, we understand the data based on similarity, what fits our model, it fits. Its excluded otherwise.</p><p>3. Reinforcement Learning: We are left independent to learn.</p><p>With the same scenario, but with an even larger twist, we are neither told what the problem is and we are neither told how we are to achieve the solution, even surprising given any sort of guidance.</p><p>So its a lot like playing cricket or football, for shooting the goal, we need to figure out by ourselves with how much strength is needed to be given, where exactly we are supposed to put the impact on the ball in order to score a goal.</p><p>Now we have our Supervised learning, it has two methods of its own, namely:</p><ul><li>Regression</li><li>Classification</li></ul><p>Now we have already defined what linear regression is.</p><p>The output varies based on continuous values, like the acceleration/reverse acceleration of a car.</p><p>Now Linear Regression is looks quite simple but there is some huge amount of calculations that we have to perform on our data set to actually get our model to give predictions.</p><p>So to perform Linear Regression we are using Google Colaboratory, if you want you can always use your basic python, but you will of course have to make sure that you have the required libraries installed for that.</p><p>The required libraries are as follows:</p><ul><li>Numpy</li><li>Pandas</li><li>Matplotlib, we will be using the pyplot, sub-library.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*8s1E5V31rn9KQYP2_w2hCA.jpeg" /><figcaption>This is how we mount the google drive into the google colaboratory and assign the entire data set to a variable</figcaption></figure><p>After that’s done, we will apply a scatter plot graph on our data set just to observe relationships between variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*h4f3FALTP6Qo0cHUHQxMYQ.jpeg" /></figure><p>Now here we notice that our data varies in huge amounts, so we would like to get in a more smaller scale.</p><p>Here we are entering into the concept of data preprocessing.</p><p>Just like in the food that we eat, we break the food down into small(scaleable) pieces for it to go through our food pipe so that our stomach can process the food(data).</p><p>Data preprocessing is the changes that you make in the data before giving it to the machine learning algorithm. A few particular tasks that are done are:</p><ul><li>Making all the data similar in scale</li><li>Separating the inputs and outputs from raw data</li><li>Filling up blank/Null data</li><li>Dropping unnecessary features</li></ul><p>So in our problem now we are only have the size of the house and the prices of the houses. So we are going to perform feature scaling on this dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*BUej_gvGRK7BffA9V9JAMg.jpeg" /><figcaption>If you apply data.head() before the above statements you will have some decimal/integer values</figcaption></figure><p>The formula that you see above that we have used for data preprocessing is shown as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*qHJrPt5F0jbL0yhbgEH4_g.jpeg" /></figure><p>Now when you do the scatter plot of the raw data, then you will notice that the scale has reduced to between -1 to 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*9-7bkrR-gQKEiGsGXRHxgQ.jpeg" /><figcaption>Notice the scale of the scatter plot</figcaption></figure><p>The next step after scaling our data is to analyse the shape of our data set, to perform operations on our data set, we cannot really consider working on the Worksheet that we have, in the coding interface we would have to take it in the form of a two-dimensional array, also called a Matrix, in mathematics.</p><p>Before we move more further into coding, we need to clear our base much more, with Theory.</p><p>So we are dealing with Linear Regression. We will also be dealing with linear equations.</p><p>The equation of the line is:<br>f (x)= y = (θ0)+ (θ1)x</p><p>In the above equation θ0 and θ1 are the parameters. X is the Input. Y is the Output. f(x) is the model that maps X to Y.</p><p>So f(x)-y would give us the error, but that would be for one data value from our data set.</p><p>Total Error is sum of all squared errors (to avoid negative numbers)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*56gVBMZ9p1xau2xOpyXmhQ.jpeg" /></figure><p>You might notice why we have divided it with 2m…</p><p>That is only to reduce the amount of computations, and “m” is the total number of data samples.</p><p>Now we will separate our Input and Output from the 2-dimensional array that we had made.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*JkYm1imN1unLsz1h6J4DsQ.jpeg" /></figure><p>So here we have taken x and y as input and output respectively. We are using the .iloc function to copy the respective columns of data in order to separate the data. Here you have to be very careful as to which data you are splitting.</p><p>Then we are putting them into the matrices x and y respectively as to work on them separately.</p><p>Calculating and minimizing the error is the most crucial part of machine learning. The difference between predicted and actual result is known as error as we had seen earlier. Gradient descent algorithm is an example of minimizing the error. When the gradient becomes zero, we have reached the minimum error.</p><p>We minimize the error by optimizing the parameters. Two parameters theta1 and theta2 should be updated simultaneously.</p><p>Temp0=𝜃0−𝑐 * 𝜕𝐽(𝜃0,𝜃1)/𝜕𝜃0</p><p>Temp1=𝜃1−𝑐 * 𝜕𝐽(𝜃0,𝜃1)/𝜕𝜃1</p><p>θ0=Temp0</p><p>θ1=Temp1</p><p>[𝜃0,𝜃1 are parameters, 𝐽(𝜃0,𝜃1) is the cost function and 𝜕𝐽(𝜃0,𝜃1) is the partial derivative of the cost function with respect to 𝜃1 and 𝜃0 ]</p><p>After minimize the error we will get the finest parameters and predict based on that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*LwVwuAnNMKp7WyeXYxH5Lw.jpeg" /></figure><p>So here we have done a function called computeError() with the input and output matrices. And as we mentioned about gradient Descent before.</p><p>Gradient Descent will help our model get trained based on the iterations and the learning rate we set for it. In certain cases even if you increase the learning rate to more that 5000, our result would make little to no difference cause technically it cannot get any more precise, and that solely depends on the dataset that we have.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*cBCFUUQ_TbqInS--uO3ArQ.jpeg" /></figure><p>So here we notice that with the iterations of 2500 that we had done was more than enough for this as we can see in the bottom right that the curve as flattened already. So having our model to do 10000 iterations would practically be only counter productive use of your computing resources and would definitely take more of our time for our model to get trained and we would still have the same results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*qGI8Ny_AoGLd_2F8ThcdBg.jpeg" /></figure><p>So the first bunch of code that you are having a look at is the training accuracy and the error of our Machine Learning model. We can see that the accuracy of our model is 99.06% which is honestly very good.</p><p>I have heard this from a faculty who taught me in my college that your Model is mostly always accepted if it is somewhere above 95% at least, anywhere below that is unnacceptable.</p><p>The next function that we have is our predict function which based on the input from the user, i.e., the size of the house will give us the predicted price of the house as output with some amount which can vary (more or less).</p><p>So now we have had a look at the multivariate Linear Regression or Linear Regression performed on multiple variables.</p><p>Now there is honestly nothing much to panic about in this one, because it is relatively simple. And there are a few things that you should keep in mind when you are dealing with multiple variables.</p><ol><li>Make sure that you are selecting the correct input and output variables and the correct data set that you will be putting into account in the model</li><li>Making sure that the sizes of the Matrices that you are using have the correct shape or the mathematically correct number of rows and columns for multiplication.</li><li>Making sure that you apply enough number of iterations so that you use less amount of your computer resources and save more time.</li></ol><p>So compared to our univariate problem here we will be dealing with many more variables, as I mentioned. The variables are as such, Area Code, Distance from the main road, number of bedrooms, number of bathrooms, etc.</p><p>We are doing pretty much the same things as our univariate problem. I will show a few snippets of that right now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FDvn5rDgTq_UTQYG3pQz3g.jpeg" /><figcaption>The first 5 data samples of the data set</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*DNje0XQwX3SW7bYCPAN-ig.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XssS4Y7m2FaW8fNokBaF2w.jpeg" /></figure><p>You will notice that we have taken out the SALES_PRICE column from here and set that into our output variable Y.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/206/1*usJYIig8AlVUMCYq-lDtiA.jpeg" /></figure><p>Also, if you might not have noticed, do not forget to perform feature scaling on them .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*mAvZY06Ppi8al7qhP98F5g.jpeg" /></figure><p>Here is a scatter plot between the size of the house and price of the house just to get some understanding how much our dataset varies and is not simply linear like our previous univariate situation. And even with such variance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*y4NeL3LJKhEQOxYMg6ix-w.jpeg" /></figure><p>I managed to get 95.06% accuracy with only 10000 iterations and having our learning rate set as 1.</p><p>I had impemented many various combinations of learning rate and iterations so as to find the best accuracy, but the maximum I was able to get was this based on our dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3sXx6-5bq7s6shVxc_IKCA.jpeg" /></figure><p>Here the first block of is basically taking the inputs for every other variable so that we can scale them and put it into our model as input so as to get a predicted output. Instead of taking individual inputs, we can take all the inputs into an array.</p><p>The second block of code mentioned here is to take the transpose of te input because our output matrix is in horizontal and mathematically, through the rules of matrix multiplitcation, we won’t be able to multiply them.</p><p>The third block of code is simple but very essential because we need to make sure that whatever is our input values, it has to also detect and compare with the columns of our dataset.</p><p>The fourth block of code was just to show how our input given looks like, before any sort of preprocessing and other steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*elvF_wx6q2aawhWl2h6pPA.jpeg" /><figcaption>The given input after preprocessing for our ML model</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*6vuotARbUGwN4Cd-iPmHaw.jpeg" /></figure><p>So the first block of code is just to take out our input data and below that is the expected output that our model should be able to achieve.</p><p>The second block of code is getting the predicted price based on the input.</p><p>The third block of code is showing us the the price range, like how in our Univariate Linear Regression we had some amount that you can add or subtract in order to be more closer to our real data, or the expected output. We are putting that value into the variable ra to say price range.</p><p>The fourth and the last block of code is to show that the predicted value added with our price range value is 88 lakhs,35k where as the comment line shows 87 lakhs, 74k… So we notice that there is a difference of 1 lakh and 29k.</p><p>And these sort of differences will be there, and there is nothing to be ashamed or to be felt bad about it. As life is full of learning and imporving yourself, exactly like Machine Learning. Nothing would be perfect, but getting closer to perfection is the effort we need to strive for.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e76f298a8ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>