<?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 Ravish Kumar on Medium]]></title>
        <description><![CDATA[Stories by Ravish Kumar on Medium]]></description>
        <link>https://medium.com/@ravishraj?source=rss-83050f0803ca------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*MsTM8NOjaysSlfLD8oNaxA.png</url>
            <title>Stories by Ravish Kumar on Medium</title>
            <link>https://medium.com/@ravishraj?source=rss-83050f0803ca------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 05:36:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ravishraj/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[Exception Handling in Python]]></title>
            <link>https://medium.com/enjoy-algorithm/exception-handling-in-python-edc1e938c834?source=rss-83050f0803ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/edc1e938c834</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python3]]></category>
            <dc:creator><![CDATA[Ravish Kumar]]></dc:creator>
            <pubDate>Mon, 26 Feb 2024 06:12:56 GMT</pubDate>
            <atom:updated>2024-02-26T06:12:56.179Z</atom:updated>
            <content:encoded><![CDATA[<h3>Exception Handling in Python For ML</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*huuk_Ivii2OTrKcIzXY5GQ.png" /></figure><h4>What are exceptions?</h4><p>Computer programs can be syntactically correct but still fail during runtime (execution) because of some fundamental logical issues. The errors detected during runtime are known as exceptions. For example:</p><pre>a = 1/0</pre><p>The statement above is syntactically correct, but we can quickly determine that division by zero is impossible with mathematical logic. Computer programs are smart enough to catch these exceptions and will produce errors. For the above statement in Python, it will make <strong>ZeroDivisionError</strong>, shown below:</p><pre><br>Traceback (most recent call last)<br>Cell In [31], line 1<br>----&gt; 1 a = 1/0<br><br>ZeroDivisionError: division by zero</pre><p>Some predefined exceptions are available in Python, and the most popular ones are <strong>ZeroDivisionError, NameError, </strong>and<strong> TypeError. </strong>Examples of these can be seen in the code below:</p><pre>&gt;&gt;&gt; a = 1/0<br>Traceback (most recent call last):<br>  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;<br>ZeroDivisionError: division by zero<br><br>&gt;&gt;&gt; b = alpha*10<br>Traceback (most recent call last):<br>  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;<br>NameError: name &#39;alpha&#39; is not defined<br><br>&gt;&gt;&gt; c = &#39;age&#39; + 10<br>Traceback (most recent call last):<br>  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;<br>TypeError: can only concatenate str (not &quot;int&quot;) to str</pre><h4>List of predefined exceptions in Python?</h4><p>We can get a list of all the predefined illegal operations in Python programming language like this:</p><pre>print(dir(locals()[&#39;__builtins__&#39;]))<br><br>[&#39;ArithmeticError&#39;, &#39;AssertionError&#39;,<br>  &#39;AttributeError&#39;, &#39;BaseException&#39;, &#39;BlockingIOError&#39;, <br>  &#39;BrokenPipeError&#39;, &#39;BufferError&#39;, &#39;BytesWarning&#39;, <br>  &#39;ChildProcessError&#39;, &#39;ConnectionAbortedError&#39;, <br>  &#39;ConnectionError&#39;, &#39;ConnectionRefusedError&#39;, <br>  &#39;ConnectionResetError&#39;, &#39;DeprecationWarning&#39;, <br>  &#39;EOFError&#39;, &#39;Ellipsis&#39;, &#39;EnvironmentError&#39;, <br>  &#39;Exception&#39;, &#39;False&#39;, &#39;FileExistsError&#39;, <br>  &#39;FileNotFoundError&#39;, &#39;FloatingPointError&#39;, <br>  &#39;FutureWarning&#39;, &#39;GeneratorExit&#39;, &#39;IOError&#39;, <br>  &#39;ImportError&#39;, &#39;ImportWarning&#39;, &#39;IndentationError&#39;,<br>  &#39;IndexError&#39;, &#39;InterruptedError&#39;, &#39;IsADirectoryError&#39;, <br>  &#39;KeyError&#39;, &#39;KeyboardInterrupt&#39;, &#39;LookupError&#39;, &#39;MemoryError&#39;,<br>  &#39;ModuleNotFoundError&#39;, &#39;NameError&#39;, &#39;None&#39;, &#39;NotADirectoryError&#39;,<br>  &#39;NotImplemented&#39;, &#39;NotImplementedError&#39;, &#39;OSError&#39;, &#39;OverflowError&#39;, <br>  &#39;PendingDeprecationWarning&#39;, &#39;PermissionError&#39;, &#39;ProcessLookupError&#39;,<br>  &#39;RecursionError&#39;, &#39;ReferenceError&#39;, &#39;ResourceWarning&#39;, &#39;RuntimeError&#39;,<br>  &#39;RuntimeWarning&#39;, &#39;StopAsyncIteration&#39;, &#39;StopIteration&#39;, &#39;SyntaxError&#39;,<br>  &#39;SyntaxWarning&#39;, &#39;SystemError&#39;, &#39;SystemExit&#39;, &#39;TabError&#39;, &#39;TimeoutError&#39;,<br>  &#39;True&#39;, &#39;TypeError&#39;, &#39;UnboundLocalError&#39;, &#39;UnicodeDecodeError&#39;,<br>  &#39;UnicodeEncodeError&#39;, &#39;UnicodeError&#39;, &#39;UnicodeTranslateError&#39;,<br>  &#39;UnicodeWarning&#39;, &#39;UserWarning&#39;, &#39;ValueError&#39;, &#39;Warning&#39;, <br>  &#39;ZeroDivisionError&#39;, &#39;__build_class__&#39;, &#39;__debug__&#39;, &#39;__doc__&#39;, <br>  &#39;__import__&#39;, &#39;__loader__&#39;, &#39;__name__&#39;, &#39;__package__&#39;, &#39;__spec__&#39;,<br>  &#39;abs&#39;, &#39;all&#39;, &#39;any&#39;, &#39;ascii&#39;, &#39;bin&#39;, &#39;bool&#39;, &#39;breakpoint&#39;, &#39;bytearray&#39;,<br>  &#39;bytes&#39;, &#39;callable&#39;, &#39;chr&#39;, &#39;classmethod&#39;, &#39;compile&#39;, &#39;complex&#39;,<br>  &#39;copyright&#39;, &#39;credits&#39;, &#39;delattr&#39;, &#39;dict&#39;, &#39;dir&#39;, &#39;divmod&#39;, &#39;enumerate&#39;,<br>  &#39;eval&#39;, &#39;exec&#39;, &#39;exit&#39;, &#39;filter&#39;, &#39;float&#39;, &#39;format&#39;, &#39;frozenset&#39;, &#39;getattr&#39;,<br>  &#39;globals&#39;, &#39;hasattr&#39;, &#39;hash&#39;, &#39;help&#39;, &#39;hex&#39;, &#39;id&#39;, &#39;input&#39;, &#39;int&#39;, <br>  &#39;isinstance&#39;, &#39;issubclass&#39;, &#39;iter&#39;, &#39;len&#39;, &#39;license&#39;, &#39;list&#39;, &#39;locals&#39;, <br>  &#39;map&#39;, &#39;max&#39;, &#39;memoryview&#39;, &#39;min&#39;, &#39;next&#39;, &#39;object&#39;, &#39;oct&#39;, &#39;open&#39;, &#39;ord&#39;,<br>  &#39;pow&#39;, &#39;print&#39;, &#39;property&#39;, &#39;quit&#39;, &#39;range&#39;, &#39;repr&#39;, &#39;reversed&#39;, &#39;round&#39;,<br>  &#39;set&#39;, &#39;setattr&#39;, &#39;slice&#39;, &#39;sorted&#39;, &#39;staticmethod&#39;, &#39;str&#39;, &#39;sum&#39;, <br>  &#39;super&#39;, &#39;tuple&#39;, &#39;type&#39;, &#39;vars&#39;, &#39;zip&#39;]</pre><h4>Errors and Exceptions</h4><p>Computer programs may fail because of many issues like fundamental logical flaws, infinite loops, missing base conditions in recursion, or even syntax errors. Out of all these issues, flaws or failures coming from fundamental predefined logical failures are known as exceptions. These exceptions can easily be detected during the execution of a program and can be handled as well, which we call exception handling.</p><p><strong>Note:</strong> Although programmers can handle errors using exceptional handling techniques, it is not advisable to do that.</p><h4>Exception Handling in Python</h4><p>Now that we know exceptions terminate the execution of programs, we need to handle them properly so that other processes are not affected. We use <strong>“try and except” </strong>statements in Python to handle them. The syntax for the try-except block can be seen below:</p><pre>try:<br>   # code that can create exceptions<br><br>except:<br>   # code to execute if there is any exception</pre><p><strong>Example 1: Handline ZeroDivisionError exception using try-except block</strong></p><pre>try:<br>    a = 1<br>    b = 0<br>    c = a/b<br><br>except:<br>    print(&quot;Denominator can not be 0&quot;)<br><br>## Denominator can not be 0</pre><p><strong>Example 2: Handling the particular exception in multiple except statements</strong></p><p>Here, we have used variables “d” and “e” and did not define them in earlier statements. It will produce NameError; hence, that except statement will be called.</p><pre>try:<br>    a = 1<br>    b = 0<br>    c = d/e<br><br>except ZeroDivisionError:<br>    print(&quot;Denominator can not be 0&quot;)<br>    <br>except NameError:<br>    print(&quot;Some variable is not defined&quot;)<br><br>## Some variable is not defined</pre><p><strong>Example 3: Try-except-else statements</strong></p><p>While catching the particular statements, we sometimes need some notification that our try statement worked without any exceptions. In that case, to get notified that we have successfully avoided any exceptions, we can use a try-except-else statement like this:</p><pre>try:<br>    a = 10<br>    b = 2<br>    c = a/b<br>    <br>except NameError:<br>    <br>    print(&quot;Undefined variable is used!!&quot;)<br>    <br>else:<br>    print(&quot;Division Successful.&quot;)<br><br>## Division Successful.</pre><p><strong>Example 4: Try-except-else-finally statements</strong></p><p>After getting notified and coming out of this try-except block, we can use the final statement in the last if we need to execute one final program. For example, if we have opened the file, we finally need to close it after passing the try-except statement like this:</p><pre>try:<br>    my_file = open(&#39;0001-Copy1.1999-12-10.farmer.ham.txt&#39;, &quot;r&quot;)<br>    file_content = my_file.read()<br>    <br>except NameError:<br>    <br>    print(&quot;Undefined variable is used!!&quot;)<br>    <br>else:<br>    print(&quot;Content read successfully.&quot;)<br><br>finally:<br>    my_file.close()<br>    print(&quot;File is closed.&quot;)<br><br>##Content read successfully.<br>## File is closed.</pre><h4>Use Cases of Exception Handling</h4><ul><li>Programmers deal with a lot of codebase while working on a large software of ML applications. Exception handling makes the program debugging easy and efficiently catches which line creates the issue.</li><li>With exception handling, we can stop the abrupt termination of programs and keep continuing the execution of the rest of the statements.</li><li>While implementing the machine learning model, we need to import various libraries and execute these models on remote servers. Some libraries may not be installed on the remote server. We can avoid the execution of those libraries with the help of try-except statements.</li></ul><h4>Conclusion</h4><p>Computer programs fail to execute because of some predefined logical flaws, which are known as exceptions. They can terminate the execution of programs abruptly and need to be handled. We use a try-except statement block in Python to catch and handle the exceptions separately. This helps debug large codes easily and maintain smooth execution in case of small mistakes.</p><p><strong>Enjoy Learning.</strong></p><h4><a href="https://www.enjoyalgorithms.com/live-machine-learning-course/">16 Week Live Project-Based ML Course: Admissions Open</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edc1e938c834" width="1" height="1" alt=""><hr><p><a href="https://medium.com/enjoy-algorithm/exception-handling-in-python-edc1e938c834">Exception Handling in Python</a> was originally published in <a href="https://medium.com/enjoy-algorithm">EnjoyAlgorithms</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Andrews Curve For Data Visualization]]></title>
            <link>https://medium.com/enjoy-algorithm/andrews-curve-for-data-visualization-4599ccc9ed9a?source=rss-83050f0803ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/4599ccc9ed9a</guid>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Ravish Kumar]]></dc:creator>
            <pubDate>Tue, 20 Feb 2024 03:45:50 GMT</pubDate>
            <atom:updated>2024-02-20T03:55:11.824Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SFqrm2v_ubLvZFg33LFIzw.png" /></figure><p>Analyzing high-dimensional data is challenging as no method exists to visualize more than three dimensions simultaneously. This is popularly renowned as the <strong>Curse of Dimensionality</strong> and refers to a scenario where we have “too many” features in our dataset.</p><p>Although the definition of “too many” is subjective and highly depends on the project we are working on. However, with the new trend of data collection, data engineers tend to collect as many features as possible. This is because removing data features is relatively easier than regenerating the same scenario and collecting the entire data again.</p><figure><img alt="Dimenisonality reduction" src="https://cdn-images-1.medium.com/proxy/0*AP9tMItWYZayTbRl.png" /></figure><p>This opens up another challenge in analyzing the data samples. We can only send the data to the ML model if we analyze it first and then ensure that it will be helpful in learning. But to analyze such a huge dimension, we first reduce the dimensionality, explore the relationship, and then feed the data to build ML models.</p><p>Data features in the higher dimension have their properties, like variance and relative distance. When we try to reduce the dimensionality, we lose some of these properties, and techniques that provide the least loss are considered to be better.</p><p>Two prevalent methods for reducing dimensionality are t-stochastic Neighborhood Estimation (t-SNE) and Principal Component Analysis (PCA). But here, we will learn a new, less renowned yet effective technique to analyze the relationship among data samples in a higher dimension.</p><h4>Andrews Curve</h4><p>Andrews curve is a projection of each row of the data onto a vector:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*Wstcaq_zQbmdXfZuXzrjbg.png" /></figure><p>This vector is a dynamic vector and changes with respect to the variable “t”. If a data has “d” features, then the row vector of that data will look something like this: [x1, x2, x3, …., xd]. When we project this sample over the dynamic vector, it will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D0ulm9exIPB4qzC-IlKchg.png" /></figure><p>We can think of this projection as a variable “t” function with an already defined range of ‘t’ as (-Π, +Π).</p><h4>What does Adrews Curve represent?</h4><p>Andrews curve brings the multi-dimensional data into a lower space by retaining the relative distance between other samples and keeping the variance similar. Variance can be correlated to the information present in the data. So, plotting the projected function represents <strong>“How similar are the data samples when they are representing the same or similar output?”</strong> For example, if data Sample-1 and Sample-2 both give the same class label as the output, they should be relatively closer to each other in the higher dimension. And if the relative distance is lesser in the higher dimension, it should show similar behavior in the lower dimension.</p><h3>Andrews Curve on Iris Dataset using Python</h3><h4>Introduction to IRIS Dataset</h4><p>IRIS is a widely popular dataset containing three flower classes: Setosa, Versicolor, and virginica. It has four-dimensional features: Sepal length, Sepal width, Petal length, and Petal width. ML models segregate these flowers based on these features as per their types.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-RJBSqxsOxoHJ1i3" /></figure><h4>Loading the IRIS Dataset into the Python Code</h4><p>We can download this dataset from the official GitHub repository of the Pandas library <a href="https://github.com/pandas-dev/pandas/blob/main/pandas/tests/io/data/csv/iris.csv">IRIS.csv</a>. The line below will load all of this data into our code environment.</p><pre>import pandas as pd<br><br>df = pd.read_csv(<br>    &#39;https://raw.github.com/pandas-dev/&#39;<br>    &#39;pandas/main/pandas/tests/io/data/csv/iris.csv&#39;<br>)<br><br>print(df.head())<br><br><br>&#39;&#39;&#39;<br>      SepalLength   SepalWidth   PetalLength   PetalWidth     Name<br>-------------------------------------------------------------------------<br>0          5.1         3.5          1.4         0.2        Iris-setosa<br>1          4.9         3.0          1.4         0.2        Iris-setosa<br>2          4.7         3.2          1.3         0.2        Iris-setosa<br>3          4.6         3.1          1.5         0.2        Iris-setosa<br>4          5.0         3.6          1.4         0.2        Iris-setosa<br><br>&#39;&#39;&#39;<br></pre><p>Please note that the data is supervised as the labels are present with the column name “Name”.</p><h4>Plotting Separate Classes</h4><p>As the data has 4-dimensional features, we might not be able to find similarities among the samples by plotting them. So, we will use the Andrews curve to project each sample on the dynamic vector. To make the understanding more firm, we will first draw the Andrews curve for samples belonging to one class. Let’s start with Setosa.</p><p><strong>Setosa</strong></p><p>To extract the samples from the Setosa class, we will use <strong><em>df[df[‘Name’]==’Iris-setosa’]. </em></strong>Now, in the Pandas library, we have a direct function of andrews_curve to plot the curve using the dataframe, and the complete function and its arguments can be seen below.</p><blockquote>pandas.plotting.<strong>andrews_curves</strong>(<em>frame</em>, <em>class_column</em>, <em>ax=None</em>, <em>samples=200</em>, <em>color=None</em>, <em>colormap=None</em>, <em>**kwargs</em>)</blockquote><p>It expects a data_frame, a column from the dataframe to be drawn, the plot color, and the number of samples that need to be drawn. A complete list of these functional arguments can be found <a href="https://pandas.pydata.org/docs/reference/api/pandas.plotting.andrews_curves.html">here</a>.</p><pre>df_setosa = df[df[&#39;Name&#39;]==&#39;Iris-setosa&#39;]<br><br>plt.figure(&#39;setosa&#39;)<br>pd.plotting.andrews_curves(df_setosa, &#39;Name&#39;, color=[&#39;r&#39;])<br>plt.xlabel(&#39;t&#39;)<br>plt.ylabel(&#39;f(t)&#39;)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*1QDHxb_-4qiOK91I_O6-kg.png" /></figure><p><strong>Versicolor</strong></p><p>Similarly, for the Veriscolor class samples.</p><pre>df_versicolor = df[df[&#39;Name&#39;]==&#39;Iris-versicolor&#39;]<br><br>plt.figure(&#39;versicolor&#39;)<br>pd.plotting.andrews_curves(df_versicolor, &#39;Name&#39;, color=[&#39;g&#39;])<br>plt.xlabel(&#39;t&#39;)<br>plt.ylabel(&#39;f(t)&#39;)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*35WdkIuyK5vx0nM_4O_FFQ.png" /></figure><p><strong>Virginica</strong></p><pre>df_virginica = df[df[&#39;Name&#39;]==&#39;Iris-virginica&#39;]<br><br>plt.figure(&#39;virginica&#39;)<br>pd.plotting.andrews_curves(df_virginica, &#39;Name&#39;, color=[&#39;b&#39;])<br>plt.xlabel(&#39;t&#39;)<br>plt.ylabel(&#39;f(t)&#39;)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*1svd0AGnItuN63mFcfKQOg.png" /></figure><p>Please note that the curves for Virginica and Versicolor are almost similar. This is the same thing noticed while applying the k-means clustering algorithm on this dataset. The two clusters were very close to each other. If we use the k-means algorithm on Iris Dataset, the clustering will be formed like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DKuSLbMnCJATZUvr" /></figure><p>We can observe that the purple and yellow color samples are very close to each other compared to the green curves representing the Setosa class.</p><h4>Plotting All Classes to observe the data pattern</h4><pre>plt.figure(&#39;Andrews Curve&#39;)<br><br>pd.plotting.andrews_curves(df, &#39;Name&#39;, color=[&#39;r&#39;, &#39;g&#39;, &#39;b&#39;])<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*Cjh5BD1P3ZdScJuYimFP2A.png" /></figure><p>This complete plot will now enable us to identify the hidden patterns in the dataset, which is 4-dimensional. With the individual class representation, we learned that the Versicolor and Virginica classes are very similar and confirmed the same via k-means clustering output.</p><h4>Conclusion</h4><p>Andrews Curve is a way to represent higher dimensional data into a lower space so that analysis becomes easy. It is represented via a Fourier series and can also be thought of as a projection of higher dimensional data points on a dynamic vector.</p><p><strong>Enjoy Learning!</strong></p><h4><a href="https://www.enjoyalgorithms.com/live-machine-learning-course/">16 Week Live Project-Based ML Course: Admissions Open</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4599ccc9ed9a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/enjoy-algorithm/andrews-curve-for-data-visualization-4599ccc9ed9a">Andrews Curve For Data Visualization</a> was originally published in <a href="https://medium.com/enjoy-algorithm">EnjoyAlgorithms</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Box Plot using Python: Data Summary by 5 Numbers]]></title>
            <link>https://medium.com/enjoy-algorithm/box-plot-using-python-data-summary-by-5-numbers-614a80bf2ba1?source=rss-83050f0803ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/614a80bf2ba1</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[Ravish Kumar]]></dc:creator>
            <pubDate>Mon, 19 Feb 2024 04:36:51 GMT</pubDate>
            <atom:updated>2024-02-19T04:36:51.372Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Wm8D-y5JLTtEOT-6gxhyg.png" /></figure><p>Tabular Data contains hundreds and thousands of rows with multiple columns containing attribute values for those rows. Remembering all the data is impossible; hence, we summarize the data using various techniques and try to remember the entire data using those summaries. In this article, we will learn one method of summarizing the whole structured/tabular dataset using one of the most popular techniques in Data Science, i.e., Box Plot.</p><h4>What is a Box Plot?</h4><p>A box plot is a data visualization technique that summarizes the structured data using five useful numbers calculated from the data. These five numbers are:</p><ol><li><strong>Minimum</strong></li><li><strong>First quartile</strong></li><li><strong>Median</strong></li><li><strong>Third quartile</strong></li><li><strong>Maximum</strong></li></ol><p>It is also known as a whisker plot in some literature. Let’s understand these five numbers in detail with the help of a dummy example.</p><h4>Example1: Calculating the five numbers to summarize a dataset</h4><p>Let’s say we have collected the maths marks out of 100 for 10 students from a class, and the records are 11, 07, 35, 55, 64, 90, 86, 88, 95, and 97. Let’s calculate the five numbers from this record. For that, rearranging the dataset in ascending order will be very handy. Records in ascending order would be 07, 11, 35, 55, 64, 86, 88, 90, 95, 97.</p><h4><strong>1. Minimum:</strong></h4><p>Here, the minimum mark is 07.</p><h4><strong>2. Median</strong></h4><p>A median represents the middle element of the data if it is arranged in ascending or descending order. In the rearranged example dataset, if “n” is the total number of samples in the data, there can be two scenarios: <strong>n is even or odd.</strong></p><ul><li><strong>Odd number of samples:</strong> If n is odd, the observation at the [(n+1)/2]th position will be the middle of the arranged data and the median. For example, if we have five samples arranged in ascending order, the sample in the middle would be the sample at position (5+1)/2 = 3. Why? Because two samples would be on the left of the 3rd position sample and 2 samples on the right. The sample at the 3rd position would be the middle and hence median.</li><li><strong>Even number of samples:</strong> If n is even, there will be no middle position. For example, when we have six samples, both 3rd and 4th samples will be in the middle. In this case, we calculate the average of the numbers present at the two middle positions: (n/2 and (n/2 + 1).</li></ul><p>The example data above has 10 samples, and hence, the median would be the average of the 5th and 6th elements of the rearranged samples (07, 11, 35, 55, <strong>64, 85</strong>, 88, 90, 95, 97): (64 + 86)/2 = 75.</p><p><strong>So median is 75.</strong></p><h4>3. First quartile</h4><p>A quartile is a way to divide the number of data samples (100%) into four equal subgroups, each containing 25% of the data. The number of samples is more or less equal in each group.</p><p>The first quartile is the median of the dataset present on the left of the median of the complete dataset. In our example, the data samples on the left side of the median are 07, 11, 35, 55, and 64. As the number of samples is odd, the median for this dataset would be <strong>35</strong>, which will be the first quartile.</p><h4>4. Third Quartile</h4><p>The third quartile is the median of the dataset present on the right of the median of the complete dataset. In our example, the data samples on the right side of the median are 86, 88, 90, 95, and 97. As the number of samples is odd, the median for this dataset would be <strong>90</strong>, which will be the third quartile.</p><h4><strong>5. Maximum</strong></h4><p>The maximum in the dataset is 97.</p><p>This concludes the calculation of those five magical numbers and can be used to summarize the complete dataset.</p><h4>Box Plot</h4><p><strong>Stage 1:</strong> Now, we need to represent the entire dataset through the box plot. For that, we will first make an axis containing the range of data samples. An axis ranging from 0 to 100 will have all the data samples in our case.</p><p><strong>Stage 2:</strong> Once the axis is drawn, we will make a rectangular box with one side starting from the first quartile and ending at the third quartile. There will be a line at the median parallel to the other side of the rectangular box.</p><p><strong>Stage 3:</strong> Finally, a whisker will be drawn from the minimum to the first quartile and from the maximum to the third quartile. Let’s illustrate this box plot using the famous Seaborn Python library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IFmc313xybOdMP_5WQLIvA.png" /></figure><h3>Make a Box Plot on the IRIS dataset.</h3><p>We will use the famous IRIS dataset containing four features: “Sepal Length, Sepal Width, Petal Length, Petal Width,” and a corresponding label of three flower categories: “Setosa, Versicolor, Virginica”.</p><h4>Import Libraries</h4><pre>import pandas as pd<br>import matplotlib.pyplot as plt<br>import numpy as np<br>import seaborn as sns</pre><h4>Read the dataset</h4><pre>df = pd.read_csv(<br>    &#39;https://raw.github.com/pandas-dev/&#39;<br>    &#39;pandas/main/pandas/tests/io/data/csv/iris.csv&#39;<br>)<br>print(df.head())<br><br>&#39;&#39;&#39;<br><br>   SepalLength  SepalWidth  PetalLength  PetalWidth         Name<br>0          5.1         3.5          1.4         0.2  Iris-setosa<br>1          4.9         3.0          1.4         0.2  Iris-setosa<br>2          4.7         3.2          1.3         0.2  Iris-setosa<br>3          4.6         3.1          1.5         0.2  Iris-setosa<br>4          5.0         3.6          1.4         0.2  Iris-setosa<br>&#39;&#39;&#39;<br></pre><h4>Extract the features for which we want the plot</h4><pre>df_box = df[[&#39;SepalLength&#39;, &#39;SepalWidth&#39;, &#39;PetalLength&#39;, &#39;PetalWidth&#39;]]</pre><h4>Plot the Box plot for all the features</h4><pre>plt.figure()<br>sns.boxplot(df_box)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*vOL7F2wSB1WmcrPL1Jyfnw.png" /></figure><p>From this box plot, we can quickly summarize the individual features, and simultaneously, we can compare all the features present in the dataset to know more about the inlined pattern.</p><h4>Conclusion</h4><p>Box plot provides a five-point summary of the entire numerical feature from the structured dataset. These five points are Minimum, Maximum, Median, First, and Third Quartiles. This is very famous and frequently used for Data Visualization.</p><p><strong>Enjoy Learning.</strong></p><h4><a href="https://www.enjoyalgorithms.com/live-machine-learning-course/">16 Week Live Project-Based ML Course: Admissions Open</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=614a80bf2ba1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/enjoy-algorithm/box-plot-using-python-data-summary-by-5-numbers-614a80bf2ba1">Box Plot using Python: Data Summary by 5 Numbers</a> was originally published in <a href="https://medium.com/enjoy-algorithm">EnjoyAlgorithms</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Common Python Mistakes While Preparing Machine Learning Models]]></title>
            <link>https://medium.com/enjoy-algorithm/common-python-mistakes-while-preparing-machine-learning-models-2c9ef73b6aec?source=rss-83050f0803ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c9ef73b6aec</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[python3]]></category>
            <dc:creator><![CDATA[Ravish Kumar]]></dc:creator>
            <pubDate>Fri, 16 Feb 2024 06:40:06 GMT</pubDate>
            <atom:updated>2024-02-16T06:40:06.878Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DAfWwbZ2edRX4F9TgcnNIw.png" /></figure><p>In almost every Machine Learning and Deep Learning code, we notice a similar structure:</p><ul><li>The code starts with importing necessary libraries.</li><li>Then, we read the data files.</li><li>Analyzing and Preprocessing the read data.</li><li>Splitting the processed data into train val and test sets.</li><li>Create the model with optimizers and loss functions.</li><li>Finally, evaluate the model based on various metrics.</li></ul><p>While implementing this pipeline in Python, we encounter various kinds of errors. This article will show common mistakes in each stage and learn their resolutions.</p><h3>Common Mistakes at the stage of importing libraries</h3><p>This is the first step in almost all ML projects, where we first import required libraries to use their functions inside our programs. For example, in the code below, we import libraries like Numpy for mathematical calculations, Pandas to read the file, and Matplotlib &amp; Seaborn to plot the data features.</p><pre>import pandas as pd<br>import matplotlib.pyplot as plt<br>import numpy as np<br>import seaborn as sns</pre><h4>1. ModuleNotFoundError</h4><p>When we try to import a library that is not installed in the Python environment, it will produce a ModuleNotFoundError. For example, if Pandas is not already installed in a system, it will throw an error like this:</p><pre>Traceback (most recent call last):<br>File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;<br>No module named &#39;pandas&#39;</pre><p><strong>Resolution of this error:</strong></p><p>To solve the ModuleNotFoundError error, we need to install the corresponding library inside our Python environment. For the above example, we can install the Pandas library using pip like this: <strong><em>&quot;pip3 install pandas&quot;. </em></strong>Sometimes, we must install some libraries from the source as pip installation does not work. In that case, we clone their git repository and then build the module by running the setup files. Once installed, the error will be resolved.</p><h4>2. ImportError</h4><p>This error appears when we try to import a function not present inside the mentioned library. For example, there is no function named &quot;read_abc&quot; inside the Pandas library, so it is throwing an import error.</p><pre>from pandas import read_abc<br><br>Traceback (most recent call last):<br>  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;<br>ImportError: cannot import name &#39;read_abc&#39; from &#39;pandas&#39; (/Users/ravishkumar/EA_venv/lib/python3.9/site-packages/pandas/__init__.py)</pre><p><strong>Resolution of this error:</strong></p><p>To solve the ImportError, we need to understand what supports or functions a library properly provides. For example, we have two libraries, Numpy, and Pandas, because their functional supports differ. We can not call a function defined in the Pandas library by importing the Numpy library inside the code. Also, in most cases, developers make some spelling mistakes, which is why this error occurs. So, we need to ensure that the function is present inside that library and that the function is called with proper spelling.</p><p>Sometimes, the installation goes differently than expected, and the library gets installed partially. In that case, we need first to uninstall the library using pip, e.g., pip3 uninstall pandas. Later, re-install it fresh like this pip3 install pandas.</p><h3>Common Mistakes at the stage of reading data files</h3><p>When we import the required libraries and functions, we must use them to progress with ML pipeline development. The first requirement is the data, which is maintained structured or unstructured. The most common way to keep the structured dataset is in the CSV files. These CSV files are then read inside Python programs using the Pandas library like this:</p><pre>import pandas as pd<br><br>df = pd.read_csv(&#39;iris.csv&#39;)</pre><h4>1. FileNotFoundError:</h4><p>This error appears when we try to read a data file that is not present at the mentioned location. For example, if we directly mention read_csv(&#39;iris.csv&#39;), our programs expect that the &quot;iris.csv&quot; is present at the same location where the Python code file is.</p><pre>FileNotFoundError: [Errno 2] No such file or directory: &#39;iris.csv&#39;</pre><p><strong>Resolution of this error:</strong></p><p>To resolve FileNotFoundError, we need to ensure two things:</p><ul><li>Is that file present in our system?</li><li>If that file is present, did we mention the correct path location of that file inside our function? For example, if the file is at the Desktop location, then mention it like this: <strong><em>pd.read_csv(&#39;home/ravish/Desktop/iris.csv&#39;)</em></strong></li></ul><p>Ensuring these points will resolve the error.</p><h4>2. EmptyDataError:</h4><p>The characteristic of a CSV file is that the data samples should be separated with commas &quot;,&quot;. If we provide the filename with nothing with a comma &quot;,&quot; separation, it will produce EmptyDataError.</p><pre>EmptyDataError: No columns to parse from file</pre><p><strong>Resolution of this error:</strong></p><p>To resolve the EmptydataError, first, we can ensure comma-separated data inside a file by viewing it and opening it through any CSV viewers. If opening the entire data is impossible, we can re-fetch the files and check whether they contain the required data.</p><h3>Common Mistakes at the stage of Analyzing and preprocessing data</h3><p>Once the data is read, we need to process it to feed it to Machine Learning models for finding patterns. The data we read using the Pandas library gives a DataFrame object. To optimize the numerical computations on this, we change the DataFrame to numpy arrays like this:</p><pre>df = pd.read_csv(<br>    &#39;https://raw.github.com/pandas-dev/&#39;<br>    &#39;pandas/main/pandas/tests/io/data/csv/iris.csv&#39;<br>)<br><br>arr = np.array(df)<br>print(arr.shape)<br><br>## (150, 5)</pre><p>The most common errors at this stage will occur when handling large datasets in dataframes or numpy arrays.</p><h4>1. ValueError because of NaN or Missing Values.</h4><p>Suppose we want to convert the data types of a Python array, which contains NaN (Not a Number) values. This will throw an error.</p><pre>Traceback (most recent call last)<br><br>ValueError: cannot convert float NaN to integer</pre><p><strong>Resolution of this error:</strong></p><p>To solve this error, you need to first replace the NaN values in the data with your desired data type and then perform the desired operation.</p><pre>np.nan_to_num(arr) ## This will replace all Nan values with zero</pre><h4>2. TypeError:</h4><p>This type of error is prevalent when playing with data. We might perform arithmetic operations on two variables having different data types. For example,</p><pre>X = 10<br>Y = &#39;a&#39;<br>C = X + Y<br><br>#TypeError: unsupported operand type(s) for +: &#39;int&#39; and &#39;str&#39;</pre><p><strong>Resolution of this error:</strong></p><p>Please ensure that the data types of the two variables are similar and then only perform mathematical operations using them.</p><h4>3. IndexError</h4><p>This can happen when we try to access an index from a list or numpy array when it does not exist. For example, if a numpy array has 10 values and we want to extract the value present at the 11th index, it will throw an error.</p><pre># IndexError: index 200 is out of bounds for axis 0 with size 150</pre><p><strong>Resolution of this error:</strong></p><p>Please ensure that the <strong>index</strong> we are extracting from the array mentioned in our program is always less than the length of that array. Why is it less than the length of the array and not equal to the length of the array? Because the index starts from 0 in Python programming.</p><h4>3. AttributeError</h4><p>We know that everything in Python is an Object, and every object has some data type. Every type of object has some predefined attributes, but when we try to use an attribute that is not valid for a certain type of object, AttributeError occurs.</p><pre><br>string = &quot;Hello, world!&quot;<br>string.reverse()<br><br>---------------------------------------------------------------------------<br>AttributeError                            Traceback (most recent call last)<br>Cell In [59], line 2<br>      1 string = &quot;Hello, world!&quot;<br>----&gt; 2 string.reverse()<br><br>AttributeError: &#39;str&#39; object has no attribute &#39;reverse&#39;</pre><p><strong>Resolution of this error:</strong></p><p>To resolve this error, we must first ensure that a particular object contains that attribute.</p><h3>Common Mistakes at the stage of splitting the dataset into Train, Validation, and Test sets.</h3><p>After data processing, we split the dataset into</p><ul><li><strong>Train set: </strong>Used to train the Machine Learning model.</li><li><strong>Validation set (Val set): </strong>Used to fine-tune the hyperparameters by checking the performance of the trained model and tweaking the values of the hyperparameters.</li><li><strong>Test set: </strong>Used to evaluate the performance of the final trained model after tuning the hyperparameters.</li></ul><p>Developers mostly use the Scikit-learn library for this job, so let&#39;s see errors related to that and mistakes while writing this splitting from scratch.</p><p><strong>Splitting using Scikit-learn:</strong></p><pre>import numpy as np<br>from sklearn.model_selection import train_test_split<br>X, y = np.arange(10).reshape((5, 2)), range(5)<br><br>X_train, X_test, y_train, y_test = train_test_split(X, y, <br>                                                    test_size=0.33,<br>                                                    random_state=42)</pre><h4>1. ValueError:</h4><p>The splitting of the dataset depends on its availability. However, the train data percentage should be higher and capture all types of patterns in the entire dataset. We need to mention the test_size as the input parameter to the function, which lies strictly inside (0,1) and splits the dataset based on that library. So if we place something else in test_size, it will throw ValueError.</p><pre>X_train, X_test, y_train, y_test = train_test_split(X, y, <br>                                                    test_size=1.5,<br>                                                    random_state=42)<br><br># ValueError: test_size=1.5 should be either <br># positive and smaller than the number of samples 5 or a float <br># in the (0, 1) range<br><br><br>X_train, X_test, y_train, y_test = train_test_split(X, <br>                                                    test_size=0.33,<br>                                                    random_state=42)<br><br>## ValueError: not enough values to unpack (expected 4, got 2)<br><br>## This is due to the reason that we are not giving both input and output <br>## to the train_test_split function.</pre><p><strong>Resolution of the ValueError:</strong></p><p>Check all the input arguments of the function and the allowed ranges for these values. This will solve the ValueError.</p><p><strong>Scratch Splitting:</strong></p><pre>X, y = np.arange(10).reshape((5, 2)), range(5)<br>tot_len_x = len(X)<br>test_percent = 0.33<br>train_percent = 1- test_percent<br><br>X_train, Y_train = X[:int((train_percent)*tot_len_x)], y[:int((train_percent)*tot_len_x)]<br>X_test, Y_test = X[int((train_percent)*tot_len_x):], y[int((train_percent)*tot_len_x):]</pre><p>Error possibilities with this implementation are higher, so one needs to be cautious while implementing it.</p><h4>2. TypeError</h4><p>Please note that splitting the numpy arrays requires integer indices, and when we multiply <strong><em>(train_percent)*tot_len_x, </em></strong>it can result in non-integer values and will produce TypeError.</p><pre>X_train, Y_train = X[:((train_percent)*tot_len_x)], y[:((train_percent)*tot_len_x)]<br><br>## TypeError: slice indices must be integers or None or have an __index__ method</pre><p><strong>Resolution of TypeError:</strong></p><p>To solve the TypeError while splitting the dataset, you can make sure that the indices are integer by placing an extra &quot;int&quot; in front of the multiplication <strong><em>int((train_percent)*tot_len_x). </em></strong>This will ensure that the indices are integer and solve the type error. There is a possibility of logical errors like making <strong><em>train_percent &gt; 1, </em></strong>So one must be cautious while handling numpy arrays in splitting sets.</p><h3>Common Mistakes at the stage of Model creation, choosing optimization and loss functions</h3><p>There are many possibilities for encountering different errors while building ML models, choosing suitable optimization algorithms, and defining proper cost functions. But here, we will discuss only a few of them that are very common.</p><h4>Value Error:</h4><p>This error occurs when the training data and labels have different shapes.</p><pre>model.fit(classifier.fit(X_train, y_train)<br><br># ValueError: Found input variables with inconsistent numbers of samples: [112, 111]</pre><p><strong>Resolution of this error:</strong></p><p>When we try to train a supervised learning model, we must ensure that the lengths of the labels and the length of the input data should be the same. It justifies that every input sample has a corresponding output.</p><p>The chances of making Python mistakes are very low in this stage if we use frameworks and libraries for different algorithms. If we take care of the functional arguments of an algorithm defined inside a library, the model will get trained. But, the chances of performing the logical errors at this point are high.</p><p>For example, if binary cross entropy is used as a loss function for solving multi-class classification problems or regression problems. This is a fundamental logical flow and can be resolved only with a better understanding and working of Loss and Cost functions and proper optimization algorithms while building ML models.</p><h3>Common Mistakes at the Stage of Model Evaluation</h3><p>After training the Machine Learning model, we evaluate its performance on the test data, and based on the performance, we send the model for deployment. But during evaluation, we can encounter the following common errors:</p><h4>1. ValueError</h4><p>This is one of the most common errors when we have Y_actual and Y_predicted arrays with different lengths. This error must have been propagated from the splitting dataset part.</p><pre>from sklearn.metrics import confusion_matrix<br>cm = confusion_matrix(y_test, y_pred)<br><br>## ValueError: Found input variables with inconsistent numbers of samples: [38, 0]</pre><p><strong>Resolution of this error:</strong></p><p>One needs to ensure that the shapes of the two variables (y_test, y_pred) are the same. If they have different lengths and shapes, we will always encounter errors.</p><h4>2. Empty Image</h4><pre>plt.plot(accuracy_score(y_test, y_pred))<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pJNQFSrHnSZ33oFOHCvepA.png" /></figure><p>Please note that the image is empty, and it&#39;s a common mistake when we plot our ML model&#39;s accuracy on the test data.</p><p><strong>Resolution of this error:</strong></p><p>Please note that it&#39;s a logical but common error. Accuracy is just a number that does not vary for the entire dataset. It&#39;s the percentage of correct predictions out of all predictions.</p><p>Other possible logical errors include evaluating Precision when recall is required, and vice versa, or other theoretical errors. However, discussing them is out of the scope of this blog.</p><p><strong>Enjoy Learning!</strong></p><h4><a href="https://www.enjoyalgorithms.com/live-machine-learning-course/">16 Week Live Project-Based ML Course: Admissions Open</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c9ef73b6aec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/enjoy-algorithm/common-python-mistakes-while-preparing-machine-learning-models-2c9ef73b6aec">Common Python Mistakes While Preparing Machine Learning Models</a> was originally published in <a href="https://medium.com/enjoy-algorithm">EnjoyAlgorithms</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Read and Write Text Files Using Python Open]]></title>
            <link>https://medium.com/enjoy-algorithm/read-and-write-text-files-using-python-open-59ae618f48fc?source=rss-83050f0803ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/59ae618f48fc</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Ravish Kumar]]></dc:creator>
            <pubDate>Wed, 14 Feb 2024 08:37:29 GMT</pubDate>
            <atom:updated>2024-02-14T08:48:28.217Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G3RibJkwmQX_HOGVDcpX5Q.png" /></figure><p>Data files in ML and Data Science can be present as documents because maintaining a document is easy. Especially in Natural Language Processing (NLP), most textual datasets are present in files ending with a &quot;.txt&quot; file extension. In this article, we will learn methods to read the content of these document files, modify them, and save them again by updating the same document or creating a new document.</p><h4>Sample Document To Test</h4><p>We can create a dummy text file or download any authentic sample file to do some hands-on. For example, the image below shows a dataset containing emails.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zpxE4vvkHNCmTgiSLmkugA.png" /></figure><h4>How to open any Document in Python?</h4><p>We need to read their content while building ML models or analyzing these datasets. For that, in most cases, we use the <a href="https://docs.python.org/3/library/functions.html#open">&quot;open&quot; function</a> natively present in Python. This function expects two mandatory input arguments:</p><ul><li><strong>file:</strong> It includes the filename of that document to be opened along with its location directory. For example, if a folder is present in the Downloads folder, we need to give a complete directory of the file as a string like this: &#39;~/Downloads/sample_file1.txt&#39;.</li><li><strong>Mode: </strong>It is an optional argument representing the mode in which the file needs to be opened. The default value is &quot;r&quot; representing &quot;read&quot; mode. In simple terms, if we use open(file) directly, it will open the file in read-only mode. A list with all the modes is present in the table below.</li></ul><pre>Character                                       Meaning<br>------------------------------------------------------------------<br>   &#39;r&#39;, &#39;r+&#39;, or &#39;r+b&#39;    open the file in read-only mode (default) and do not truncate<br><br>   &#39;w&#39; &#39;w+&#39; or &#39;w+b&#39;     open the file for writing, truncating the file first<br><br>   &#39;x&#39;     open for exclusive creation, failing if the file already exists<br><br>   &#39;a&#39; or &#39;+&#39;        open for writing, appending to the end of file if it exists<br><br>   &#39;b&#39;                                       binary mode<br><br>   &#39;t&#39;                                   text mode (default)<br><br>   &#39;+&#39;                          open for updating (reading and writing)</pre><p>These modes represent a lot about the state of the file being opened by the open function. If we open the file with &#39;w&#39; mode, it will open the file with write mode, and if that file already exists, it will first delete the content present in that file and then write our instructed information in that file.</p><p>The line below shows a way to open one of the files present in the sample folder in the read-only mode.</p><pre><br>sample_file = open(&#39;0001.1999-12-10.farmer.ham.txt&#39;, &quot;r&quot;)<br><br>                |   ------------------------------    |<br>                |                   |                 |<br>               \_/                 \_/               \_/<br><br>          Open function     path of file to open    Mode<br>     </pre><p>As we know, in Python, everything is an object. So, the line above will create a file object with the name sample_file. This object will also contain some other information about the file being opened. For example, we can access the file&#39;s name opened using &#39;<strong>sample_file.name&#39; </strong>and the mode with which the file opened using <strong>&#39;sample_file.mode&#39;.</strong></p><pre>print(sample_file.name, sample_file.mode)<br><br>## 0001.1999-12-10.farmer.ham.txt r</pre><h4>Closing the Opened File</h4><p>When we open the file using Python&#39;s &quot;open&quot; function, it must be closed after performing the desired operations. For example, if we open the above file to read its content, then it should be closed after reading like this:</p><pre>sample_file = open(&#39;0001.1999-12-10.farmer.ham.txt&#39;, &quot;r&quot;)<br><br>sample_file.close() ## Closing</pre><p><strong>But why do we need to close the opened file?</strong></p><p>Let&#39;s list down the reasons for closing the opened file:</p><ul><li>The opened file needs to be closed as other programs running on the same system may start interfering with the content being dumped into that opened file. It will make the content corrupt or a garbage collector.</li><li>The opened file will use space from the RAM, slowing down our program.</li><li>In most cases, the changes in the opened files get reflected when we close the file. So, if we do not close the file, our changes will not reflect in that.</li><li>We will hit the limit of the number of files that can be opened inside a program.</li></ul><p><strong>Shouldn&#39;t it be automatically closed?</strong></p><ul><li>No, it should not be closed automatically, as we sometimes might need to dump information into the same file while doing the parallel execution performed on the same system.</li><li>Also, we can not automatically close opened files as the number of operations happening in that opened file can vary. If we automatically close the file, it may cause data loss issues.</li></ul><h4>How to check if the file is already closed?</h4><p>To check whether the file opened is already closed or not, we can use the &quot;.closed&quot; operation like this:</p><pre># Case 1<br><br>sample_file = open(&#39;0001.1999-12-10.farmer.ham.txt&#39;, &quot;r&quot;)<br><br>print(&quot;Case 1 : File is closed : &quot;,sample_file.closed)<br><br>sample_file.close()<br><br>print(&quot;Case 2 : File is closed : &quot;,sample_file.closed)<br><br><br>## Case 1 : File is closed :  False<br>## Case 2 : File is closed :  True<br></pre><h4>How do you automatically close the file after performing some operations?</h4><p>To avoid interference from other sources and get a sense of when the file will be closed and open, we open the file from the &quot;with&quot; statement like this:</p><pre>with open(&#39;0001.1999-12-10.farmer.ham.txt&#39;, &quot;r&quot;) as file1:<br><br>    print(&quot;Case 1 : File is closed : &quot;, file1.closed)<br><br>print(&quot;Case 2 : File is closed : &quot;, file1.closed)<br><br><br>&#39;&#39;&#39;<br>Case 1 : File is closed :  False<br>Case 2 : File is closed :  True<br>&#39;&#39;&#39;</pre><p>In Python, indentation matters a lot, and by using that, our program senses which operations need to be performed by keeping the file open, and as soon as we come out of the &quot;with&quot; statement, the file will get automatically closed. In most cases, we open files using the &#39;with&#39; statement.</p><p>Now, as the file is open, we will learn about performing actions on these opened text files. Some popular actions are <strong>Reading, Writing, and Appending</strong>.</p><h4>Reading content from the text file</h4><ul><li><strong>Reading the entire content at once:</strong></li></ul><pre>with open(&#39;0001.1999-12-10.farmer.ham.txt&#39;, &quot;r&quot;) as file1:<br><br>    file_content = file1.read()<br><br>print(file_content)<br><br>&#39;&#39;&#39;<br>This is line 1 in sample text file.<br>This is line 2 in sample text file.<br>This is line 3 in sample text file.<br>This is line 4 in sample text file.<br>This is line 5 in sample text file.<br>&#39;&#39;&#39;</pre><ul><li><strong>Reading the content as a list of lines in the text file using &quot;readlines&quot;:</strong></li></ul><p>Here, every line in the content is treated as a list element and forms a complete list on that basis. Please note the spelling &quot;readlines,&quot; which is plural, and that&#39;s why all the lines are present in the content.</p><p>We can also mention the number of characters we want to read</p><pre>with open(&#39;0001.1999-12-10.farmer.ham.txt&#39;, &quot;r&quot;) as file1:<br><br>    file_content = file1.readlines()<br>    <br><br>print(file_content)<br><br><br>&#39;&#39;&#39;<br>[&#39;This is line 1 in sample text file.\n&#39;, <br>      &#39;This is line 2 in sample text file.\n&#39;, <br>      &#39;This is line 3 in sample text file.\n&#39;, <br>      &#39;This is line 4 in sample text file.\n&#39;, <br>      &#39;This is line 5 in sample text file.&#39;]<br>&#39;&#39;&#39;</pre><ul><li><strong>Reading the content as a list of lines in the text file using &quot;readline&quot;:</strong></li></ul><p>Here, the &quot;readline&quot; attribute of the opened file object is used to read a single line of the content. If we call the &quot;readline&quot; attribute &quot;n&quot; times, it will read the &quot;n-th&quot; line from the text file. Please note the new line in the output printed.</p><pre>with open(&#39;0001.1999-12-10.farmer.ham.txt&#39;, &quot;r&quot;) as file1:<br><br>    file_content1 = file1.readline()<br>    file_content2 = file1.readline()<br>    file_content3 = file1.readline()<br>    file_content4 = file1.readline()<br>    file_content5 = file1.readline()<br>    file_content6 = file1.readline()<br><br>print(file_content1)<br>print(file_content2)<br>print(file_content3)<br>print(file_content4)<br>print(file_content5)<br>print(file_content6)<br><br>&#39;&#39;&#39;<br>This is line 1 in sample text file.<br><br>This is line 2 in sample text file.<br><br>This is line 3 in sample text file.<br><br>This is line 4 in sample text file.<br><br>This is line 5 in sample text file.<br><br>&#39;&#39;&#39;</pre><p><strong>Special case: </strong>If we call the &quot;readline&quot; attribute six times for the content having only five lines, it will not print anything.</p><h4>Writing a text file in Python by opening it in write mode</h4><p>Write is another important operation we perform with the text files while creating data or logging information by running various programs. We use the &quot;open&quot; function with the &quot;w (write)&quot; mode to open the text file in the write mode like this:</p><pre>open(&quot;sample_write.txt&quot;, &quot;w&quot;)<br><br>      -------\/--------<br><br>    filename + file directory</pre><p>There can be two scenarios: 1. Filename already exists in the mentioned file directory, and 2. The filename does not exist in the mentioned directory. Let&#39;s understand these scenarios by performing these things.</p><ul><li><strong>File exists</strong></li></ul><p>We will first open the file in read mode to read the original content, then open it in the write mode to write something in it, and then again open it in the read mode to see the new content after writing in it. Here is the sample code:</p><pre>### Open the file to read the original content in it<br><br>with open(&#39;0001-Copy1.1999-12-10.farmer.ham.txt&#39;, &quot;r&quot;) as file1:<br>    <br>    file_content1 = file1.read()<br>    print(&quot;** Original Content ** &quot;,file_content1)<br><br>#### file closed<br><br><br>### Open the file to write something in it<br><br>with open(&#39;0001-Copy1.1999-12-10.farmer.ham.txt&#39;, &quot;w&quot;) as file1:<br>    <br>    file1.write(&quot;This is new line written!!&quot;)<br>    <br>## file closed<br><br>### Open the file to read the new content in it<br><br>with open(&#39;0001-Copy1.1999-12-10.farmer.ham.txt&#39;, &quot;r&quot;) as file1:<br>    <br>    file_content1 = file1.read()<br>    print(&quot;** New Content ** &quot;,file_content1)<br><br>&#39;&#39;&#39;<br>** Original Content **  This is line 1 in sample text file.<br>This is line 2 in sample text file.<br>This is line 3 in sample text file.<br>This is line 4 in sample text file.<br>This is line 5 in sample text file.<br>** New Content **  This is new line written!!<br>&#39;&#39;&#39;</pre><p>Please note that the content is overwritten. The original content is lost in this case, and the new content we have written is the only content present in the same file.</p><ul><li><strong>The file does not exist.</strong></li></ul><pre>with open(&#39;sample_write.txt&#39;, &quot;w&quot;) as file1:<br>    <br>    file1.write(&quot;This is new line written!!&quot;)</pre><p>This will create a new file with the name of the filename mentioned in the open function at the given file directory location.</p><h4>Reading from one file and writing it in another</h4><p>We can store the readings as list entities using the readlines attribute and then use the Python loops to write those entities into another file.</p><pre>with open(&#39;0001.1999-12-10.farmer.ham.txt&#39;, &quot;r&quot;) as file1:<br>    <br>    all_lines = file1.readlines()<br>    <br>with open(&#39;0001-Copy1.1999-12-10.farmer.ham.txt&#39;, &quot;w&quot;) as file2:<br>    <br>    for line in all_lines:<br>        <br>        file2.write(line)<br>        <br>with open(&#39;0001-Copy1.1999-12-10.farmer.ham.txt&#39;, &quot;r&quot;) as file1:<br>    <br>    file_content1 = file1.read()<br>    <br>    print(&quot;** New Content ** &quot;,file_content1)<br><br>&#39;&#39;&#39;<br>** New Content **  This is line 1 in sample text file.<br>This is line 2 in sample text file.<br>This is line 3 in sample text file.<br>This is line 4 in sample text file.<br>This is line 5 in sample text file.<br>&#39;&#39;&#39;</pre><p>One good question that should cross our mind is, what if we do not want to lose the data or content present in the file, just put extra things into that same file? This won&#39;t be possible in the write mode as it will truncate the previous content. We can store the content of that file somewhere and then re-write it with the updated content. This can be tedious and requires more runtime memory. For this, we have an append mode.</p><h4>Appending the file: Adding more content to the existing file</h4><p>Here is the code to perform the appending operation to any existing file. We first need to have the new content we want to append and then use Python loops to append that.</p><pre>new_lines = [&#39;This is line 6 in sample text file.\n&#39;, &#39;This is line 7 in sample text file.\n&#39;]<br><br>with open(&#39;0001-Copy1.1999-12-10.farmer.ham.txt&#39;, &quot;a&quot;) as file1:<br>    <br>    for line in new_lines:<br>        file1.write(line)<br><br>with open(&#39;0001-Copy1.1999-12-10.farmer.ham.txt&#39;, &quot;r&quot;) as file1:<br>    <br>    file_content1 = file1.read()<br>    <br>    print(&quot;** New Content ** &quot;, file_content1)</pre><h4>Conclusion</h4><p>In Machine Learning, we often need to read text files by opening them, writing or modifying the existing content, and then restoring the updated versions. This content mentions how to open a text file using Python&#39;s in-built Open function with and without &#39;with&#39; statements. We hope you enjoyed the article and learned something new.</p><p>Enjoy Learning!</p><h4><a href="https://www.enjoyalgorithms.com/live-machine-learning-course/">16 Week Live Project-Based ML Course: Admissions Open</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59ae618f48fc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/enjoy-algorithm/read-and-write-text-files-using-python-open-59ae618f48fc">Read and Write Text Files Using Python Open</a> was originally published in <a href="https://medium.com/enjoy-algorithm">EnjoyAlgorithms</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Detailed Maths Topics In Machine Learning]]></title>
            <link>https://medium.com/enjoy-algorithm/detailed-maths-topics-in-machine-learning-ca55cd537709?source=rss-83050f0803ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca55cd537709</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[math]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Ravish Kumar]]></dc:creator>
            <pubDate>Tue, 13 Feb 2024 03:35:24 GMT</pubDate>
            <atom:updated>2024-02-13T03:35:24.487Z</atom:updated>
            <content:encoded><![CDATA[<h3>Detailed Maths Topics and Their Direct Use In Machine Learning</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eI6ZzKZb-MFpHHU9BeyyqQ.png" /></figure><p>Machine Learning is becoming popular because of the growing support of libraries and frameworks. It has become easier to find applications of AI and ML across all domains as people. However, by using AI via libraries and frameworks, one may not become a knower or professional in this field. It&#39;s good to have the support of coding frameworks to increase usability, but to land in the AI industry; we must know the logic behind those codes.</p><p>If we remove the frameworks&#39; support in AI, it will become essential to know the mathematical details to write the line-wise logic and make machines learn the complex hidden patterns in the data. Specifically, we need an understanding of Probability, Statistics, Linear Algebra, Calculus, and Graphs. In this article, we will dive deeper into the need for maths and know precisely where they will be used in machine learning.</p><h4>How does Maths help in becoming an expert in Machine Learning?</h4><p>With the concrete knowledge of Mathematics involved, one can utilize the full potential of ML while building interesting applications across all possible domains. For example:</p><ul><li>With the knowledge of inlined maths behind algorithms, one can select the best algorithm for the available dataset.</li><li>Mathematical knowledge behind the working of regularizers can help solve overfitting or high variance issues.</li><li>One can analyze more complex relationships among data features with the knowledge of Graphs.</li><li>One can design proper cost functions with the knowledge of the mathematics behind optimizers.</li></ul><p>There can be many such examples where maths can help make one an expert in Machine Learning. But what precisely in Maths? How much maths would be required? Let&#39;s find the concrete answer to this and learn the use of all these topics with some examples.</p><h3>What level of maths is required for ML?</h3><p>The answer to this question is subjective and depends on the individual requirements. For example, if someone is doing research in machine learning, they may need to have a profound knowledge of maths as research requires researchers to be thoroughly in-depth. But, simultaneously, a person who wants to use the applications developed using AI may not even require any level of mathematics.</p><p>In this article, we will specifically discuss the minimum depth levels required for the person starting the ML journey or seeking a mathematical starting point to improve the strength in the ML domain.</p><h3>What minimal topics in Maths are required for Machine Learning?</h3><p>In Machine Learning, these five maths topics are very frequently used:</p><ol><li><strong>Linear Algebra</strong></li><li><strong>Probability</strong></li><li><strong>Statistics</strong></li><li><strong>Calculus</strong></li><li><strong>Graphs</strong></li></ol><p>In the later parts of these blogs, we will see what we need to know about these topics and where they will be used in Machine Learning.</p><h4>Linear Algebra</h4><p>Linear Algebra is the most used maths topic in ML, ranging from classical Machine Learning to the most recent and advanced LLMs. One can easily find the usability of Linear Algebra in all ML algorithms, like Linear Regression, SVM, KNN, Random Forest, or any other algorithm.</p><ul><li><strong>N-dimensional vector:</strong> We generally have a large number of samples for every feature present in our dataset. If we consider one feature vector having n data samples, it will be an n-dimensional vector. As the data is present everywhere in Machine Learning, we need to deal with n-dimensional vectors everywhere; hence, knowledge of the properties of n-dimensional vectors like dot-product, cross-product, addition, and subtraction is crucial.</li><li><strong>Distance between Vectors: </strong>In ML, every feature is considered one dimension, and generally, the dataset contains numerous features. We first calculate the distance between the two features to observe their similarities. Hence, the knowledge of calculating the distance between two n-dimension vectors is crucial. The direct use-case of distance calculation can be found in two ML algorithms: <a href="https://www.enjoyalgorithms.com/blog/k-nearest-neighbours-in-ml/">K-Nearest Neighbors</a> and <a href="https://www.enjoyalgorithms.com/blog/k-means-clustering-algorithm/">K-Means</a>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EjNk4oywtHxrGojq" /></figure><ul><li><strong>Projection onto a plane: </strong>In SVM, we try to find the distance between a sample of n-dimensions and a plane existing in n-dimensions. In that case, we try to project that sample onto the hyperplane. Hence, the concepts of projection onto a plane and the knowledge of Hyperplanes are essential. The details of this can be found in t<a href="https://www.enjoyalgorithms.com/blog/support-vector-machine-in-ml/">he SVM blog</a>.</li><li><strong>Matrix: </strong>In the case of multi-dimensional features and a large number of parameters to learn, we take the help of matrices. In the case of Deep Learning, the number of parameters can reach Billions, and it becomes impossible to perform the process for each parameter. These parameters are stored as learnings in the form of Weight and Bias matrices. If one has used any ML application internally, that application uses these weight matrices to find the predictions. The Matrix concept makes Machine Learning and Deep Learning sustainable; otherwise, it would have taken ages to train the model and store the learnings. One can visit the blog <a href="https://www.enjoyalgorithms.com/blog/cost-function-in-machine-learning/">How Machine Learns in Machine Learning</a> to observe Matrices&#39; basic needs.</li></ul><figure><img alt="Representing weight vector matrix" src="https://cdn-images-1.medium.com/proxy/1*oOflMaF0kTaro8Q9sFvPxA.png" /></figure><ul><li><strong>Matrix multiplication, addition, subtraction, and transpose: </strong>Basic properties of Matrix, like multiplication, addition, and subtraction, are also present in all ML algorithms. We pass input data in the form of a matrix, multiply it by the weight matrix, and finally add it to the Bias matrix to form the final prediction. Hence, knowledge of these mathematical computations is essential to observe the transformation of the input features into the final predicted output.</li></ul><pre>Y_predicted = (Weight).Transpose * X_input + Bias</pre><ul><li><strong>Orthogonality: </strong>The complete dataset can be considered a matrix where rows correspond to values and columns correspond to the features. To check whether one feature is independent of all other features, the easiest way is to check the orthogonality of the Matrix. If all columns are perpendicular to all others, the Matrix is orthogonal. These concepts are crucial and used in popular algorithms like <a href="https://www.enjoyalgorithms.com/blog/principal-component-analysis-in-ml/">Principal Component Analysis (PCA)</a> and <a href="https://www.enjoyalgorithms.com/blog/support-vector-machine-in-ml/">Support Vector Machines (SVM)</a>.</li><li><strong>EigenValues and EigenVectors: </strong>As the dimensions in the dataset were increasing rapidly, there was a need to form dimensionality reduction techniques to observe the dataset and plot them in a 3D plane. Algorithms like PCA use the concept of Eigen Values and Eigen Vectors to check which features contribute more information to the data and subsequently preserve them in the final dataset as they are essential. To know these algorithms, we need to know EigenValues and EigenVector decompositions of matrices.</li><li><strong>Singular Value Decomposition: </strong>Matrix sizes are becoming huge these days with the advancement of computing power. In that case, we need a more straightforward way to extract the most essential information in the Matrix. That&#39;s where SVD comes into the picture in ML, where we factorize the Matrix into three different matrices. It is beneficial in the case of building applications involving a very high number of dimensions like <a href="https://www.enjoyalgorithms.com/blog/image-compression-using-pca/">Image Compression</a> or even <a href="https://www.enjoyalgorithms.com/blog/tsne-algorithm-in-ml/">t-SNE Algorithm</a>.</li></ul><h4>Probability and Probability Distribution Functions</h4><p>Probability is among the most used topics in almost all computer science fields. In Machine Learning, a complete algorithm, <a href="https://www.enjoyalgorithms.com/blog/naive-bayes-in-ml/">Naive Bayes Algorithm</a>, is primarily dedicated to Probability to understand how valuable maths can be in understanding the workings of ML thoroughly. Also, the predictions given by models in the case of classification algorithms are presented as probabilities of the various classes present in the dataset. Hence, understanding the workings of Probability is of utmost necessity. These are a few topics that one needs to understand under Probability clearly:</p><ul><li><strong>Simple Probability: </strong>In ML classification problems,<strong> </strong>we can easily find the usability of simple probability theories, like which class will be the dominant. Probability tells us about the chances of the presence/occurrence of any class based on the given input data. Along with the simple Probability, one should also know the basic rules like the sum or product rules of probabilities to gain more firm knowledge. The softmax activation function in ANNs uses simple probability theory to formulate the output in terms of probabilities and predict the maximum probable class.</li><li><strong>Conditional Probability and Bayes Theorem: </strong>Conditional Probability states the Probability of an event&#39;s occurrence based on another event&#39;s occurrence. This conditional Probability is used in Baye&#39;s theorem as well. These algorithms are extremely important in Machine learning as they hint at how input features can affect the predictions from an ML algorithm. The<a href="https://www.enjoyalgorithms.com/blog/naive-bayes-in-ml/"> Naive Bayes Classifier</a> algorithm is entirely based on the Bayes theorem itself, so one can sense the importance of these topics in ML.</li></ul><figure><img alt="baye&#39;s theorem terms " src="https://cdn-images-1.medium.com/proxy/1*EIVtLAe05L4htlZeMc8OFA.jpeg" /></figure><ul><li><strong>Random Variables: </strong>Continuous and Discrete random variables differ from algebraic variables and represent the outcomes of the random experiments. When assigning some initial values to the parameters in Machine Learning, we use random variables, which act as a starting point for our ML training process. Hence, the knowledge of random variables is required in ML or Data Science engineers/Scientists.</li><li><strong>Probability Distribution: </strong>In the case of classification problems, we can not use loss functions like MSE and MAE. Hence, we used to match the PDFs of the predicted and actual. One can learn about this PDF matching in these two blogs: <a href="https://www.enjoyalgorithms.com/blogs/classification-and-regression-in-machine-learning/">Classification and Regression in Machine Learning</a> and <a href="https://www.enjoyalgorithms.com/blog/loss-and-cost-functions-in-machine-learning/">Loss or Cost Functions in Machine Learning</a>.</li></ul><figure><img alt="Classification problems in machine learning" src="https://cdn-images-1.medium.com/proxy/1*iboJDHi01Ipd_qxRcII_Rg.png" /></figure><ul><li><strong>Continuous and Discrete Distribution: </strong>Sometimes, the probability distribution does not follow a continuous nature, and hence, we need discrete density functions</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*GFL_LDxQJ6IakBKBq3LKBA.png" /></figure><ul><li><strong>Popular Distribution Functions:</strong> <strong>Gaussian, Skewed, non-skewed: </strong>Probability Distribution Functions, popularly known as PDFs, are essential to see the data distribution as algorithms like Linear regression work well with the input data from Gaussian distribution, which is a type of PDF.</li><li><strong>Maximum Likelihood Estimation (MLE): </strong>The logistic regression algorithm uses a particular type of cost function based on MLE methods.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/0*9-UXYqIhGRsV4Vys" /></figure><h4>Statistics</h4><p>Machine Learning is another form of statistics where we estimate the data summary. This summary can be anything ranging from finding the average or mean out of data to finding the summarization in a more complex form by predicting hidden patterns. For example, suppose we give you the salaries of 10 persons working in a company in the same position and ask you to predict the salary for the 11th person; what would be your guess? Average!! Right? Yes. This average can be far away from the actual figure, and using ML, we try to reduce this gap between predicted and Actual values. Hence, ML is another form of statistics only.</p><p>The topics we can focus on in Statistics are mainly Data Summarization techniques like</p><ul><li><strong>Mean: </strong>Mean is the average of the data values.<strong> </strong>The use of mean in Machine Learning can be found in the case of normalizing the features, calculating R² values, and many more. The reference to the blogs for <a href="https://www.enjoyalgorithms.com/blog/need-of-feature-scaling-in-machine-learning/">normalization</a> and <a href="https://www.enjoyalgorithms.com/blog/evaluation-metrics-regression-models/">evaluation metrics for regression models</a> where the mean is used can be found in the respective links.</li><li><strong>Median: </strong>The median represents the middle element in the data in ascending or descending order. It is beneficial when dividing data samples into equal intervals or inter-quartile ranges (IQR). One of the direct use cases can be found in the Box plot used for Data Analysis.</li><li><strong>Mode: </strong>Mode is the most frequent number present in the data sample. It summarizes the data regarding highly occurring elements, which can be used in machine learning to find which sample dominates the dataset. In the case of classification problems, if the mode suggests that one class is dominant, then ML models may always predict that class.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IFmc313xybOdMP_5WQLIvA.png" /></figure><h4>Calculus</h4><p>Calculus is also one of the most crucial math topics in Machine Learning. Most of its use can be found when training ML models, as it is a constant part of almost all optimization algorithms. For example, in the Gradient Descent algorithm, we use derivatives of the cost function to sense the direction (+ve or -ve) for updating the parameters. Let&#39;s list down some concepts under calculus that would be required.</p><ul><li><strong>Basics of Function: </strong>Functions are a core part of machine learning that is even present in the definition of ML.<strong> </strong>In ML, we try to map a function between input and output data. For example, we try to fit polynomials as per the mentioned degree in linear or polynomial regression algorithms.</li></ul><pre>Degree 1 : θ1*X + θ0<br><br>Degree 2: θ2*X^2 + θ1*X + θ0</pre><ul><li><strong>Continuous and Discrete Functions: </strong>In Machine Learning, we generally use derivatives over the functions. To check whether a function is differentiable, we need to check its continuity. Hence, the knowledge of properties of continuous and discrete functions helps decide whether a function is suitable for our use case. For example, continuity is a crucial property for any activation function in Artificial Neural Networks. Please check the <a href="https://www.enjoyalgorithms.com/blog/activation-functions-in-neural-networks">blog on activation functions</a> for more details.</li><li><strong>Basics of Differentiation:</strong> Differentiation of functions is critical in Machine Learning as we need it in all the algorithms as we estimate the direction to increase/decrease the parameter values based on the derivative of the cost function. Today, Python libraries can provide these values instantly, but knowing these mathematical concepts can help design or debug complex methodologies.</li><li><strong>Composite function &amp; Chain rule:</strong> While doing the backpropagation in neural networks, we need to use the chain rule to update all the parameters. This happens because the cost function at the output layer becomes a composite function, and the only way to find the derivative of the cost function is to use the chain rule. You can find the use of <a href="https://www.enjoyalgorithms.com/blog/chain-rule-of-calculus-for-neural-networks">chain rule in ANNs here</a>.</li><li><strong>Partial derivatives:</strong> In ML, there can be more than one parameter that machines need to learn. But to check the effect of one parameter on the overall cost function, we need to consider the partial derivative of the cost function w.r.t. all the individual parameters. In partial derivative, we only consider one parameter as a variable, and the rest are kept constant. A more detailed use of partial derivatives can be found in these blogs: <a href="https://www.enjoyalgorithms.com/blog/parameter-learning-and-gradient-descent-in-ml/">Gradient Descent</a> and Backpropagation in ANN.</li><li><strong>Fourier Series: </strong>A Fourier series is an expansion of a periodic function in terms of sine and cosine functions. We can find its direct use in data analysis and plotting Andrews curve.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SFqrm2v_ubLvZFg33LFIzw.png" /></figure><ul><li><strong>Matrix Differentiation: </strong>In Deep Learning models, the number of parameters can reach up to billions. In that case, it will become impossible to calculate the partial derivatives with respect to all the individual parameters. Hence, we use the matrix-based differentiation to compute the derivative layer-wise, not for each element.</li></ul><h4><strong>Graph</strong></h4><p>The concept of graphs is fundamental in Machine Learning. When training ML models, we plot curves to check whether loss decreases in subsequent epochs/iterations. We also use graphical representations to showcase the different types of analysis from the data to extract more meaningful information. Hence, graphs are another concept that is present in all stages of the ML pipeline. If we list down some topics under the graph, then:</p><ul><li><strong>Linear Function and Equations: </strong>Knowledge about the linear equations and functions is crucial when we learn ML, as most of the algorithms talk about the slopes/gradients and the equations like θ1*X + θ0 where we need to know values for θ1 and θ0.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*huIde8aAGLQbNBCt" /></figure><ul><li><strong>Non-linear and discrete graph formation: </strong>In the case of Polynomial fitting on the dataset, or even piece-wise learning in Machine Learning, we can find the use-case of non-linear and discrete functions. To check the fineness of the fitting, we need to plot the curves to check whether the predicted values of Y overlap the Actual values.</li><li><strong>Parabolic equations: </strong>Cost functions like MSE (Mean Squared Error) are specially designed to be in parabolic form as finding minima becomes straightforward. Another advantage of a parabolic equation is that it can have only one minimum, so optimizers will easily find parameters corresponding to that minimum. With this example, we can sense how useful it can be to know graphs.</li></ul><pre>MSE = Σ (Y&#39; - Y)^2, # Y&#39; = Predicted Value of Y and Y is the actual value of Y</pre><ul><li><strong>Higher-order polynomials and exponentials: </strong>We can find the higher-order Polynomial fitting on the dataset in numerous places. Even exponentials can be found in the inlined working of the Sigmoid activation function and the basic ML algorithm Logistic Regression. To understand these algorithms thoroughly, we must understand how the logit functions work.</li><li><strong>Functions like Tanh, Sigmoid, and custom graphical forms: </strong>The knowledge of curves like Tanh, Sigmoid, Relu, and other exponential curves can help decide the proper activation function in ANNs. An activation function must follow some properties, such as being bounded and zero-centered. With the graphical knowledge, we can easily sense that a function holds these properties.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_tMJj2ymAni4CDgU71NHOg.png" /></figure><h3>Do we need to learn all these concepts first and then start the ML journey?</h3><p>While reading Machine Learning, learners will encounter these mathematical concepts very frequently. It is not a prerequisite for starting Machine Learning. Generally, a learner starts with ML by being a user of ML and then dives deeper into the domain of ML by the amount of interest. Hence, mathematics is definitely not a prerequisite in ML, but if learners want to build a career in this field, they should know the bare minimum concepts mentioned in this blog.</p><p>Indeed, all the knowledge is not required to take your first step in the journey of Machine Learning, but it is advisable to learn all these concepts in parallel and identify their usage in ML to explore the full potential of this field.</p><h3>Conclusion</h3><p>The Knowledge of Mathematics can transform simple ML engineers into advanced ones. It enables them to understand the inlined principle of ML algorithms and even modify them as per their needs. In this article, we have summarized what exact topics in math are required for a machine learning beginner to excel in this domain. We hope you enjoyed the article.</p><p><strong>Enjoy Learning!</strong></p><h4><a href="https://www.enjoyalgorithms.com/live-machine-learning-course/">16 Week Live Project-Based ML Course: Admissions Open</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca55cd537709" width="1" height="1" alt=""><hr><p><a href="https://medium.com/enjoy-algorithm/detailed-maths-topics-in-machine-learning-ca55cd537709">Detailed Maths Topics In Machine Learning</a> was originally published in <a href="https://medium.com/enjoy-algorithm">EnjoyAlgorithms</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Popular Python Libraries In Machine Learning]]></title>
            <link>https://medium.com/enjoy-algorithm/popular-python-libraries-in-machine-learning-db9d7f433626?source=rss-83050f0803ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/db9d7f433626</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[libraries]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Ravish Kumar]]></dc:creator>
            <pubDate>Sun, 11 Feb 2024 05:46:38 GMT</pubDate>
            <atom:updated>2024-02-11T05:46:38.739Z</atom:updated>
            <content:encoded><![CDATA[<h3>Learning Tips For Popular Python Libraries In Machine Learning</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nJBoaZeS-ylfwtSq4vnVTA.png" /></figure><p>Python is considered the most used programming language in Machine Learning. But have you ever wondered why? And Why exactly is ML becoming so popular these days? It&#39;s all because of the ease in the usability of machine learning, which has become possible with the support of an enormous number of Python libraries. We can now build an entire ML model in just 10 to 15 lines of code, which would have taken hundreds and thousands of lines.</p><h4>Why do we need libraries in Machine Learning?</h4><p>Libraries package the reusable code modules and present them via functions that take user input and provide the desired output. Not only this, these libraries provide us with the best-optimized form of the functions by using concepts like multi-threading to make execution time extremely fast. Hence, knowledge of these libraries saves time and stops us from reinventing the wheel. It allows us to focus on more advanced parts of machine learning, like developing newer architecture or coining newer algorithms.</p><p>But one question should be coming into our minds: if so many libraries exist, what should we focus on while starting the ML journey?</p><h4>Which libraries shall we focus on while starting the ML journey?</h4><p>Python community is vast, and that&#39;s why we have the support of many Python libraries consisting of all types of functions. But we only need to know some of them to start our Machine Learning journey. Some of the most popular libraries that we should practice before doing hands-on in ML are:</p><ol><li><strong>Numpy</strong> (Numerical-Python) to perform numerical calculations efficiently.</li><li><strong>Scipy (Scientific Python) </strong>to<strong> </strong>optimize linear algebra, calculus, and image data-based calculations.</li><li><strong>Pandas </strong>to manage the datasets efficiently and effectively.</li><li><strong>Matplotlib</strong> to visualize the dataset or perform analysis.</li><li><strong>Scikit-learn </strong>to build the end-to-end pipeline for Machine Learning.</li></ol><p>Here, we will be discussing each of these libraries briefly and provide their resources to follow and learn.</p><h4>Numpy (Numerical Python)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VvQbtXljBGwvIuWcBeWkyg.png" /></figure><p>Numpy is a very popular open-source library in Machine Learning, and one can find its presence in almost all codes used in ML. The reason for that is that Numpy is used to perform numerical calculations. In ML, we narrow down all forms of datasets to numerical format and then feed them to our Machines to extract meaningful hidden patterns.</p><p>It is used to store and perform operations on multi-dimensional arrays or matrices. The capabilities and support it carries for various mathematical functions to perform wider operations ranging from simple linear algebra to estimating infinite Fourier series is way beyond any other libraries. Apart from this, it is swift in the computations compared with similar libraries and acts as a base for other libraries.</p><p><strong>Tips to learn Numpy</strong></p><p>For beginners who have started their ML journey, the best way to learn Numpy would be to:</p><ul><li>Learn critical operations like slicing, broadcasting, stacking, flattening, reshaping, and resizing numpy arrays.</li><li>Create a dummy multi-dimensional array using Numpy and perform linear algebra operations like Matrix multiplication, addition, or subtraction.</li><li>Try to compare the execution time between the &quot;library-based solutions&quot; and &quot;self-implemented solutions&quot; and observe the advantages of numpy.</li></ul><p><strong>Resources to follow and learn Numpy:</strong></p><ul><li><a href="https://numpy.org/doc/stable/">Numpy original documentation</a></li><li><a href="https://www.enjoyalgorithms.com/blog/introduction-to-numpy-in-python/">Summary of Numpy&#39;s useful functions</a></li></ul><h4>Scipy (Scientific Python)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eCzA0WrjHO2KAASuR4VVcg.png" /></figure><p>Scientific Python, popularly known as Scipy, is another open-source library built over the famous Numpy library. It is partially written in Python and partially in C language to boost the speed of mathematical computations further. It provides support for linear algebra, calculus, eigenvalue problems, statistics, and many more. Scipy is an advanced library and hence has some critical applications in Deep Learning or graphical data structures like Sparse matrix support.</p><p>One question should be coming into the mind: why use Scipy if Numpy is already there? Scipy is a full-fledged package comprising everything related to numerical data calculations like linear algebra, Fourier series, calculus, trigonometry, etc. If we require these numerical supports, then Scipy is better. Otherwise, for simple array formation, sorting indexing, and simple mathematical calculations, Numpy is more than enough.</p><p><strong>Tips to learn Scipy</strong></p><p>For beginners who have started their ML journey, the best way to learn Scipy would be to:</p><ul><li>The use of Scipy is mainly seen with Signal processing. Hence, in the case of audio datasets, it works the best. Therefore, load the audio datasets, perform Fourier Analysis, and extract insights.</li><li>Waveforms like Sine, Cosine, and Tangent can easily be formed with the Scipy library. So, to practice ML on dummy algorithms to check whether the model is learning, one can check the pattern following capabilities of that model on the Sine or Cosine datasets.</li><li>Perform linear algebra calculations like matrix multiplication, finding determinants, eigenvalues, and eigenvectors using Scipy, and compare the execution performance with respect to the Numpy library.</li></ul><p><strong>Resources to follow and learn Scipy:</strong></p><ul><li><a href="https://docs.scipy.org/doc/scipy/">Scipy official documentation page</a> and <a href="https://scipy.org/community/">Scipy Community.</a></li><li><a href="https://github.com/scipy/scipy">Scipy GitHub codebase</a></li></ul><h4>Pandas</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NpaMIJDuJmN5a2sG" /></figure><p>Pandas is a Python library mainly focusing on Data Analyses. It is also an open-source library built over the Numpy library, which supports large varieties of datasets across all domains. Machine Learning beginners need datasets to practice their learnings to perform analysis or build ML models. Pandas library provides functions to a broader variety of datasets, using which they can easily practice.</p><p>It supports two types of data structures (Series for one-dimensional and DataFrame for multi-dimensional) to process data in either structured or semi-structured format.</p><p><strong>Tips to learn Pandas</strong></p><ul><li>Explore the existing datasets in the Pandas library and play with basic functions like viewing the DataFrame, sorting it, preprocessing it, and then exporting it to files like CSV, JSON, or text files.</li><li>Read data from different file extensions like CSV, excel sheets, JSON, and Text files, apply processing and data analysis techniques, and then save the processed data to that file.</li><li>Use Pandas&#39; built-in plot functions to see what support for data plotting it provides.</li></ul><p><strong>Resources to follow and learn Pandas:</strong></p><ul><li><a href="https://pandas.pydata.org/docs/">Pandas official documentation</a></li><li>Book: <a href="https://amzn.to/3DyLaJc">Python for Data Analysis</a></li><li><a href="https://www.enjoyalgorithms.com/blog/introduction-to-pandas/">Summary of Pandas&#39; useful functions</a></li></ul><h4>Matplotlib</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FdQ1Yza2KDK4V-Yb.png" /></figure><p>Matplotlib is a popular Python library that plots curves for various data types, training, performance analysis, and visualization. This library helps make informed decisions about the data or processes required for better training. It is one of the most used libraries by data scientists or analysts working in this industry and acts as the base for other visualization libraries like <a href="https://www.enjoyalgorithms.com/blog/introduction-to-seaborn-library-in-python/">Seaborn</a>, which applies beautification to the matplotlib plots.</p><p><strong>Tips to learn Matplotlib</strong></p><ul><li>Start with simple plots of visualizing the relationship between two simple lists or arrays.</li><li>Try various data analysis techniques on different datasets and plot curves like histograms, pie charts, bar graphs, scatter plots, and box plots. Please also understand the meaning of these plots because that will improve the graphical reading ability.</li><li>Plot 3D scatter plots to visualize the higher dimensional datasets.</li></ul><p><strong>Resources to follow and learn Matplotlib:</strong></p><ul><li><a href="https://matplotlib.org/stable/tutorials/index.html">Matplotlib official documentation</a></li><li><a href="https://www.enjoyalgorithms.com/blog/introduction-to-matplotlib/">Introduction to Matplotlib with popular plots</a></li></ul><h4>Scikit-Learn</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/0*12_COVroNLP-B4uf" /></figure><p>Scikit-learn is the one-stop library for many Machine Learning beginners and professionals. It provides a lot of functionalities, including dummy data to practice ML, preprocessing modules, a wide range of pre-defined ML algorithms, and support for training evaluation and deployment. Earlier libraries like Pandas and Numpy were not providing additional support mentioned before. In our list of required ML libraries, Scikit-Learn is the only library capable of doing all the things involved in building end-to-end ML pipelines.</p><p>It is an open-source library primarily built over Scipy, Numpy, and Matplotlib libraries, which gives it the additional advantage of speedy training and evaluation. It also provides the support to visualize the complete model development pipeline, which includes the stages like how the data will be received, processed, fed to the model, training occurs, evaluation happens, and results are published.</p><p><strong>Tips to learn Scikit-Learn</strong></p><ul><li>Scikit-Learn is a huge library, and learning all at once would not be preferable. Hence, using the functions when we need them while building model development pipelines would be better.</li><li>Observe the difference between the execution time of ML algorithms when developed from scratch and Scikit-learn&#39;s inbuilt function. It will give a better understanding of how much these libraries help by making the execution fast.</li><li>Use label encoding methods present in Scikit-learn to convert the non-numerical features into numerical values. This saves a lot of time in the case of large datasets.</li><li>Try to load some datasets → preprocess them → use label encoders if required → normalize data features → play with dimensionality reduction techniques → try algorithms to train → visualize the performance of the trained model → Create the complete pipeline and visualize it.</li></ul><p><strong>Resources to follow and learn Matplotlib:</strong></p><ul><li><a href="https://scikit-learn.org/stable/user_guide.html">Scikit-learn official documentation</a></li><li><a href="https://github.com/scikit-learn/scikit-learn">GitHub Codebase of Scikit-learn</a></li><li><a href="https://www.enjoyalgorithms.com/blog/introduction-to-scikit-learn/">Important functions in Scikit-learn</a></li></ul><p>Although more libraries help learn Machine Learning and will be used while developing specific models.</p><h4>Conclusion</h4><p>The complete knowledge of these five libraries, Numpy, Scipy, Pandas, Matplotlib, and Scikit-learn, will be considered a good starting point for beginners. We have prepared this list based on the requirements to build Machine Learning applications shown in <a href="https://www.enjoyalgorithms.com/machine-learning-courses/">this ML Course</a>. Other libraries like TensorFlow, Keras, PyTorch, and Theano were good candidates for this list, but they are mainly used for developing Deep Learning algorithms. We hope you enjoyed the article.</p><p><strong>Enjoy Learning!</strong></p><h4><a href="https://www.enjoyalgorithms.com/live-machine-learning-course/">16 Week Live Project-Based ML Course: Admissions Open</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db9d7f433626" width="1" height="1" alt=""><hr><p><a href="https://medium.com/enjoy-algorithm/popular-python-libraries-in-machine-learning-db9d7f433626">Popular Python Libraries In Machine Learning</a> was originally published in <a href="https://medium.com/enjoy-algorithm">EnjoyAlgorithms</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Starting Machine Learning Journey At Different Career Levels]]></title>
            <link>https://medium.com/enjoy-algorithm/starting-machine-learning-journey-at-different-career-levels-1f933c5ceeec?source=rss-83050f0803ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f933c5ceeec</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[careers]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Ravish Kumar]]></dc:creator>
            <pubDate>Mon, 29 Jan 2024 03:19:16 GMT</pubDate>
            <atom:updated>2024-01-30T03:35:35.686Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2nH4-iMWzxMa9_Xpi1LkkQ.png" /></figure><p>With the recent trend of Generative AI and Large Language Models (LLMs), everyone is considering joining the field of Machine Learning as it will be the future. Whether one is a college student, a top-tech manager, or even a leader in the tech industry, everyone can be seen talking about AI and studying it by following the same approach. But, is it true that at any career level, one needs to follow the same pathway of learning ML?</p><p>Even before that, does everyone need to know the ML to survive the recent recession in the tech industry? This was one of the most discussed topics among people working in the software industry. It is always worthwhile to be updated with the recent changes in the tech industry, but it is not always true to start doing hands-on or solving all the problems using AI. This blog will discuss how learners at different career levels should prepare themselves for starting the ML journey with step-wise strategies.</p><h4>College Students</h4><p>Machine Learning is not limited to any specific branch these days. It can solve tasks in the construction industry, machine manufacturing, and even pharmaceuticals. Hence, every college student, irrespective of their branches, should know the basics of ML to think of out-of-the-box solutions to some long-unsolved problems or replace traditional approaches to make the system more robust.</p><p>During college days, students can start investing a small amount of time in this order:</p><ul><li><strong>Step 1: </strong>Start with Python programming language.</li><li><strong>Step 2:</strong> Learn the Basics of Data Structures and Algorithms</li><li><strong>Step 3:</strong> Learn the Basics of Machine Learning</li><li><strong>Step 4:</strong> Start playing with open-source datasets</li><li><strong>Step 5:</strong> Exploratory Data Analysis</li><li><strong>Step 6:</strong> Machine Learning Techniques, libraries, and frameworks</li><li><strong>Step 7:</strong> ML Algorithms along with Big Project, including deployment.</li></ul><p>If you want detailed step-wise guidance for starting the machine learning journey, please read this blog: <a href="https://www.enjoyalgorithms.com/blog/how-to-start-machine-learning-journey-a-step-by-step-guidance/">How to start ML journey step-by-step guidance</a>.</p><h4>Software Interns</h4><p>Internships in tech firms are an opportunity to express the industry potential and excel in the field. During their internship, many students or professionals focus on solving the given problem statement via one of the methods, mostly traditional. But in actuality, they can start solving the given problem statement and keep learning and thinking if another way exists to solve it.</p><p>My ML journey also started during my internship at KPIT Technologies, where I used the Learning by doing philosophy. It is the best approach to strengthen any tech stack in the computer science domain. The learning strategy changes slightly, and we follow a parallel approach to Learning.</p><p>Interns can keep solving the given industry problem statement and simultaneously searching if some solution involving AI or ML exists. If they find some, it&#39;s a good hint that a possibility of integration exists. They can start learning ML basics and check where those theoretical aspects benefit them in the AI integration.</p><p><strong>Steps to follow for interns to start their ML journey:</strong></p><ul><li><strong>Step 1:</strong> Search for existing AI solutions and how they can be utilized to solve the given industry problem statement.</li><li><strong>Step 2: </strong>Start with the basics of ML if you already know the basics of programming and DSA, and think about where exactly they can find the use of theory in solving the given problem statement using AI.</li><li><strong>Step 3: </strong>Finding the complete end-to-end solution using AI is not always true. Even if AI can be used to solve only a part of the complete problem statement, move towards integrating that.</li></ul><p>Usually, these out-of-the-box solutions help you grab attention and pre-placement offers in the respective firms. Learning by doing strategy is also mentioned in the blog <a href="https://www.enjoyalgorithms.com/blog/how-to-start-machine-learning-journey-a-step-by-step-guidance/">here</a>.</p><h4>Early Freshers</h4><p>Freshers in any industry can think of learning ML and AI as their companions in solving challenging problems. During early career, most employees try to deliver whatever is assigned to them. However, with the knowledge of AI and ML, they can propose additional solutions to their employer or suggest alternative methods to a part of the solution and achieve robust performance.</p><p>This way of approaching any problem statement will enhance the collaboration opportunities, and they can even be capable of working in the core AI ML field. The best way to learn ML for freshers would be to start from the basics of Machine Learning like:</p><ul><li>What is ML, and where exactly is it used?</li><li>What are the various applications of ML in the tech industry?</li><li>How can ML be used in the domains they are currently working in, and how can AI solve their traditional problems?</li></ul><p>Based on these questions, they can attend specific research paper conferences and seminars and participate in Hackathons after doing hands-on with basic ML projects falling in their domains. Examples of some popular applications of Machine Learning across broader technical domains are:</p><ul><li><strong>ML in agriculture: Predicting: </strong><a href="https://www.enjoyalgorithms.com/blog/soil-fertility-prediction-using-ml">Soil fertility prediction</a></li><li><strong>ML in medical science: </strong><a href="https://www.enjoyalgorithms.com/blog/cancer-classification-using-machine-learning">Cancer Classification</a></li><li><strong>ML for security: </strong><a href="https://www.enjoyalgorithms.com/blog/credit-card-fraud-detection-using-machine-learning">Credit card fraud detection</a></li></ul><h4>Experienced Professionals</h4><p>After a lengthy discussion with many industry professionals, we discovered that most are willing to switch careers into AI. Still, they do not have time to invest in preparing for interviews and reading Machine Learning by giving extra time.</p><p>It is not true that to use AI, you always need to be directly present in firms that only focus on AI products like LLMs in Amazon Alexa, Google&#39;s DeepMind, or Tesla&#39;s Neuralink. They need to focus on applying the existing AI techniques to solve their general problems. Even before that, they first need to know whether the problem domain they are working on requires AI support.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Iztd9umoDk_BPI-SDc04bA.png" /></figure><p>Professionals need to consider AI a supporting technique to solve existing problems quickly. AI itself is nothing, but AI + X is a complete solution where X can be any business domain, like medical science, software engineering, rocket science, space programs, or anything else.</p><p>Experienced professionals can start using AI or integrating AI solutions into their existing problems and, in parallel, start reading the basics of Machine Learning. This is opposite to what we saw in the case of college students, but for experienced professionals,</p><h4>Tech Managers</h4><p>Technical managers are responsible for completing any system&#39;s pipeline; hence, they are overloaded with deliverables. However, with the tight schedule, the scope of innovation becomes limited. In such cases, tech managers need to consider which sub-modules in the pipeline can be solved via newer approaches, including AI. This can improve the robustness of the overall system. Usually, the team follows the instructions of tech managers, which adds to the responsibility of tech managers to provide initial insights on the solution.</p><p>But to understand and propose solutions, tech managers should be aware of the applications of Machine learning and AI specifically used in each of the modules in the pipeline. Technical managers should know more than the basics of ML, as when the team members are stuck somewhere, they need to guide them regarding some additional improvements like:</p><ol><li>Applying feature engineering for better insights</li><li>Introducing regularizers to reduce overfitting</li><li>Designing key evaluation metrics to test the performance of the developed model.</li><li>What possible algorithms will be best suited for the given problem statement?</li><li>How to solve the challenges</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uytwBpS1fOQoFSD8S1UNiQ.png" /></figure><h4>Tech Leaders, including CEOs and CTOs</h4><p>Tech Leaders attend many different seminars and business meetings where they listen to several projects and research papers. Leaders usually participate in these meetings to understand the business use case and find potential integrations into their platforms. Similarly, researchers showcase the potential of their products in a full-fledged manner with a lot of insights and technicalities.</p><p>Leaders should be aware of the terminologies, techniques, and potential business use cases in such cases. Leaders should know the fundamentals like</p><ul><li>What is Machine Learning, and how is it different from AI?</li><li>What data infrastructure is present in the firm, and how can they utilize the existing data to perform Business Analytics?</li><li>The knowledge about the classification of ML models on the basis of Input data: Supervised, Unsupervised, Semi-Supervised, and Reinforcement Learning.</li><li>The knowledge about the classification of ML models on the basis of the nature of the problem statement: Classification, Regression, and Clustering.</li><li>Whether they need to spend money on making data labeled or not?</li><li>How do various ML algorithms work from a theoretical angle? Leaders may not be doing directly hands-on, but they will be able to suggest possible directions to explore.</li></ul><h4>Conclusion</h4><p>Machine Learning is one of the most demanding topics in the software industry, and people at all career stages want to learn it. The learning journey of Machine Learning can vary as per the individual requirements at various career stages, which is discussed in this blog. It outlines how a beginner at the career stages of 1. A student, 2. Intern 3. Early fresher, 4. Experienced professions, 5. Tech managers, and 6. Tech leaders can utilize the best way of Learning and learn this technology faster.</p><p><strong>Enjoy Learning!</strong></p><h4><a href="https://www.enjoyalgorithms.com/live-machine-learning-course/">16 Week Live Project-Based ML Course: Admissions Open</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f933c5ceeec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/enjoy-algorithm/starting-machine-learning-journey-at-different-career-levels-1f933c5ceeec">Starting Machine Learning Journey At Different Career Levels</a> was originally published in <a href="https://medium.com/enjoy-algorithm">EnjoyAlgorithms</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Most Asked Interview Questions In Machine Learning]]></title>
            <link>https://medium.com/enjoy-algorithm/most-asked-interview-questions-in-machine-learning-f7fdafd63e81?source=rss-83050f0803ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7fdafd63e81</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Ravish Kumar]]></dc:creator>
            <pubDate>Thu, 05 Jan 2023 12:25:07 GMT</pubDate>
            <atom:updated>2024-01-29T17:51:33.466Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T433tgvXuyhbAlUUZFNvnw.png" /></figure><p>Machine Learning and Data Science are two trending areas in computer science where people want to build a career. However, the preparation for this interview is non-conventional. If you go through several Machine Learning interview experiences, you will realize that there is a pattern in which these questions are being asked. In this article, we will discuss that pattern in greater detail.</p><p>Before jumping into the interview questions of Machine Learning interviews, let&#39;s discuss what possible things one can do to reach this interview stage. The total number of persons sitting in ML interviews is increasing tremendously. Hence, we need to do something different to help us stand out in the crowd.</p><p>Based on the experiences shared by ML professionals, the only thing that attracts the attention of technical recruiters is your hands-on experience with Machine Learning. One can commonly find information about the course completion, which is good, but that does not reflect that you can solve industrial ML problems. Hence, we advise gaining some hands-on ML experience by implementing online projects to know precisely how the ML system works.</p><p>There is a reason for discussing projects because it is the entry for the funnel of ML interview questions. Recruiters generally start asking about the steps involved in any project and finally land on some trivial questions, which will be discussed later in the blog.</p><p><strong>Let&#39;s divide all the types of ML interview questions into two unique categories:</strong></p><ol><li><strong>Project Specific</strong>: Starting of the funnel</li><li><strong>Generic Questions</strong>: a bucket of basics</li></ol><p>And the golden rule is: Funnel connects the bucket. Let&#39;s discuss the first type.</p><h3>Project Specific</h3><p>One needs to ensure that the project&#39;s objective and results should be mentioned in the resume. There can be very specific questions about the project&#39;s aim, like why this project and what you achieved. We will discuss some of the most asked questions here, and one can generalize and find their version of questions. Generally, interviewers are less interested in what you have &quot;done&quot; in your ML project; clearly mentioning the &quot;achievement/s&quot; will be beneficial.</p><p>Let&#39;s take an example project and discuss the questions related to that in greater detail. We will use an email spam classification project, and step-wise implementation can be found in EnjoyAlgorithms&#39; <a href="https://www.enjoyalgorithms.com/blog/email-spam-and-non-spam-filtering-using-machine-learning/">Email Spam and Non-spam Filtering using Machine Learning</a> blog.</p><h4>Why did you choose the Email spam classification project?</h4><p>Today&#39;s era is online, and with the increase in online usage, there comes security. Per the survey, one of the easiest ways of reaching people is via email, as the email addresses are publicly available and even sold on some platforms. Hence, tech giants like Google and Microsoft use better spam categorization algorithms to keep their users safe. I wanted to explore this capability of ML and went ahead with this project.</p><h4>Explain the pipeline of your project.</h4><p>I/we (depending on the number of persons involved) collected an open-source dataset from Kaggle to demonstrate the capability of ML to classify incoming emails into Spam and non-spam categories. Once the data was collected, I/we did a thorough analysis and pre-processing. After the data processing, I/we separated the dataset into three sets: Train, Validation, and Test. Finally, we selected the KNN algorithm to fit the model on the train data and checked the performance on the test dataset.</p><p><strong>Note: </strong>This is the crucial step in the interview and can be considered the node of starting discussions. The interviewer can focus on any steps mentioned in the project pipeline. Hence, one needs to be concise and know every step precisely. One can explore the ML project pipeline in EnjoyAlgorithms&#39; blog <a href="https://www.enjoyalgorithms.com/blog/pathway-for-machine-learning-projects/">Step by Step Pathway to Implement Machine Learning Projects</a>.</p><h4>Explain the dataset you used for this project.</h4><p>I/We used an open-source dataset for this project where 57% of all emails belonged to the Spam category, and the remaining 43% were in the non-spam (ham) category. The biggest challenge here was to find/form a dataset that can have significant Non-spam category mails, as people avoid sharing personal emails because of data privacy concerns.</p><p>As the dataset is in text format, I/we applied text-preprocessing techniques like word tokenization of the emails, removal of stop-words, stemming the words, extracting relevant features out of it, and finally, encoding text into word-vector format to make machines understand the text.</p><p><strong>Note: </strong>Now, the questions will go in a very specific zone, like explaining what word tokenization is, what stemming algorithm you used, what techniques you used for word-vector encoding, etc. We would recommend seeing these blogs to find the detailed answers to these questions:</p><ul><li><a href="https://www.enjoyalgorithms.com/blog/text-data-pre-processing-techniques-in-ml/">Pre-processing of text data</a></li><li><a href="https://www.enjoyalgorithms.com/blog/word-vector-encoding-in-nlp/">Word Vector Encoding</a></li></ul><p>If the project is based on structured data, please have a look at these blogs to find answers to the questions that can be asked on your dataset,</p><ul><li><a href="https://www.enjoyalgorithms.com/blog/data-pre-processing-for-machine-learning/">Data Pre-processing of structured data</a></li><li><a href="https://www.enjoyalgorithms.com/blog/structured-data-pre-processing-hands-on/">Hands-on data Methods for pre-processing of structured data</a></li></ul><h4>What percentage of data was used for training the machine learning model?</h4><p>I/We split the processed dataset into three sets: the train containing 80% of the data, validation containing 10%, and the test including the remaining 10%. I/We chose this combination as the model demanded this much dataset to provide the expected performance.</p><h4>Which algorithm did you use to train using this dataset?</h4><p>I/We used KNN (K-Nearest Neighbours) for this project.</p><h4>What is the KNN algorithm?</h4><p>KNN stands for K-Nearest Neighbor, a supervised learning algorithm that can solve <a href="https://www.enjoyalgorithms.com/blogs/classification-and-regression-in-machine-learning/">classification and regression problems</a>. It provides a non-parametric solution for our problem statements. It involves the selection of hyperparameter k, which states how many neighbors we want to consider to decide the property of any given sample. KNN is deemed the first ML algorithm and is very popular in the ML industry.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1Pjyi4Y3yCgCAfdD" /></figure><p><strong>Note:</strong> Please read the blog on the <a href="https://www.enjoyalgorithms.com/blog/k-nearest-neighbours-in-ml/">KNN algorithm</a> to know more details about this algorithm. Each word spoken in the interview can lead our interview in that direction. One can use this trick to control any interview&#39;s direction, which is the art that will come with confidence. For example, while answering what KNN is, we stated that it is a non-parametric solution. We could have skipped this line if we did not know the non-parametric solution.</p><h4>There are more sophisticated algorithms, so why KNN?</h4><p>We only know which algorithm will fit our requirements in ML once we try different algorithms. For our project, we started with the most basic algorithm, KNN. Indeed, I/we could have used alternate algorithms like <a href="https://www.enjoyalgorithms.com/blog/random-forest-in-ml/">Random Forests</a> and <a href="https://www.enjoyalgorithms.com/blog/xg-boost-algorithm-in-ml/">XG-Boost</a>, as they are more sophisticated. Still, these algorithms bring complexity, and I found the explainable nature of KNN more fascinating. Hence, I went ahead with KNN.</p><h4>What cost function did you use for this project?</h4><p>As this is a classical binary classification problem, I/we used the standard binary cross-entropy as our cost function for this project.</p><p><strong>Note:</strong> For ML projects, designing the appropriate cost function is crucial; hence, we must know what exactly we used in our project.</p><h4>Which optimization technique did you use for this project?</h4><p>I/We used the default optimization technique of gradient descent in the KNN algorithm. We could have tried playing with different techniques, but GD gave us the desired performance.</p><h4>What performance metric did you use to evaluate your model?</h4><p>The email classification problem is a classification problem; hence, accuracy as the evaluation metric was acceptable. But I/we found some research papers that said we can not always rely on accuracy parameters. Therefore, I/We evaluated the model using four <a href="https://www.enjoyalgorithms.com/blog/evaluation-metrics-classification-models/">evaluation metrics for classification models</a>: Accuracy, precision, sensitivity, and specificity.</p><p><strong>Note:</strong> Please ensure you know each term mentioned in the above question. If you are still getting familiar with any of the terms or less confident, do not say that you used that metric.</p><h4>What was the accuracy of your model?</h4><p>With <a href="https://www.enjoyalgorithms.com/blog/k-nearest-neighbours-in-ml/">KNN</a>, I/we achieved 92% accuracy for our model. The reference paper we used claimed to have 95% accuracy, but they used a different algorithm and a custom dataset that they generated with the annotation engineers&#39; help.</p><p><strong>Note: </strong>This question will definitely come, as that&#39;s how we know how good a model is. You need to mention the target you wanted to achieve and what did you achieve.</p><h4>How can you improve the performance further?</h4><p>There can be multiple ways to do so. Some of them are:</p><ol><li>Use more advanced algorithms, like XG-Boost and Neural Networks.</li><li>Use of a broader dataset that can help the model learn more unseen cases.</li></ol><h4>What was the conclusion of this project?</h4><p>I/We saw the capability of Machine Learning in providing security from phishing threats, and it did the job smartly. This model could have been improved and can be deployed later to check the performance on similar datasets.</p><p>This would be our final question on project-specific categories. It is not true that basic questions will only be asked when the project-specific questions end. Interviewers can use the topics mentioned during the answers to project-specific questions and ask basic related to those topics. Let&#39;s list down some standard generic questions as well.</p><h3>Generic Questions</h3><h4>What are the various challenges that you faced in your project?</h4><p>One bigger challenge was to get balanced data to provide equal numbers of Spam and non-spam category emails. People avoid sharing non-spam emails but easily share spam emails because of privacy concerns. To resolve this issue, I/we removed spam emails so our model doesn&#39;t get biased.</p><p><strong>Note: </strong>This question is trendy in ML interviews. If you have done something yourself, you must have faced difficulty and a way to resolve that. Interviewers want to know how you tackled the hurdles.</p><h4>What is the Bias-variance tradeoff?</h4><p>The prediction error given by any Machine Learning model can be represented as Error = Bias² + Variance + Irreducible_error. To reduce this error, we want both bias and variance lower. But when we reduce the biases in our model, variance increases and vice-versa. This is popularly known as the Bias-Variance tradeoff.</p><p><strong>Note: </strong>This question is asked in 9 out of 10 ML interviews. Please see the <a href="https://www.enjoyalgorithms.com/blog/bias-variance-tradeoff-in-machine-learning/">Bias-variance tradeoff</a> blog for a more detailed answer.</p><h4>What are underfitting and overfitting?</h4><p>Underfitting and overfitting are two problems that can affect the model&#39;s performance. In underfitting, the model does not perform well on training data, or we can say that the model fails to learn complex patterns in the dataset. This problem can be solved by</p><ul><li>Increasing the complexity of the algorithm so that it starts learning more patterns.</li><li>Engineering more features so the model understands the true relationship between dependent and independent variables.</li></ul><p>In overfitting, the model learns too much from training data and needs to generalize the learning on unseen test set samples. Overfitting can be solved by:</p><ul><li>Decreasing the complexity of the model as it is learning too much.</li><li>Increasing data samples so the model gets exposed to more unseen patterns for better generalizability.</li><li>Applying regularization techniques.</li></ul><p><strong>Note: </strong>This is one of the most critical questions in ML interviews. We recommend seeing <a href="https://www.enjoyalgorithms.com/blog/regularization-in-machine-learning/">this blog</a> to understand the detailed mathematics of how regularization solves overfitting problems.</p><h4>What is regularization, and can you name some famous regularization techniques?</h4><p>Regularization is a technique used to reduce the overfitting problem of the model. Some famous regularization techniques are L1, L2, and dropout regularization.</p><p><strong>Note: </strong>The difference between L1 and L2 regularization and the working of dropout regularization techniques are some of the most frequently asked topics in interviews. Please read the blog on <a href="https://www.enjoyalgorithms.com/blog/regularization-in-machine-learning/">regularization techniques</a> for more details.</p><h4>What is a cost function in Machine Learning?</h4><p>A cost function represents the problem statement we want to solve using Machine Learning as an optimization problem. Machines try to reduce the error between the predicted and the actual value for any input sample. We have finite samples to train, which becomes our cost function when we average the errors over all the samples.</p><p><strong>Note: </strong>Read the blog on <a href="https://www.enjoyalgorithms.com/blog/loss-and-cost-functions-in-machine-learning/">cost functions used in Classification and Regression problems</a> to know the details. This question is fundamental and can justify your grip on machine learning.</p><h4>What is the difference between Supervised and Unsupervised learning?</h4><p>In Supervised learning, machines know the input and corresponding output and then try to map the function for input and output pairs. Some popular algorithms for Supervised learning are <a href="https://www.enjoyalgorithms.com/blog/linear-regression-in-machine-learning/">Linear regression</a>, <a href="https://www.enjoyalgorithms.com/blog/logistic-regression-in-ml/">Logistic Regression</a>, <a href="https://www.enjoyalgorithms.com/blog/decision-tree-algorithm-in-ml/">Decision Trees</a>, etc.</p><p>In Unsupervised learning, machines only know the input and map functions to bring similar samples together. Some popular algorithms for Unsupervised learning are Principal Component Analysis, k-means clustering, etc.</p><p><strong>Note:</strong> Please see the <a href="https://www.enjoyalgorithms.com/blogs/supervised-unsupervised-and-semisupervised-learning/">Supervised vs. Unsupervised Learning</a> blog for a more detailed description.</p><h4>What is Stemming, and how is it different from lematization?</h4><p>Stemming is a technique in data pre-processing used for text data. Using this technique, we bring words into their native form by removing common suffixes and prefixes added to the word. For example, Interchanging will be converted to interchang. There are some pros and cons related to this technique; pros: The complexity of these algorithms is less, and hence execution becomes faster. Cons: These algorithms do not preserve the true meaning of the words before slicing.</p><p>On the other hand, Lemmatization also reduces the words to their native form, preserving their true meaning. The complexity of these algorithms is higher; hence, it is only used when the dataset is small.</p><p><strong>Note: </strong>This question is placed here because our data is in textual format, and you can expect more such questions on data pre-processing of text data.</p><h4>Explain the working of the Gradient Descent Algorithm.</h4><p>Gradient Descent is an optimization technique used to optimize the cost functions in Machine Learning. Machines try various sets of parameters and try to find which sets of parameters produce the least cost function and store corresponding parameters in the form of learning. GD speeds up the process of finding these sets of parameters using calculus and states that where the cost function gradient is zero, the cost will be either minimum or maximum. But we design the cost function to include only minima; hence, it drives the updates of the parameters in those portions where the gradient approaches zero.</p><p><strong>Note: </strong>Please read the blog on <a href="https://www.enjoyalgorithms.com/blog/parameter-learning-and-gradient-descent-in-ml/">Gradient Descent</a> for more details, along with the algorithm&#39;s Pseudocode.</p><figure><img alt="Incorrect and correct implementation of GD" src="https://cdn-images-1.medium.com/proxy/1*cKKAIVnQ_Wa22i_RELyhOQ.jpeg" /></figure><h4>Conclusion</h4><p>This article discussed how machine learning interviews progress and how to deal with the questions asked. We discussed how interviewers link project-specific questions mentioned in our resumes to the basics of machine learning. This blog is designed based on several real interview experiences. We hope you enjoyed the article.</p><p><strong>Enjoy Learning!</strong></p><h4><a href="https://www.enjoyalgorithms.com/live-machine-learning-course/">16 Week Live Project-Based ML Course: Admissions Open</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7fdafd63e81" width="1" height="1" alt=""><hr><p><a href="https://medium.com/enjoy-algorithm/most-asked-interview-questions-in-machine-learning-f7fdafd63e81">Most Asked Interview Questions In Machine Learning</a> was originally published in <a href="https://medium.com/enjoy-algorithm">EnjoyAlgorithms</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Top Machine Learning Projects With Python Code]]></title>
            <link>https://medium.com/enjoy-algorithm/top-machine-learning-projects-with-python-code-c83d937050c9?source=rss-83050f0803ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/c83d937050c9</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[supervised-learning]]></category>
            <dc:creator><![CDATA[Ravish Kumar]]></dc:creator>
            <pubDate>Thu, 15 Dec 2022 06:45:39 GMT</pubDate>
            <atom:updated>2024-01-30T03:23:12.325Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C73tCMEx6BenrqQGhH-Bgw.png" /></figure><p>Machine learning is gaining tremendous demand in the software industry, and this is not only from the recruiter side. In the upcoming placement sessions, many freshers have started targeting ML or the Data Science industry for three primary reasons: 1. Higher package 2. Smart work 3. Future stability.</p><p>However, the central issue in getting the resume shortlisted by ML companies is that they seek projects in Machine Learning and Data Science. Some companies use ML algorithms to shortlist resumes with ML projects automatically. So, in this article, we will list some popular projects that can be mentioned in the resumes to increase the chances of getting shortlisted for ML interviews. All these projects are in Python; hence, you are advised to revise the <a href="https://www.enjoyalgorithms.com/blog/basic-python-for-ml-data-science/"><strong>fundamentals of Python</strong></a>. Also, ML projects need a proper pipeline for smooth completion; therefore, one can look at the <a href="https://www.enjoyalgorithms.com/blog/pathway-for-machine-learning-projects/"><strong>guide to building an ML projects</strong></a> blog.</p><p>We will categorize these projects into two major categories: 1. Supervised learning projects and 2. Unsupervised learning projects. Further, these big categories can be divided into smaller sub-categories based on the nature of input data. One can learn this categorization separately inside the blog of <a href="https://www.enjoyalgorithms.com/blog/classification-of-machine-learning-models/"><strong>Classification of Machine Learning models on five different bases</strong></a><strong>.</strong></p><h3>Supervised Learning Projects</h3><p><a href="https://www.enjoyalgorithms.com/blogs/supervised-unsupervised-and-semisupervised-learning/"><strong>Supervised Learning</strong></a> is a type of Machine Learning where machines learn to map a mathematical function between &#39;known&#39; input and &#39;known&#39; output variables. It can be further classified into two major sub-categories based on the nature of the input data: 1. Classification Projects 2. Regression Projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*7TZAHYOzx-gTHGvZG8X1iw.png" /></figure><h4>‣ Classification Projects</h4><p><a href="https://www.enjoyalgorithms.com/blogs/classification-and-regression-in-machine-learning/"><strong>Classification</strong></a> is a type of Supervised Learning where the &#39;known&#39; output is categorical or qualitative data. For example, classifying emails into Spam and non-spam categories. One can learn about all types of data in the <a href="https://www.enjoyalgorithms.com/blog/data-pre-processing-for-machine-learning/"><strong>Data Pre-processing of Structured Data in Machine Learning</strong></a> blog.</p><h4>• <strong>Projects with Structured Data</strong></h4><p>Structured datasets contain a well-defined structure and are generally stored in Excel or CSV formats. These datasets require <a href="https://www.enjoyalgorithms.com/blog/data-pre-processing-for-machine-learning/"><strong>data Pre-processing of structured data</strong></a> before feeding it into the machine learning model. Classification projects with structured data are:</p><h4>1. <a href="https://www.enjoyalgorithms.com/blog/cancer-classification-using-machine-learning/">Cancer Classification using Machine Learning</a></h4><p>Cancer classification is one of the classical projects and a part of every curriculum on Machine Learning. This project uses <a href="https://www.enjoyalgorithms.com/blog/support-vector-machine-in-ml/"><strong>SVM</strong></a> (Support Vector Machines) to classify the cells as malign and benign based on the fluid&#39;s properties. One shall include this course to gain attention from companies working with medical diagnoses.</p><p>Here is the <a href="https://github.com/enjoyalgorithms/Machine-learning-project-code/blob/main/industry_projects/cancer%20prediction/Cancer_prediction.ipynb"><strong>complete code for the cancer classification project</strong></a><strong>.</strong></p><h4>2. <a href="https://www.enjoyalgorithms.com/blog/how-uber-use-machine-learning/">Uber Surge Price Calculator</a></h4><p>Uber is not a taxi provider company; it&#39;s a Machine Learning company. It uses ML technology to upscale the business in almost all its verticles. This project lists ML usage by Uber and demonstrates one of the use cases of calculating the surge price multiplication factor. Cab service companies decide the fare between the origin and destination locations using this surge multiplication factor based on the cab demand. This project uses the <a href="https://www.enjoyalgorithms.com/blog/random-forest-in-ml/"><strong>Random Forest algorithm</strong></a> for this demonstration.</p><p>Here is the <a href="https://github.com/enjoyalgorithms/Machine-learning-project-code/blob/main/industry_projects/Uber%20Serge%20Price/Uber_surge_multiplier_prediction.ipynb"><strong>complete code for the Uber surge multiplier prediction project</strong></a><strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*N3r7VBhBr1XfHGEuWGV_pg.png" /></figure><h4>3. <a href="https://www.enjoyalgorithms.com/blog/pubg-cheater-detection-system-using-ml/">PUBG Cheater Detection Using ML</a></h4><p>PUBG, also known as BGMI, is a top-rated online mobile game among the youth. As the game is online, there are high chances of encountering cheaters/hackers, which can adversely affect growth. Hence, companies use advanced ML techniques to detect the presence of cheaters in the battleground and suspend their accounts. This project uses the <a href="https://www.enjoyalgorithms.com/blog/random-forest-in-ml/"><strong>Random Forest algorithm</strong></a> to detect the cheaters in the PUBG game.</p><p>Here is the <a href="https://github.com/enjoyalgorithms/Machine-learning-project-code/blob/main/industry_projects/PUBG%20Cheater%20Detection/PUBG_cheater_detection.ipynb"><strong>complete code for the PUBG cheater detection project</strong></a><strong>.</strong></p><h4>• Projects with Unstructured Data</h4><p>Unstructured datasets do not contain any predefined structure in them. Some famous examples of these datasets are Audio signals, text documents, and Images. Textual datasets require <a href="https://www.enjoyalgorithms.com/blog/text-data-pre-processing-techniques-in-ml/"><strong>text data pre-processing</strong></a> and then <a href="https://www.enjoyalgorithms.com/blog/word-vector-encoding-in-nlp/"><strong>word-vector encoding</strong></a><strong> </strong>to make machines understand this data. Classification projects with unstructured data are:</p><h4>‣ Projects having text data involvement are:</h4><h4>1. <a href="https://www.enjoyalgorithms.com/blog/email-spam-and-non-spam-filtering-using-machine-learning/">Email Spam, non-spam filtering using Machine Learning</a></h4><p>Mailing companies like Gmail, Outlook, and Yahoo are heavily investing in their technology to provide security to their users. One possible method is segregating spam emails automatically to avoid phishing attacks. This project demonstrates the capability of Machine learning in the cyber-security domain, where the ML model classifies emails into Spam and non-spam categories based on internal textual content. It uses the <a href="https://www.enjoyalgorithms.com/blog/k-nearest-neighbours-in-ml/"><strong>KNN classifier</strong></a> for this task.</p><p>Here is the <a href="https://github.com/enjoyalgorithms/Machine-learning-project-code/blob/main/industry_projects/email%20spam%20non-spam/email_spam_detection.ipynb"><strong>complete code for the email spam classification project</strong></a><strong>.</strong></p><figure><img alt="spam email filtering using machine learning image 8" src="https://cdn-images-1.medium.com/proxy/1*LN171f2gTlLAPK-YN9oA_Q.png" /></figure><h4>2. <a href="https://www.enjoyalgorithms.com/blog/sentiment-analysis-using-naive-bayes"><strong>Twitter Sentiment Analysis</strong></a></h4><p>Sentiment analysis is a machine learning technique companies use to understand the sentiment of their customers. Customers write online reviews, and companies classify these reviews as positive, negative, and neutral. This project is trendy in Machine Learning and is considered one of the best projects to work with text data. The referred blog uses the <a href="https://www.enjoyalgorithms.com/blog/naive-bayes-in-ml"><strong>Naive Bayes</strong></a> algorithm to predict the sentiment of Twitter users via tweets.</p><p>Here is the <a href="https://github.com/enjoyalgorithms/Machine-learning-project-code/blob/main/industry_projects/sentiment-analysis-naive-bayes/Sentiment_Analysis.ipynb"><strong>complete code for the Twitter Sentiment Analysis project</strong></a><strong>.</strong></p><h4>‣ Projects having Image data involvement are:</h4><h4>1. <a href="https://www.enjoyalgorithms.com/blog/optical-character-recognition-using-logistic-regression/">Optical Character Recognition</a></h4><p>OCR (Optical Character Recognition) is one of the most innovative uses of Machine Learning in the real world. Many companies, including tech giants Microsoft and Google, are utilizing the benefits of recognizing characters from text documents. This project demonstrates how a simple linear model of <a href="https://www.enjoyalgorithms.com/blog/logistic-regression-in-ml/"><strong>Logistic Regression</strong></a> can recognize handwritten characters after learning from the famous MNIST dataset.</p><p>Here is the <a href="https://github.com/enjoyalgorithms/Machine-learning-project-code/blob/main/industry_projects/optical-character-recognition/optical-character-recognition-logistic-regression.ipynb"><strong>complete code for the Handwritten Digit Recognition project</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*MsAeXV3ANU2IWoG0EQRhYw.png" /></figure><h4>‣ Regression Projects</h4><p><a href="https://www.enjoyalgorithms.com/blogs/classification-and-regression-in-machine-learning/"><strong>Regression</strong></a> is a type of supervised Learning with &#39;known&#39; output present in the form of continuous, numerical, or quantitative data. The datasets are primarily structured; hence, we need <a href="https://www.enjoyalgorithms.com/blog/data-pre-processing-for-machine-learning/"><strong>structural data pre-processing techniques</strong></a>. Regression projects with structured data are:</p><h4>• Projects with Structured Dataset</h4><h4>1. <a href="https://www.enjoyalgorithms.com/blog/life-expectancy-prediction-using-linear-regression/">Life Expectancy Prediction</a></h4><p>This is one of the classical Machine Learning projects and is very popular among the freshers attempting to learn Machine Learning or Data Science. Expected life is directly linked with the development index of any area. Hence, organizations like WHO use ML techniques to predict the Life Expectancy of people living in any part of the world. This project uses the <a href="https://www.enjoyalgorithms.com/blog/linear-regression-in-machine-learning/"><strong>Linear Regression</strong></a> algorithm to fit the input features (GDP, mortality, population, income, etc.) to the output of expected life in years.</p><p>Here is the <a href="https://github.com/enjoyalgorithms/Machine-learning-project-code/blob/main/industry_projects/life-expectancy-linear-regression/Life%20expectancy.ipynb"><strong>complete code for the Life expectancy prediction project</strong></a>.</p><figure><img alt="Error distribution for performance evaluation " src="https://cdn-images-1.medium.com/proxy/1*7_MibZPmMDFx_L4SRQBprQ.png" /></figure><h4>2. <a href="https://www.enjoyalgorithms.com/blog/drug-discovery-using-ml/">Drug Discovery Using Machine Learning</a></h4><p>Machine learning helps medical science discover drugs quickly. Earlier drug discovery took significant time, and the disease persisted for longer. ML played a vital role even in the COVID-19 vaccine&#39;s quick discovery. This project demonstrates the capability of ML to assist and tackle newly emerging and spreading diseases. It uses the <a href="https://www.enjoyalgorithms.com/blog/xg-boost-algorithm-in-ml/"><strong>XG-Boost</strong></a> algorithm to predict the effect of various compounds on a particular target protein and then uses this effect to discover the drug.</p><p>Here is the <a href="https://github.com/enjoyalgorithms/Machine-learning-project-code/blob/main/industry_projects/drug_discovery/drug_discovery_main.ipynb"><strong>complete code for the drug discovery project</strong></a>.</p><h3>Unsupervised Learning Projects</h3><p><a href="https://www.enjoyalgorithms.com/blogs/supervised-unsupervised-and-semisupervised-learning/"><strong>Unsupervised Learning</strong></a> is a type of Machine Learning where machines try to fit a function on &#39;known&#39; input and &#39;unknown&#39; output. Here, machines internally generate the pseudo output and then fit a function on input and output pairs. This area of projects is the true future for the upcoming machine learning era. The reason is that supervised learning algorithms are highly dependent upon data labeling, which is time-consuming and expensive.</p><figure><img alt="Unsupervised learning example image 2" src="https://cdn-images-1.medium.com/proxy/1*YUl_BcqFPgX49sSb5yrk3A.jpeg" /></figure><p>We can divide the unsupervised learning projects into two major categories: 1. Clustering 2. Dimension Reduction.</p><h4>‣ Clustering Projects</h4><p>Clustering is an unsupervised technique where a machine groups similar data samples together, and this group is called a cluster. Popular algorithms for this technique are <a href="https://www.enjoyalgorithms.com/blog/k-means-clustering-algorithm"><strong>k-means</strong></a><strong> </strong>and <a href="https://www.enjoyalgorithms.com/blog/customer-segmentation-using-hierarchical-clustering/"><strong>Hierarchical clustering</strong></a><strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*WVSTlTvXGuLzIjO0H1v0Uw.png" /></figure><h4>1. <a href="https://www.enjoyalgorithms.com/blog/personality-prediction-using-ml">Personality Prediction using Machine Learning</a></h4><p>There are five main types of human personalities: openness, neuroticism, agreeableness, extroversion, and conscientiousness. This project groups persons into these five personalities based on the traits shown on their social media platforms. It uses the most famous <a href="https://www.enjoyalgorithms.com/blog/k-means-clustering-algorithm/"><strong>k-means clustering</strong></a> algorithm in machine learning.</p><p>Here is the <a href="https://github.com/enjoyalgorithms/Machine-learning-project-code/blob/main/industry_projects/personality_prediction/Personality.ipynb"><strong>complete code for the personality prediction project</strong></a><strong>.</strong></p><h4>2. <a href="https://www.enjoyalgorithms.com/blog/music-recommendation-system-using-ml">Music Recommendation System Using Machine Learning</a></h4><p>Recommendation systems are the most used ML technique in today&#39;s world. Amazon and Netflix are the two biggest and most successful tech companies because of their strong recommendation system. This project demonstrates how ML can be used to recommend music to users based on their precious music listening history. It uses the <a href="https://www.enjoyalgorithms.com/blog/k-means-clustering-algorithm"><strong>k-means algorithm</strong></a> to develop this recommendation system.</p><p>Here is the <a href="https://github.com/enjoyalgorithms/Machine-learning-project-code/blob/main/industry_projects/music_recommendation_system_unsupervised_learning/dataAnalysis_model.ipynb"><strong>complete code for the Music Recommendation System project</strong></a>.</p><h4>‣ Dimension Reduction Projects</h4><p>Dimensionality reduction is one of the prime applications of unsupervised Learning. Here, machines try to represent the same amount of information with fewer features. For example, converting ten into three features and retaining most information. Popular algorithms for this are <a href="https://www.enjoyalgorithms.com/blog/principal-component-analysis-in-ml/"><strong>PCA</strong></a> and <a href="https://www.enjoyalgorithms.com/blog/tsne-algorithm-in-ml/"><strong>t-SNE</strong></a>.</p><h4><a href="https://www.enjoyalgorithms.com/blog/image-compression-using-pca">Image Compression using Principal Component Analysis</a></h4><p>Image data consumes higher bandwidth, and hence, there is a need to reduce the size of the images for transmission. Machine Learning can help with that as well. This project uses <a href="https://www.enjoyalgorithms.com/blog/principal-component-analysis-in-ml/"><strong>PCA (Principal Component Analysis)</strong></a>, a dimension reduction technique that compresses the image by 80% with the minimum loss in information.</p><p>Here is the <a href="https://github.com/enjoyalgorithms/Machine-learning-project-code/blob/main/industry_projects/PCA_Image_compression/image_compression.ipynb"><strong>complete code for image compression using PCA</strong></a><strong>.</strong></p><figure><img alt="Comparison of output image with input image" src="https://cdn-images-1.medium.com/proxy/1*-RhfPKZvQ0Xfl6jz4zzfgA.jpeg" /></figure><h4>Conclusion</h4><p>In this article, we have listed some popular Machine Learning projects and provided links to their complete codes. We suggest first going through the step-wise implementation mentioned in the blogs, self-implementing them, and using the codes for assistance.</p><p><strong>Enjoy Learning, Enjoy Algorithms!</strong></p><h4><a href="https://www.enjoyalgorithms.com/live-machine-learning-course/">16 Week Live Project-Based ML Course: Admissions Open</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c83d937050c9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/enjoy-algorithm/top-machine-learning-projects-with-python-code-c83d937050c9">Top Machine Learning Projects With Python Code</a> was originally published in <a href="https://medium.com/enjoy-algorithm">EnjoyAlgorithms</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>