<?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 Meharaj Ul Mahmmud on Medium]]></title>
        <description><![CDATA[Stories by Meharaj Ul Mahmmud on Medium]]></description>
        <link>https://medium.com/@meheraj?source=rss-6b011a65d0bf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*BLBt8U3kHecO20Gs</url>
            <title>Stories by Meharaj Ul Mahmmud on Medium</title>
            <link>https://medium.com/@meheraj?source=rss-6b011a65d0bf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 22:22:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@meheraj/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[Exploring the Levenshtein Distance Algorithm: A Comprehensive Guide]]></title>
            <link>https://meheraj.medium.com/exploring-the-levenshtein-distance-algorithm-a-comprehensive-guide-34ecfdaefbd4?source=rss-6b011a65d0bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/34ecfdaefbd4</guid>
            <category><![CDATA[levenshtein-distance]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Meharaj Ul Mahmmud]]></dc:creator>
            <pubDate>Thu, 16 Nov 2023 13:44:16 GMT</pubDate>
            <atom:updated>2023-11-16T13:44:16.062Z</atom:updated>
            <content:encoded><![CDATA[<h3>Exploring the Levenshtein Distance Algorithm</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I2ldwafEKR6fUdaHb_uBkg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@markusspiske?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Markus Spiske</a> on <a href="https://unsplash.com/photos/a-car-parked-on-the-side-of-the-road-DOVt26lm_XM?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Unsplash</a></figcaption></figure><p>The field of computer science and algorithmic analysis is rich with various techniques to solve a multitude of problems. One such fundamental algorithm that plays a crucial role in fields like natural language processing, spell checking, and DNA sequencing is the Levenshtein distance algorithm. In this comprehensive guide, we will delve into the intricacies of the Levenshtein distance algorithm, covering its concept, applications, and a step-by-step implementation in Python with illustrative examples.</p><h3>Understanding Levenshtein Distance</h3><h4>What is Levenshtein Distance?</h4><p>The Levenshtein distance, also known as the edit distance, measures the minimum number of single-character edits required to transform one string into another. These edits can be insertions, deletions, or substitutions.</p><h4>Applications of Levenshtein Distance:</h4><ol><li><strong>Spell Checking:</strong> Levenshtein distance is widely used in spell checkers to suggest corrections for misspelled words.</li><li><strong>DNA Sequencing:</strong> It helps in comparing DNA sequences, identifying genetic similarities, and understanding evolutionary relationships.</li><li><strong>Natural Language Processing (NLP):</strong> Used in applications like fuzzy string matching, autocorrection, and text similarity analysis.</li></ol><h3>Theoretical Overview</h3><h4>Mathematical Representation</h4><p>Let’s denote two strings, A and B, with lengths m and n, respectively. The Levenshtein distance between the two strings, denoted as D(A, B), is calculated using dynamic programming.</p><p>0 &amp; \text{if } i = 0 \text{ or } j = 0 \\ D(i-1, j-1) &amp; \text{if } A[i] = B[j] \\ \min(D(i-1, j), D(i, j-1), D(i-1, j-1)) + 1 &amp; \text{otherwise} \end{cases}</p><h3>Step-by-Step Implementation in Python</h3><pre>def levenshtein_distance(str1, str2):<br>    m, n = len(str1), len(str2)<br>    <br>    # Initialize a matrix to store distances<br>    dp = [[0] * (n + 1) for _ in range(m + 1)]<br>    <br>    # Fill the matrix with base cases<br>    for i in range(m + 1):<br>        for j in range(n + 1):<br>            if i == 0:<br>                dp[i][j] = j<br>            elif j == 0:<br>                dp[i][j] = i<br>            elif str1[i - 1] == str2[j - 1]:<br>                dp[i][j] = dp[i - 1][j - 1]<br>            else:<br>                dp[i][j] = 1 + min(dp[i - 1][j],      # Deletion<br>                                  dp[i][j - 1],      # Insertion<br>                                  dp[i - 1][j - 1])  # Substitution<br>    <br>    return dp[m][n]</pre><pre># Example Usage<br>str1 = &quot;kitten&quot;<br>str2 = &quot;sitting&quot;<br>distance = levenshtein_distance(str1, str2)<br>print(f&quot;Levenshtein Distance between &#39;{str1}&#39; and &#39;{str2}&#39;: {distance}&quot;)</pre><h3>Examples and Performance</h3><h4>Example 1</h4><ul><li>String 1: “kitten”</li><li>String 2: “sitting”</li><li>Levenshtein Distance: 3</li></ul><h4>Example 2</h4><ul><li>String 1: “algorithm”</li><li>String 2: “altruistic”</li><li>Levenshtein Distance: 7</li></ul><p>The Levenshtein distance algorithm provides a powerful tool for measuring the similarity between strings. Its versatility makes it applicable in various domains, from spell checking to DNA analysis. By understanding its theoretical foundations and implementing it step by step in Python, we have equipped ourselves with a valuable algorithm that can be a cornerstone in various applications. As technology continues to advance, the significance of such fundamental algorithms remains paramount in solving real-world problems.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34ecfdaefbd4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Subtle Intro to Big Data]]></title>
            <link>https://meheraj.medium.com/a-subtle-intro-to-big-data-2628dfaa4448?source=rss-6b011a65d0bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/2628dfaa4448</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[big-data]]></category>
            <dc:creator><![CDATA[Meharaj Ul Mahmmud]]></dc:creator>
            <pubDate>Wed, 07 Jun 2023 05:27:13 GMT</pubDate>
            <atom:updated>2023-06-07T05:27:13.876Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gwh4ElgPDfTIF0AfGxrdxQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@franki?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Franki Chamaki</a> on <a href="https://unsplash.com/s/photos/big-data-analytics?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>We are producing a massive amount of data every day whether we know about it or not. Our every activity on the internet, every click of our mouse, every sensor in our mobile phone is generating data, and that’s about 2.5 Quintillion bytes of data every day.</p><p>This data comes from everywhere: sensors used to gather climate information, posts to social media sites, digital pictures and videos, purchase transaction records, and cell phone GPS signals to name a few.</p><p>So, what to do with all these data? Well, the platform where we are generating the data can use the data to get insights about their product, their service, and last but not least their business models. A platform could be a social media site, an eCommerce site, our mobile phones, and many others. Business leaders are appointing Data scientists for gathering the insights from these data and improving their business model.</p><p>It is believed that actual structured data is only 5% of the total data and therefore you need better ways to analyze the remaining 95%. Traditional database analysis or searching standard texts does not help complete the overall analysis.</p><h3>Big Data</h3><p>The real problem occurs when there is a massive amount of data at hand, and our usual data analysis tools and processes fail to analyze those data. This is where Big Data Analytics comes in.</p><p>Big Data is a collection of data that is huge in volume, yet growing exponentially. One big data example would be the data generated by a Jet Engine. A single Jet Engine generates more than 10 Terabytes (TB) of data in 30 minutes of flight time. A single flight from London, UK to New York, USA takes around 8 hours of flight time. So, there you go with the calculation.</p><p>Another example could be the data generated by Social-Media sites. Statistics show that more than 500 Terabytes (TB) of data is being generated by the users every day and those include photos, videos, text messages, comments, etc. I hope you got the gist.</p><h3>Big Data Challenges</h3><p>There a few challenges in managing, analyzing, and processing these huge amount of data. First of all these data is not structured and what I mean by being structured is you have a fixed format to access, store, and process the data. In case of big data, mostly there is no fixed format.</p><p>Then there is limitation of processing power. At the rate data is being generated, half of the the business leaders do not have the proper resources to gather insights of majority of their users’ data. Therefore, the percentage of data the business can process is going down.</p><h3>Characteristics of Big Data</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*5alCgwLcEOedRp1mRrarzQ.jpeg" /><figcaption>Three V’s of Big Data (old model)</figcaption></figure><h4>Volume</h4><p>Big Data is all about <strong>Volume</strong>. Volumes of data that can reach unprecedented heights in the face. It was estimated that there will be 40 Zettabytes of data created by 2020 but the actual amount was around 60 Zettabytes [1 Zettabyte = 1 Billion Terabytes]. So, it is not uncommon for large companies to have Petabytes of data in storage. And it helps in shaping the future of a company.</p><p>But most of the companies do not have the resources to analyze all the data they are acquiring. They are getting a lot of data for sure, but they have the resources to process a certain amount of data. A big amount of data is unutilized, and companies cannot have any insights from those data. Those data are said to be in the <strong>BLIND ZONE</strong>.</p><p><strong>Velocity</strong></p><p>Velocity denotes the growth of data or the rate of data creation. Velocity essentially measures how fast the data is coming in, being stored, and its associated retrieval rate. In these days, data comes in form of streams, and they have to be processed in near real time to identify a pattern or a problem. Such as Sensor data. In case of a heat sensor in a fire alarm, it is continuously gathering data about the temperature in a room, it is detecting a pattern over and over. If the pattern breaks and the temperature goes really high then the sensor detects a fire. So, the data generation is continuous, data storing is continuous, and the processing of data is also continuous.</p><p><strong>Variety</strong></p><p>As we talked about before there are a few types of data, besides the traditional Structured data, such as Semi-Structured, Quasi-Structured, and Un-Structured data.</p><p>We get the structured data in a fixed format, but in the case of unstructured data, we do not have a fixed format. Text messages, Image files, video files, MP3 files are some of the examples of unstructured data. The satellites images, sensor data, website contents, etc. are also unstructured data.<br>Semi-structured data is in between Structured and Unstructured data. Semi-structured data doesn’t reside in a relational database but does have some organizational properties that make it easier to analyze. With some processes, we can store them in relation database, but the semi-structure exists to ease space, clarity, or compute.</p><p>XML and JSON documents are semi-structured documents, as well as NoSQL databases are considered semi-structured.</p><p>Quasi-structured data is more of textual data with erratic data formats. It can be formatted with effort, tools, and time. This data type includes web clickstream data such as Google searches. Other examples are pasted texts which yield a network map based on similarity of language within the text, as well as the proximity of words to each other within the text.</p><h4>Though the three V’s are the most widely accepted core of attributes, there are several extensions that can be considered.</h4><h3>Another V… Veracity</h3><p>Data veracity, in general, indicates how accurate or trustworthy a data set may be. More specifically, when it comes to the accuracy of big data, it’s not just the quality of the data itself but how authentic the data source, type, and processing of it is.</p><p>If we think about a network traffic which is a data stream of course, it has thousands of nodes flowing, all these nodes might not be authentic. There could be a lot of malicious data, and nodes. And we do not want to increase our data size with unwanted malicious data. So data authenticity is important.</p><h3>… and More V’s (Six V’s of Big Data)</h3><h4>Value</h4><p>Data value is often quantified as the potential social or economic value that the data might create. However, the whole concept is weakly defined since without proper intention or application, high valuable data might sit at your warehouse without any value. This is often the case when the actors producing the data are not necessarily capable of putting it into value.</p><h4>Variability</h4><p>This refers to the inconsistency which can be shown by the data at times, thus hampering the process of being able to handle and manage the data effectively. The data could vary from time to time as out business is changing. Therefore, we will need to change our model to process the new kind of data. So, our big data analytical process and machine learning algorithms should be able to keep up with the data variability.</p><h3>Applications in the Real World</h3><p>Big Data has greatly enhanced decision-making processes for organizations by providing a wealth of data to test hypotheses and address problems more effectively. Risk management and decision-making are crucial areas that have benefited significantly from the availability of vast data sets.</p><p>The impact of Big Data on customer experience is profound. Companies now have access to an unprecedented amount of customer data, allowing them to offer personalized recommendations and tailored offers. Customers willingly provide this data in exchange for the personalized services they receive. The personalized recommendations we see on platforms like Netflix, Amazon, and Flipkart are a direct result of leveraging Big Data.</p><p>Machine Learning has also experienced significant advancements due to the rise of Big Data. With larger datasets available for training ML models, performance improvements are observed. Additionally, Machine Learning enables the automation of tasks that were previously manual, thanks to the insights derived from Big Data.</p><p>Demand forecasting has become more precise as companies gather more data on customer purchases. This enables them to build accurate forecasting models, facilitating production scalability and reducing costs associated with storing unsold inventory in warehouses.</p><p>In addition, Big Data finds extensive applications in areas such as product development and fraud detection, further showcasing its versatile uses and benefits.</p><h3>EndNote</h3><p>In this article, we discussed what we mean by Big Data, the characteristics and types of Big Data, and some real-world applications of Big Data.</p><p>Thank you for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2628dfaa4448" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Brief Introduction to Python Virtual Environment]]></title>
            <link>https://meheraj.medium.com/brief-introduction-to-python-virtual-environment-a3b616991f79?source=rss-6b011a65d0bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3b616991f79</guid>
            <category><![CDATA[virtual-environment]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Meharaj Ul Mahmmud]]></dc:creator>
            <pubDate>Fri, 05 May 2023 06:37:53 GMT</pubDate>
            <atom:updated>2023-05-05T06:37:53.765Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MJDZA5bN-vtEHm9_xP5l_A.jpeg" /></figure><p>You may have heard the term “virtual environment” before, but what exactly is it?<br>Virtual environments are a way of isolating projects from each other. This means that you can install and run different versions of Python on your computer without affecting any other projects you’re working on. It also makes it easier to share code between different projects — you don’t have to worry about accidentally bringing in dependencies from one project into another because they’re installed in separate places!<br>In this post I’ll explain why virtual environments are useful for Django development, and how you can use them with Docker Compose to create a fully-functional test server environment for your next project.</p><h3>What is a Python Virtual Environment?</h3><p>A virtual environment is a way of creating an isolated working environment for your Python projects. It allows you to install and use libraries that are specific to your project, without affecting other projects or the global site-packages directory.<br>Virtual environments allow you to create separate copies of Python packages (libraries), which can then be used by different projects on your computer without conflicting with each other. This means that if one project needs version 1.0 of a library while another needs 2.0, they can both use their own versions without affecting each other’s functionality or causing errors when running commands such as pip install .</p><h3>Why Use Virtual Environments in Django Development?</h3><p>Virtual environments are a great way to manage dependencies in large Python projects. Large projects often have many different dependencies, which can make it difficult to install and update packages. This can cause problems if you’re working on multiple projects with different requirements, or if one project relies on an older version of a library that conflicts with another project’s newer version.<br>Virtual environments allow you to keep separate copies of your libraries and their dependencies installed on your machine without conflicting with each other. They also allow you to easily switch between different versions of libraries as needed.</p><h3>Steps to Create and Activate a Virtual Environment</h3><h4>Creating a virtual environment</h4><p>Creating a virtual environment is a simple process that can be done using the venv module that comes with Python. To create a virtual environment, open a terminal or command prompt and navigate to the directory where you want to create the environment. Then, run the following command:</p><p>python -m venv myenv</p><p>This will create a new directory called myenv in the current directory, which contains a Python installation and a `pip` executable that can be used to install packages.</p><h4>Activating a virtual environment</h4><p>Once the virtual environment has been created, it needs to be activated before it can be used. To activate a virtual environment, navigate to the directory where the environment was created and run the appropriate activation command for your operating system:</p><blockquote>On Windows:</blockquote><p>myenv\Scripts\activate</p><blockquote>On macOS or Linux:</blockquote><p>source myenv/bin/activate</p><p>Once the virtual environment is activated, any packages installed using pip will be installed in the virtual environment, rather than in the global Python environment.</p><h3>Best Practices for Using Virtual Environments in Django Development</h3><p>When you’re ready to get started with Django development, it’s important to understand how virtual environments work. The following best practices will help you create and manage your own virtual environments:</p><ul><li>Use a separate virtual environment for each project. This is the most important step in ensuring that your projects are isolated from each other, so that they don’t conflict with one another or share dependencies with other projects on your computer.</li><li>Create an activate script for each new project that automatically activates its associated virtual environment when run. This ensures that every time you open up the command line within this directory, it loads all of its requirements into memory without any additional steps required on your part (other than running this script).</li><li>Use a requirements.txt file to document the dependencies for your project. This file can be used to recreate the virtual environment on another system or to share the dependencies with other developers.</li><li>Don’t commit the virtual environment to version control: Do not commit the virtual environment to version control. Instead, commit the requirements.txt file, which can be used to recreate the virtual environment.</li><li>Update dependencies regularly: Regularly update the dependencies in your virtual environment to ensure that you are using the latest versions and any security vulnerabilities are patched.</li><li>Delete old virtual environments: Once a project is complete, delete the virtual environment to free up space on your system.</li></ul><p>In this post, we covered the basics of virtual environments and how they can be used in Django development. We also looked at some of the more advanced features of virtual environments and how they can help you manage your project’s dependencies.<br>If you’re interested in learning more about Python virtual environments or Django development, here are some resources that I recommend:</p><ul><li><a href="https://www.digitalocean.com/community/tutorials/how-to-use-virtualenvs">Python Virtual Environments: An Introduction</a> — A great introduction to using Python virtual environments by DigitalOcean</li><li><a href="https://github.com/treyhunner/the_hitchhikers_guide_to_python">The Hitchhiker’s Guide To Python</a> — A book written by Trey Hunner (who also maintains pipenv) that covers everything from installing Python 3 all the way up through deploying web applications with Docker containers</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3b616991f79" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linear Regression Raw Python Implementation]]></title>
            <link>https://meheraj.medium.com/linear-regression-raw-python-implementation-d797f5e3508d?source=rss-6b011a65d0bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/d797f5e3508d</guid>
            <category><![CDATA[univariate-analysis]]></category>
            <category><![CDATA[linear-regression]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Meharaj Ul Mahmmud]]></dc:creator>
            <pubDate>Thu, 13 May 2021 07:54:30 GMT</pubDate>
            <atom:updated>2021-05-13T07:54:30.033Z</atom:updated>
            <content:encoded><![CDATA[<p>Raw Python Implementation of Simple Linear Regression (Univariate).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/0*Fq10R4VbL4c8BLl8.png" /></figure><p>This blog is not about teaching Linear Regression or talking about how it works. This blog is simply about implementing the Linear Regression in Raw Python without using any library function (except a few cases).</p><p>There are few steps we have to follow to reach our goal, which are,</p><ol><li>Read the dataset</li><li>Split into train and test dataset</li><li>Fit the model</li><li>Predict for the test dataset</li><li>Plot training and testing results</li><li>Model Evaluation</li></ol><p>We will be using library functions for the <strong>first, second, </strong>and<strong> fifth</strong> steps.</p><h3>Reading the dataset</h3><p>In this step, we will read the dataset, and split the columns into the dependent and independent variables.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40147610a6eb07622f68aec7dd1b37a6/href">https://medium.com/media/40147610a6eb07622f68aec7dd1b37a6/href</a></iframe><p><em>The dataset could be found here. </em><a href="https://www.kaggle.com/rohankayan/years-of-experience-and-salary-dataset"><em>https://www.kaggle.com/rohankayan/years-of-experience-and-salary-dataset</em></a></p><h3>Splitting into train and test dataset</h3><p>This part is pretty straightforward. We will use Scikit-learn’s<strong> train_test_split</strong> function for this part.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56459ffc5c7394e993318aa8f2d080e1/href">https://medium.com/media/56459ffc5c7394e993318aa8f2d080e1/href</a></iframe><h3>Model fitting</h3><p>This is the most important part of any regression analysis. We will fit our model using the training dataset.</p><p>This is the function we need to <strong>fit our model.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8083809ba27ae17b00fbf3a1793fadbf/href">https://medium.com/media/8083809ba27ae17b00fbf3a1793fadbf/href</a></iframe><p>We need a few more additional functions to calculate the slope and y-intercept as we are not using (mostly) any library or built-in functions.</p><p>The following function is to calculate the <strong>slope</strong> of the predicted line.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ee3724ff8284f6f4ad352f32ea2b28f/href">https://medium.com/media/4ee3724ff8284f6f4ad352f32ea2b28f/href</a></iframe><p>To calculate the <strong>slope</strong> we need to find the <strong>covariance</strong> of both of the variables, independent, and dependent and the <strong>variance</strong> of the independent variable.</p><p>The following functions are for calculating the <strong>covariance</strong>, and the<strong> variance.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c2ee10002b46bed67582557b0cd862d/href">https://medium.com/media/5c2ee10002b46bed67582557b0cd862d/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9eda7f2bddc7fce3852294131dd61de5/href">https://medium.com/media/9eda7f2bddc7fce3852294131dd61de5/href</a></iframe><p>This function below is for calculating the <strong>y-intercept</strong> of the predicted line.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0c539074b82d2ca99392767f61f8278/href">https://medium.com/media/d0c539074b82d2ca99392767f61f8278/href</a></iframe><p>For this, we need to calculate the mean, and for the mean, we of course need to calculate the sum. The following functions will do the work.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81f31470317523ea9cdd2f724c8687be/href">https://medium.com/media/81f31470317523ea9cdd2f724c8687be/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad0fa33a5c6343c17e7c40d35f11a8dc/href">https://medium.com/media/ad0fa33a5c6343c17e7c40d35f11a8dc/href</a></iframe><h3>Predicting for the test dataset</h3><p>This is the part where we will make predictions for our test dataset. We will first calculate the <strong>slope</strong> and the <strong>y-intercept</strong>, then find the predictions for the test dataset using the formula of a straight line.</p><blockquote>The formula of straignt line, y = a + bx</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8071dd11c1bcfca9bef13478d07f120b/href">https://medium.com/media/8071dd11c1bcfca9bef13478d07f120b/href</a></iframe><p>We are mostly finished as we have trained our model using the training dataset, and made predictions using the testing dataset. In this part, we will plot the training and testing data points. We will use <em>matplotlib</em> for the plotting.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f65390e923b8effb38d92a25afdf65f/href">https://medium.com/media/1f65390e923b8effb38d92a25afdf65f/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*QQXtu-yFF5mf5pcPzG7Hfw.png" /><figcaption>Scatter Plot (Training Dataset)</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/050137d0b519f3c52b9985c1f285045c/href">https://medium.com/media/050137d0b519f3c52b9985c1f285045c/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*CcXrgVN9tRXt-FN2giQnRg.png" /><figcaption>Scatter Plot (Testing Dataset)</figcaption></figure><h3>Model Evaluation</h3><p>Now the only part remaining is the M<strong>odel Evaluation</strong>. We will use three matrices to evaluate the model, <strong>MAE (Mean Absolute Error)</strong>, <strong>MSE (Mean Squared Error)</strong>, and <strong>R-Squared score</strong>.</p><p><strong>MAE</strong> and <strong>MSE</strong> are the two most commonly used regression loss functions. <strong>MAE</strong> is the sum of absolute differences between our target and predicted variables. <strong>MSE</strong> is the sum of squared distances between our target variable and predicted values. Both of the measures range from 0 to ∞.</p><p><strong>R-Squared</strong>, also known as the Coefficient of Determination, is a value between 0 and 1 that measures how well our regression line fits our data. The closer <strong>R-Squared</strong> is to 1 or 100% the better our model will be at predicting our dependent variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*epuUUhyFCr08Tis7.png" /><figcaption>R-Square Formula</figcaption></figure><blockquote>The numerator of the formula, is the Residual sum of squared errors (SSres).</blockquote><blockquote>The denominator of the formula is the Total sum of squared errors (SStot).</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c7ad2aa58e733294073050ef61bbf79/href">https://medium.com/media/6c7ad2aa58e733294073050ef61bbf79/href</a></iframe><p>And those are the formulas we need. To sum it all,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a419adad06cff7b0e5dc07cb8d6bbe7/href">https://medium.com/media/6a419adad06cff7b0e5dc07cb8d6bbe7/href</a></iframe><p>And that’s all you need to implement Simple Linear Regression using raw Python.</p><p>Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d797f5e3508d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basics of Linear Algebra]]></title>
            <link>https://meheraj.medium.com/basics-of-linear-algebra-4ef0570a8313?source=rss-6b011a65d0bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ef0570a8313</guid>
            <category><![CDATA[linear-algebra]]></category>
            <category><![CDATA[matrix]]></category>
            <category><![CDATA[python-scripts]]></category>
            <dc:creator><![CDATA[Meharaj Ul Mahmmud]]></dc:creator>
            <pubDate>Sun, 02 May 2021 15:22:16 GMT</pubDate>
            <atom:updated>2021-05-02T15:22:16.294Z</atom:updated>
            <content:encoded><![CDATA[<p>Linear Algebra Operations Using Raw Python.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yeFM73ybaKRt8ttHU2tW8w.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@antoine1003?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Antoine Dautry</a> on <a href="https://unsplash.com/collections/10527967/algebra?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Being a Data Science major, I have been comprehending Linear Algebra and Matrix Operations for a long time. This whole time, I have been using the most popular Numpy library. Linear Algebra is one of the most important topics in Data Science. In this post, I will try to implement some of the basic Numpy Linear Algebra functions using raw Python code.</p><p>These basic operations are at the root of every machine learning and deep learning model. Therefore we should have a clear concept of these functions.</p><h4>Zeros Matrix</h4><p>This function will return us a matrix with all the ZEROs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/688589b1f82f51548e7de335eaa1a3e2/href">https://medium.com/media/688589b1f82f51548e7de335eaa1a3e2/href</a></iframe><h4>Ones Matrix</h4><p>This function will return us a matrix with only ONEs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2fa018c41c4d598bf090bba088ed598c/href">https://medium.com/media/2fa018c41c4d598bf090bba088ed598c/href</a></iframe><h4>Identity Matrix</h4><p>This will give us a <strong>n by n</strong> square matrix with ones in the main diagonal and zeros everywhere else.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2ac33225212d908460d9306256cd09e/href">https://medium.com/media/a2ac33225212d908460d9306256cd09e/href</a></iframe><h4>Matrix Addition</h4><p>This function will return us the addition of two matrices. <strong>Matrix addition</strong> is the operation of adding two <strong>matrices</strong> by adding the corresponding entries together.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f8a553be2a62862634538f0ae57be51/href">https://medium.com/media/1f8a553be2a62862634538f0ae57be51/href</a></iframe><h4>Matrix Subtraction</h4><p>This function will subtract the second matrix from the first one. Subtraction of matrix is possible by subtracting the element of another matrix if they have the same order.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b551738194e4056c2ce6039e461a9c9a/href">https://medium.com/media/b551738194e4056c2ce6039e461a9c9a/href</a></iframe><h4>Matrix Multiplication</h4><p>This matrix will multiply a 2D matrix by a 2D matrix.</p><p><strong>There are a few things to keep in mind.</strong></p><ol><li>Order matters now. AB != BA.</li><li>Matrices can be multiplied if the number of columns in the 1st equals the number of rows in the 2nd.</li><li>Multiplication is the dot product of rows and columns. Rows of the 1st matrix with columns of the 2nd.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M0BvslLtpVbDAab_DuVqkg.png" /><figcaption>Matrix Multiplication</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/63524783d72509bb08dc34430695c6f9/href">https://medium.com/media/63524783d72509bb08dc34430695c6f9/href</a></iframe><h4>Matrix Transpose</h4><p>This will transpose a given matrix. The <em>transpose</em> of a matrix is simply a flipped version of the original matrix. We can transpose a matrix by switching its rows with its columns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*gfAHdnfz-IQUwzI1_AxSVg.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/abfa32ac544009bbebe0d0811ca2a088/href">https://medium.com/media/abfa32ac544009bbebe0d0811ca2a088/href</a></iframe><h3>Matrix Inverse</h3><p>Please refer to this <a href="https://meheraj.medium.com/inverting-a-matrix-in-python-3f7c1c136cf4">link</a> for Inverse of a Matrix.</p><h3>Summary</h3><p>So, I basically tried to implement the basic operations of Linear Algebra that are used in Machine Learning. I hope you got to know a little bit about how to multiply, add and subtract these mathematical objects. On top of that, you have learned what inverse and transpose Matrices are and what you can do with them. Although there are also other parts of Linear Algebra used in Machine Learning, this post will help you learn the most important concepts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ef0570a8313" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Inverting  a matrix in Python]]></title>
            <link>https://meheraj.medium.com/inverting-a-matrix-in-python-3f7c1c136cf4?source=rss-6b011a65d0bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f7c1c136cf4</guid>
            <category><![CDATA[script]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[matrix]]></category>
            <dc:creator><![CDATA[Meharaj Ul Mahmmud]]></dc:creator>
            <pubDate>Fri, 23 Apr 2021 16:59:26 GMT</pubDate>
            <atom:updated>2021-04-23T17:45:11.773Z</atom:updated>
            <content:encoded><![CDATA[<h3>Inverting a matrix in Python</h3><h3>Implementing a python script to inverse a 3x3 square matrix.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*tfzN-p3-qSp3-X9u9Gb-KA.jpeg" /></figure><p>A matrix is invertible if its determinant is not equated to zero (0). , there are few steps till the final result. We will go through each of them.</p><p>Steps to inverse a matrix:</p><ol><li>Check the determinant.</li><li>If the determinant is non-zero, calculate the cofactor matrix.</li><li>Calculate the adjoint matrix.</li><li>Multiply the adjoint matrix with 1 over determinant (1 / determinant).</li></ol><p><strong>Inverse matrix formula</strong></p><p><em>Inv(A) = (1 / det(A)) * Adj(A)</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a18ee0cdecbba7299049b475bdb997e/href">https://medium.com/media/8a18ee0cdecbba7299049b475bdb997e/href</a></iframe><p>Let’s find the Inverse of the matrix.</p><h3>Step 1 — Calculating the determinant</h3><p>We will have to calculate the cofactor for each of the elements of the first row. If the determinant of the given matrix is zero, then there is no inverse for the given matrix</p><blockquote>det (A) = 1(0–24) -2(0–20) + 3(0–5)</blockquote><blockquote>det(A) = -24 +40–15</blockquote><blockquote>det (A) = 1</blockquote><p>Therefore, we can say that the given matrix has an inverse matrix.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d3917eccea95ed9026a7e1dde14829a/href">https://medium.com/media/5d3917eccea95ed9026a7e1dde14829a/href</a></iframe><p>Here we have used calcMinor() function, which will return the cofactor value for a certain element.</p><p>And the function is implemented this way.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a696c3daca8a335b5b2b1f0ab63103fc/href">https://medium.com/media/a696c3daca8a335b5b2b1f0ab63103fc/href</a></iframe><p>In the calcMinor() function we have used negative indexing. This is pretty basic. But if you get a hard time understanding how the negative indexing is working here, try to visualize the code. It will come to you eventually.</p><p><strong>Step 2 — Calculating the cofactor matrix</strong></p><p>We will have to calculate the cofactor for each of the elements of the matrix. We will use the calcMinor() function here again.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3503686e9feefdef331fbb4bc43e806f/href">https://medium.com/media/3503686e9feefdef331fbb4bc43e806f/href</a></iframe><p><strong>Step 3 — Calculating the adjoint matrix</strong></p><p>Adjoint or Adjugate matrix is basically the transpose of the cofactor matrix. So now we will transpose the matrix we got in the second step.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/430032bcedf9bc5f124ebcc5cdf19a78/href">https://medium.com/media/430032bcedf9bc5f124ebcc5cdf19a78/href</a></iframe><p>This function will return us the Adjoint matrix, which is the transpose of the cofactor matrix.</p><p><strong>Step 4 — Final step, Multiplying the adjoint matrix with (1 / determinant)</strong></p><p>Multiply the adjoint matrix with (1/determinant).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b43f0e636831899ad57f58f7ba0b437/href">https://medium.com/media/9b43f0e636831899ad57f58f7ba0b437/href</a></iframe><p>This function will return us the inversed matrix.</p><p><strong>To sum it all,</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7cd8beae97ff281ffdf83b3d965dee78/href">https://medium.com/media/7cd8beae97ff281ffdf83b3d965dee78/href</a></iframe><p>And there you go. You have implemented a python script to compute the inverse of a 3x3 square matrix.</p><p>Thanks for your patience.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f7c1c136cf4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>