<?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 Ehsan Mohebianfar on Medium]]></title>
        <description><![CDATA[Stories by Ehsan Mohebianfar on Medium]]></description>
        <link>https://medium.com/@ehsan.mohebianfar?source=rss-406a773ec431------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rQYXQSAf8KYUfJRlZbKHUg.jpeg</url>
            <title>Stories by Ehsan Mohebianfar on Medium</title>
            <link>https://medium.com/@ehsan.mohebianfar?source=rss-406a773ec431------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 17:21:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ehsan.mohebianfar/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[Get prepared for a safe head-first dive into MLOps]]></title>
            <link>https://medium.com/@ehsan.mohebianfar/get-prepared-for-a-safe-head-first-dive-into-mlops-d67ccb91d482?source=rss-406a773ec431------2</link>
            <guid isPermaLink="false">https://medium.com/p/d67ccb91d482</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Ehsan Mohebianfar]]></dc:creator>
            <pubDate>Thu, 09 Mar 2023 19:24:19 GMT</pubDate>
            <atom:updated>2023-03-09T19:50:19.408Z</atom:updated>
            <content:encoded><![CDATA[<p>This blog post is the second in the series of MLOps. In the <a href="https://medium.com/@ehsan.mohebianfar/mlops-101-an-overview-2303648583c7">first one</a>, I discussed the basics of MLOps, i.e., what is MLOps? how does it relate to DevOps? and what is the hierarchy of needs for MLOps?. In this blog post, I discuss the tools and concepts, which we need to know before doing MLOps.</p><p>Here is the MLOps toolbox:</p><ul><li>Bash and linux command line</li><li>Cloud computing foundation</li><li>Python</li><li>Mathematics for programmers</li><li>Key concepts of machine learning</li><li>Data science lifecycle</li></ul><p>More likely you are familiar with the most of the tools mentioned above. Therefore, I just go through a quick overview on them one-by-one. Please note that, we do not need to be master in these tools and concepts to do MLOps, but knowing them at least in some degrees helps us a lot to do MLOps smoothly.</p><h4>Bash and Linux command line</h4><p>The majority of machine learning takes place in the cloud, and most cloud platforms expect users to interact with it through the terminal to some extent. Therefore, it is essential to have a basic understanding of the Linux command line for MLOps. Developing in a cloud shell environment that assumes familiarity with Bash and Linux can significantly enhance any skill set. Below is a short video course going through Bash essentials for Cloud.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F5_Oqp7ksChU%3Fstart%3D6%26feature%3Doembed%26start%3D6&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D5_Oqp7ksChU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F5_Oqp7ksChU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6b1046399ae36e89810d661f10b7cfa/href">https://medium.com/media/a6b1046399ae36e89810d661f10b7cfa/href</a></iframe><p>It is worth considering shifting from a personal workstation to a cloud-based development environment for efficient and secure development. There are various cloud-based tools providing more security as they eliminate the need to share developer keys and allow for efficient work due to their deep integration capabilities with the cloud resources. For instance, AWS offers <a href="https://aws.amazon.com/cloudshell/">AWS CloudShell</a> and <a href="https://aws.amazon.com/cloud9/">AWS Cloud9</a> for those starting on the AWS platform, with the latter being a more comprehensive development environment. Other cloud platforms like Microsoft Azure or Google Cloud also offer similar tools. The cloud-based development environments are free and can solve intractable problems by eliminating the need to transfer extensive data back and forth from the cloud (<a href="https://github.com/paiml/practical-mlops-book">source</a>).</p><h4>Cloud computing foundation</h4><p>Cloud Computing refers to the delivery of a wide range of computing services, such as servers, storage, databases, networking, software, analytics, and more, over the Internet. This technology presents an alternative to on-premises data centers, which require the user to manage hardware purchase and installation, virtualization, operating system installation, application installation, network setup, firewall configuration, and data storage setup, as well as maintenance throughout the data center lifecycle. In contrast, Cloud Computing shifts the responsibility of hardware purchase and maintenance to a cloud vendor who offers various software and platform services that can be rented on demand. The cost of these services is based on usage. Currently, AWS, Microsoft Azure and Google Cloud are among big vendors owning big shares in the market of cloud providers.</p><p>Some advantages of cloud computing are as follows:</p><ul><li><strong>Cost:</strong> It reduces the huge capital costs of buying hardware and software.</li><li><strong>Speed:</strong> Resources can be accessed in minutes, typically within a few clicks.</li><li><strong>Scalability: </strong>We can increase or decrease the requirement of resources according to the business requirements.</li><li><strong>Productivity: </strong>While using cloud computing, we put less operational effort. We do not need to apply patching, as well as no need to maintain hardware and software. Therefore, in this way, the IT team can be more productive and focus on achieving business goals.</li><li><strong>Reliability: </strong>Backup and recovery of data are less expensive and very fast for business continuity.</li><li><strong>Security: </strong>Many cloud vendors offer a broad set of policies, technologies, and controls that strengthen our data security.</li></ul><p>The cloud provides near-infinite compute and storage, and it works on the data without moving it. This feature is not replicable without cloud computing, making it a killer feature of the cloud. Therefore, cloud computing is a crucial aspect of almost all forms of machine learning, because the idea of near-infinite resources in cloud computing is essential as it enables the operationalizing of models that would not be feasible otherwise.</p><p>Moreover, cloud vendors intensify and improve their ML services continuously. For example, the automation of machine learning through AutoML (automation of the modeling aspect of machine learning) is a significant advancement that enables the creation of models more quickly, with higher accuracy and better explainability. With cloud advancements, like automation of machine learning, jobs in the data science industry will change, just like how data center operator jobs changed with technological advancements. It means that some simple ML tasks will be automated allowing domain expert humans make the domain expert humans controlling the ML automation orders of magnitude more effective (<a href="https://github.com/paiml/practical-mlops-book">source</a>).</p><h4>Python</h4><p>Python’s dominance as a programming language can be attributed to its optimization for developers rather than computers, unlike languages such as C or C++. While C offers excellent performance due to its lower-level nature, requiring the programmer to allocate memory, declare types, and compile programs, Python’s ease of use allows programmers to enter commands and run them with significantly less code. However, Python’s performance is slower than other languages like C, C#, Java, and Go, with certain limitations such as lack of true threads, a JIT compiler, and type inference found in other languages. Nevertheless, the emergence of cloud computing and containerization technologies has made language performance less of a problem. With cloud computing, building on top of technologies such as <a href="https://aws.amazon.com/lambda/">AWS Lambda</a> and <a href="https://aws.amazon.com/sqs/">AWS SQS</a> allows for fully distributed design, and containerized technology like Kubernetes eliminates the need for Python threads in building distributed systems.</p><p>To start learning Python with the minimum requirements, you need to know about <strong>statements</strong> which are instructions given to the computer. For example below phrase which is an statement:</p><pre>&gt;&gt;&gt; print(&quot;Hello World&quot;)<br>Hello World</pre><p>And you need to now about <strong>functions</strong> that serve as a “unit of work” like a toaster, i.e., it takes some inputs and returns some outputs. So then, we can use the function as many times as possible with new inputs. For instance, below code shows a function taking two numbers as inputs and returns back the summation (<a href="https://github.com/paiml/practical-mlops-book">source</a>).</p><pre>&gt;&gt;&gt; def add(x,y):<br>...   return x+y<br>...<br>&gt;&gt;&gt; add(1,1)  # calling the &quot;add&quot; function<br>2<br>&gt;&gt;&gt; add(3,4)<br>7</pre><p>Here is a good comprehensive course on python by David Beazley:</p><p><a href="https://dabeaz-course.github.io/practical-python/Notes/Contents.html">Practical Python Programming</a></p><h4>Mathematics for programmers</h4><p>Mathematics plays a critical role in machine learning as it provides the necessary foundations and tools to understand and develop algorithms that can analyze and learn from data. Specifically, mathematics provides the framework for the development of statistical models, optimization algorithms, and probabilistic reasoning, which are fundamental to the machine learning process.</p><p>For instance, linear algebra is used to represent and manipulate high-dimensional data, while calculus is used to optimize machine learning models to minimize error and maximize accuracy. Probability theory is used to model uncertainty and estimate the likelihood of different outcomes, while statistics is used to infer conclusions about populations based on sample data.</p><p>In addition, advanced mathematical concepts such as optimization theory, information theory, and graph theory are used in modern machine learning techniques such as deep learning, reinforcement learning, and graphical models.</p><p>In other words, understanding the basics of math is essential for working with machine learning. However, I do not go through all this concepts as it can be daunting and irritating. In this blog, I just discuss some key concepts of required mathematics for machine learning.</p><p><strong>Normal distributions</strong></p><p>A “normal distribution” is a statistical concept that describes a symmetrical, bell-shaped curve that represents the distribution of data in a population. It is also known as a Gaussian distribution, named after mathematician Carl Friedrich Gauss.</p><p>In a normal distribution, the mean, median, and mode are all equal and fall at the center of the curve. The curve is also characterized by two parameters, its mean and standard deviation, which determine its shape and location.</p><p>Many natural phenomena in the world, such as heights of people, IQ scores, and measurements of physical quantities, tend to follow a normal distribution. Understanding this concept is important in many fields, including science, finance, and engineering, as it can help researchers and practitioners make predictions and draw conclusions from data.</p><p>Let’s explore some data containing 25,000 records of human heights and weights of 19-year-old children using Jupyter notebook (<a href="https://github.com/paiml/practical-mlops-book">source</a>):</p><pre>In [0]:<br>import pandas as pd<br><br>In [7]:<br>df = pd.read_csv(&quot;https://raw.githubusercontent.com/noahgift/\<br>regression-concepts/master/height-weight-25k.csv&quot;)<br><br>Out[7]:<br>IndexHeight-InchesWeight-Pounds<br>01 65.78331 112.9925<br>12 71.51521 136.4873<br>23 69.39874 153.0269<br>34 68.21660 142.3354<br>45 67.78781 144.2971</pre><p>Figure 1 illustrates the plot for this data showing a linear relationship between height and weight (the taller you are, the more you weight!). The process of exploring data in a dataset is called “exploratory data analysis” (EDA). This involves using a combination of mathematics and visualization to analyze the data.</p><pre>In [0]:<br>import seaborn as sns<br>import numpy as np<br><br>In [9]:<br>sns.lmplot(&quot;Height-Inches&quot;, &quot;Weight-Pounds&quot;, data=df)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*_VqJltZ5sOmeMivkPlNpgg.png" /><figcaption>Figure 1. Height and weight (<a href="https://github.com/paiml/practical-mlops-book">source</a>)</figcaption></figure><p>Another term you usually hear in this concept is “descriptive statistics” used to numerically represent what the eye sees visually. The Pandas library has a <em>df.describe()</em> method that provides these statistics, such as the median and maximum value, which can be used to understand the distribution of the data. In a normally distributed dataset, extreme observations like the maximum and minimum values are rare. These trends can be observed in Figure 2.</p><pre>In [10]: df.describe()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*YVPP1n6bz8B_TFQsOg4WHA.png" /><figcaption>Figure 2. Descriptive statistics for height/weight (<a href="https://github.com/paiml/practical-mlops-book">source</a>)</figcaption></figure><p>The concept of normal distribution is a fundamental part of machine learning, and understanding it is crucial for developing and sustaining machine learning models.</p><p><strong>Optimization</strong></p><p>Optimization is the process of finding the best solution to a problem from a set of possible solutions. In math, optimization problems involve finding the maximum or minimum value of a function, subject to certain constraints.</p><p>The traveling salesman problem (TSP) is a classic example of an optimization problem. It involves finding the shortest possible route that visits a set of cities and returns to the starting city.</p><p>To solve the TSP, one approach is to systematically check all possible routes and choose the one with the shortest distance. However, this approach quickly becomes impractical as the number of cities increases, because the number of possible routes grows exponentially.</p><p>Another approach, for example is using “greedy” algorithm which picks the right solution (lowest distance) at every time leading to find a good enough solution. Let’s implement this algorithm for data showing the distance between different companies in the Bay Area (<a href="https://github.com/paiml/practical-mlops-book">source code</a>).</p><p>Here is a sample of the values (inputs):</p><pre>values = [<br>(&quot;AAPL&quot;, &quot;CSCO&quot;, 14),<br>(&quot;AAPL&quot;, &quot;CVX&quot;, 44),<br>(&quot;AAPL&quot;, &quot;EBAY&quot;, 14),<br>(&quot;AAPL&quot;, &quot;GOOG&quot;, 14),<br>(&quot;AAPL&quot;, &quot;GPS&quot;, 59),<br>(&quot;AAPL&quot;, &quot;HPQ&quot;, 14),<br>(&quot;AAPL&quot;, &quot;INTC&quot;, 8),<br>(&quot;AAPL&quot;, &quot;MCK&quot;, 60),<br>(&quot;AAPL&quot;, &quot;ORCL&quot;, 26),<br>(&quot;AAPL&quot;, &quot;PCG&quot;, 59),<br>(&quot;AAPL&quot;, &quot;SFO&quot;, 46),<br>(&quot;AAPL&quot;, &quot;SWY&quot;, 37),<br>(&quot;AAPL&quot;, &quot;URS&quot;, 60),<br>(&quot;AAPL&quot;, &quot;WFC&quot;, 60),</pre><p>The script (source) is shown below:</p><pre>#!/usr/bin/env python<br>&quot;&quot;&quot;<br>Traveling salesman solution with random start and greedy path selection<br>You can select how many iterations to run by doing the following:<br><br>python greedy_random_start.py 20 <br><br>&quot;&quot;&quot;<br><br>import sys<br>from random import choice<br>import numpy as np<br>from routes import values<br><br>dt = np.dtype([(&quot;city_start&quot;, &quot;S10&quot;), (&quot;city_end&quot;, &quot;S10&quot;), (&quot;distance&quot;, int)])<br>data_set = np.array(values, dtype=dt)<br><br><br>def all_cities():<br>    &quot;&quot;&quot;Finds unique cities<br><br>    array([[&quot;A&quot;, &quot;A&quot;],<br>    [&quot;A&quot;, &quot;B&quot;]])<br><br>    &quot;&quot;&quot;<br>    cities = {}<br>    city_set = set(data_set[&quot;city_end&quot;])<br>    for city in city_set:<br>        cities[city] = &quot;&quot;<br>    return cities<br><br><br>def randomize_city_start(cities):<br>    &quot;&quot;&quot;Returns a randomized city to start trip&quot;&quot;&quot;<br><br>    return choice(cities)<br><br><br>def get_shortest_route(routes):<br>    &quot;&quot;&quot;Sort the list by distance and return shortest distance route&quot;&quot;&quot;<br><br>    route = sorted(routes, key=lambda dist: dist[2]).pop(0)<br>    return route<br><br><br>def greedy_path():<br>    &quot;&quot;&quot;Select the next path to travel based on the shortest, nearest path&quot;&quot;&quot;<br><br>    itinerary = []<br>    cities = all_cities()<br>    starting_city = randomize_city_start(list(cities.keys()))<br>    # print &quot;starting_city: %s&quot; % starting_city<br>    cities_visited = {}<br>    # we want to iterate through all cities once<br>    count = 1<br>    while True:<br>        possible_routes = []<br>        # print &quot;starting city: %s&quot; % starting_city<br>        for path in data_set:<br>            if starting_city in path[&quot;city_start&quot;]:<br>                # we can&#39;t go to cities we have already visited<br>                if path[&quot;city_end&quot;] in cities_visited:<br>                    continue<br>                else:<br>                    # print &quot;path: &quot;, path<br>                    possible_routes.append(path)<br><br>        if not possible_routes:<br>            break<br>        # append this to itinerary<br>        route = get_shortest_route(possible_routes)<br>        # print &quot;Route(%s): %s &quot; % (count, route)<br>        count += 1<br>        itinerary.append(route)<br>        # add this city to the visited city list<br>        cities_visited[route[0]] = count<br>        # print &quot;cities_visited: %s &quot; % cities_visited<br>        # reset the starting_city to the next city<br>        starting_city = route[1]<br>        # print &quot;itinerary: %s&quot; % itinerary<br><br>    return itinerary<br><br><br>def get_total_distance(complete_itinerary):<br><br>    distance = sum(z for x, y, z in complete_itinerary)<br>    return distance<br><br><br>def lowest_simulation(num):<br><br>    routes = {}<br>    for _ in range(num):<br>        itinerary = greedy_path()<br>        distance = get_total_distance(itinerary)<br>        routes[distance] = itinerary<br>    shortest_distance = min(routes.keys())<br>    route = routes[shortest_distance]<br>    return shortest_distance, route<br><br><br>def main():<br>    &quot;&quot;&quot;runs everything&quot;&quot;&quot;<br><br>    if len(sys.argv) == 2:<br>        iterations = int(sys.argv[1])<br>        print(&quot;Running simulation %s times&quot; % iterations)<br>        distance, route = lowest_simulation(iterations)<br>        print(&quot;Shortest Distance: %s&quot; % distance)<br>        print(&quot;Optimal Route: %s&quot; % route)<br><br>    else:<br>        # print &quot;All Routes: %s&quot; % data_set<br>        itinerary = greedy_path()<br>        print(&quot;itinerary: %s&quot; % itinerary)<br>        print(&quot;Distance: %s&quot; % get_total_distance(itinerary))<br><br><br>if __name__ == &quot;__main__&quot;:<br>    main()</pre><p>The user can run the algorithm many times, for example, if we run that 25 times, it finds a good solution (imagine what can happen if you run that much more times, say 1000 times!):</p><pre>&gt; ./greedy-random-tsp.py 25<br>Running simulation 25 times<br>Shortest Distance: 129<br>Optimal Route: [(b&#39;WFC&#39;, b&#39;URS&#39;, 0), (b&#39;URS&#39;, b&#39;GPS&#39;, 1),\<br>(b&#39;GPS&#39;, b&#39;PCG&#39;, 1), (b&#39;PCG&#39;, b&#39;MCK&#39;, 3), (b&#39;MCK&#39;, b&#39;SFO&#39;, 16),\<br>(b&#39;SFO&#39;, b&#39;ORCL&#39;, 20), (b&#39;ORCL&#39;, b&#39;HPQ&#39;, 12), (b&#39;HPQ&#39;, b&#39;GOOG&#39;, 6),\<br>(b&#39;GOOG&#39;, b&#39;AAPL&#39;, 11), (b&#39;AAPL&#39;, b&#39;INTC&#39;, 8), (b&#39;INTC&#39;, b&#39;CSCO&#39;, 6),\<br>(b&#39;CSCO&#39;, b&#39;EBAY&#39;, 0), (b&#39;EBAY&#39;, b&#39;SWY&#39;, 32), (b&#39;SWY&#39;, b&#39;CVX&#39;, 13)]</pre><p>Please note that running that for once is not giving a good solution:</p><pre>&gt; ./greedy-random-tsp.py 1<br>Running simulation 1 times<br>Shortest Distance: 143<br>Optimal Route: [(b&#39;CSCO&#39;, b&#39;EBAY&#39;, 0), (b&#39;EBAY&#39;, b&#39;INTC&#39;, 6),\<br>(b&#39;INTC&#39;, b&#39;AAPL&#39;, 8), (b&#39;AAPL&#39;, b&#39;GOOG&#39;, 14), (b&#39;GOOG&#39;, b&#39;HPQ&#39;, 6),\<br>(b&#39;HPQ&#39;, b&#39;ORCL&#39;, 12), (b&#39;ORCL&#39;, b&#39;SFO&#39;, 20), (b&#39;SFO&#39;, b&#39;MCK&#39;, 16),\<br>(b&#39;MCK&#39;, b&#39;WFC&#39;, 2), (b&#39;WFC&#39;, b&#39;URS&#39;, 0), (b&#39;URS&#39;, b&#39;GPS&#39;, 1),\<br>(b&#39;GPS&#39;, b&#39;PCG&#39;, 1), (b&#39;PCG&#39;, b&#39;CVX&#39;, 44), (b&#39;CVX&#39;, b&#39;SWY&#39;, 13)]</pre><p>Indeed, optimization is the core of how machine learning works. One of the most-used optimization algorithm in machine learning is “gradient decent”.</p><p><em>Gradient decent</em></p><p>Gradient descent is an optimization algorithm used to minimize a function by iteratively moving in the direction of steepest descent of the function. In other words, it is a method to find the minimum value of a function by following the slope of the function downhill towards its minimum point.</p><p>More formally, given a function <em>f(x_1,….x_N)</em> and an initial value for <em>x = (x_1,….x_N)</em>, the gradient descent algorithm repeatedly computes the gradients (i.e., the vector of partial derivatives) of <em>f</em> with respect to <em>x_i, i = 1,…, N</em>, and then updates <em>x</em> by subtracting a small multiple of the gradients from <em>x</em>. This process is repeated until a minimum of <em>f</em> is reached or until a stopping criterion is met.</p><p>Gradient descent is widely used in machine learning, especially in training artificial neural networks. The objective function in this case is the loss function, which measures the error between the predicted output of the neural network and the actual output. By using gradient descent to minimize the loss function, the neural network can be trained to make better predictions.</p><p>In addition, MLOps requires achieving convergence, meaning creating a model that finds a solution that cannot be improved by adding more data. To improve intuition about gradient descent and convergence, using tools like the <a href="https://playground.tensorflow.org/#activation=tanh&amp;batchSize=10&amp;dataset=circle&amp;regDataset=reg-plane&amp;learningRate=0.03&amp;regularizationRate=0&amp;noise=0&amp;networkShape=4,2&amp;seed=0.45991&amp;showTestData=false&amp;discretize=false&amp;percTrainData=50&amp;x=true&amp;y=true&amp;xTimesY=false&amp;xSquared=false&amp;ySquared=false&amp;cosX=false&amp;sinX=false&amp;cosY=false&amp;sinY=false&amp;collectStats=false&amp;problem=classification&amp;initZero=false&amp;hideText=false">TensorFlow Playground</a> (figure 3) is beneficial, particularly experimenting with the learning rate to understand how too high a rate can lead to oscillation, and too low a rate may not reach the global minimum or take too long to converge. A demo from TensorFlow Playground is shown in Figure 4. Therefore, it is crucial to have an understanding of optimization and test it in practice to prevent operating costs from breaking a company or project in the real world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xhwZEKEf4c7Gzf2qjmixrg.png" /><figcaption>Figure 3. TensorFlow playground.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*L1PwlTQouG8OY9Xei1MOeg.png" /><figcaption>Figure 4. Learning rate (<a href="https://github.com/paiml/practical-mlops-book">source</a>).</figcaption></figure><h4>Key concepts of machine learning</h4><p>Machine learning is a subfield of artificial intelligence that uses algorithms to enable computers to learn from data without being explicitly programmed. Mathematically, machine learning is a process of optimization where a model’s parameters are iteratively updated based on the available data to minimize the error between the predicted output and the actual output.</p><p>There are three main types of machine learning: supervised learning, unsupervised learning, and reinforcement learning.</p><p><strong>Supervised learning</strong> involves training a model on labeled data, where the inputs and corresponding outputs are known. The goal is to learn a mapping function from inputs to outputs, such that the model can predict the output for new input data. Examples of supervised learning algorithms include linear regression, decision trees, and neural networks.</p><p><strong>Unsupervised learning</strong> involves training a model on unlabeled data, where the inputs do not have corresponding outputs. The goal is to learn the underlying structure of the data, such as patterns, clusters, or relationships. Examples of unsupervised learning algorithms include clustering, dimensionality reduction, and association rule learning.</p><p><strong>Reinforcement learning</strong> involves training an agent to interact with an environment and learn from the feedback it receives, such as rewards or penalties. The goal is to learn a policy that maximizes the cumulative reward over time. Examples of reinforcement learning algorithms include Q-learning, policy gradient, and actor-critic methods. Reinforcement learning can be applied to a wide range of tasks, such as game playing, robotics, and autonomous driving. A specific example is <a href="https://aws.amazon.com/deepracer/">AWS DeepRacer</a> system which allows the user to train a model for the car driving around a track. Here the agent is the car, the track is the environment, and then we have a reward function which decides who the agent interacts with the environment. Therefore, different reward functions leads to different results. An example of a reward function for AWS DeepRacer is as follows which rewards the agent for staying inside the two borders of the track (<a href="https://aws.amazon.com/deepracer/">source</a>).</p><pre>def reward_function(params):<br>    &#39;&#39;&#39;<br>    Example of rewarding the agent for staying inside the two borders of the<br>    track<br>    &#39;&#39;&#39;<br><br>    # Read input parameters<br>    all_wheels_on_track = params[&#39;all_wheels_on_track&#39;]<br>    distance_from_center = params[&#39;distance_from_center&#39;]<br>    track_width = params[&#39;track_width&#39;]<br><br>    # Give a very low reward by default<br>    reward = 1e-3<br><br>    # Give a high reward if no wheels go off the track and<br>    # the agent is somewhere in between the track borders<br>    if all_wheels_on_track and (0.5*track_width - distance_from_center) &gt;= 0.05:<br>        reward = 1.0<br><br>    # Always return a float value<br>    return float(reward)</pre><h4>Data science lifecycle</h4><p>Another fundamental concept to know is data science lifecycle. It is important because it provides a structured and systematic approach to deal with data from the beginning to end. By following a well-defined data science lifecycle, organizations can ensure that they are making data-driven decisions based on sound analytical processes. It provides a consistent methodology for all data science projects, ensuring that projects are completed on time and within budget.</p><p>Also, the data science lifecycle emphasizes the importance of collaboration and communication between different stakeholders involved in the project, such as business analysts, data engineers, and domain experts. This collaboration ensures that the final solution aligns with the organization’s business objectives and is easily understandable by all stakeholders.</p><p>Moreover, the data science lifecycle promotes a culture of continuous improvement by providing a feedback loop for ongoing evaluation and optimization of the solution. This ensures that the data-driven solution remains relevant and effective over time.</p><p>While you might see different approaches for data science lifecycle, they are almost the same with slightly differences and customizations. I prefer the one presented in the Figure 5, which is in line with data science way if we see that as a part of broader methodology, i.e., MLOps! As the Figure 5 is informative enough, I do not go through explanation of its parts one-by-one. The important point here is to understand well that data science lifecycle is an iterative loop!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-abb9X0m1Re-Q18J28ggJQ.jpeg" /><figcaption>Figure 5. Data science lifecycle (designed by Ehsan Mohebianfar)</figcaption></figure><h4>Resources</h4><ul><li><a href="https://github.com/paiml/practical-mlops-book">GitHub - paiml/practical-mlops-book: [Book-2021] Practical MLOps O&#39;Reilly Book</a></li><li><a href="https://dabeaz-course.github.io/practical-python/Notes/Contents.html">Practical Python Programming</a></li><li><a href="https://playground.tensorflow.org/#activation=tanh&amp;batchSize=10&amp;dataset=circle&amp;regDataset=reg-plane&amp;learningRate=0.03&amp;regularizationRate=0&amp;noise=0&amp;networkShape=4,2&amp;seed=0.45991&amp;showTestData=false&amp;discretize=false&amp;percTrainData=50&amp;x=true&amp;y=true&amp;xTimesY=false&amp;xSquared=false&amp;ySquared=false&amp;cosX=false&amp;sinX=false&amp;cosY=false&amp;sinY=false&amp;collectStats=false&amp;problem=classification&amp;initZero=false&amp;hideText=false">Tensorflow - Neural Network Playground</a></li><li><a href="https://aws.amazon.com/deepracer/">AWS DeepRacer - the fastest way to get rolling with machine learning</a></li><li><a href="https://aws.amazon.com/">Cloud Computing Services - Amazon Web Services (AWS)</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d67ccb91d482" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MLOps 101: An Overview]]></title>
            <link>https://medium.com/@ehsan.mohebianfar/mlops-101-an-overview-2303648583c7?source=rss-406a773ec431------2</link>
            <guid isPermaLink="false">https://medium.com/p/2303648583c7</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[sagemaker]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[mlops]]></category>
            <dc:creator><![CDATA[Ehsan Mohebianfar]]></dc:creator>
            <pubDate>Mon, 27 Feb 2023 22:16:18 GMT</pubDate>
            <atom:updated>2023-02-27T22:16:18.436Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Note: Different sources for this blog post have been used, mainly “Practical MLOps, by Noah Gift &amp; Alfredo Deza”</blockquote><blockquote>Think of MLOps as the process of automating machine learning using DevOps methodologies.</blockquote><p>This blog post is the start of a series about MLOps. In this series, I will talk about MLOps from the basics to advanced concepts. In this first blog post, I will explain what is MLOps? how is it different from DevOps? (or maybe better to say how does it relate to DevOps?!), and what is the hierarchy of needs for MLOps? So then, if you are new to MLOps, this series is a great place to start learning!</p><p>Let’s start the story from very beginning.</p><h4><strong>What is MLOps?</strong></h4><p>The increasing adoption of machine learning (ML) worldwide has led to a growing demand for skilled ML engineers who can effectively and methodically build ML systems. Many of these engineers are utilizing proven DevOps practices to emerging machine learning technologies. Various cloud vendors, including AWS, Azure, and GCP, offer certifications targeting ML practitioners. Organizations are actively seeking individuals who can leverage their expertise to implement and run ML workloads in a production setting, thereby generating a return on investment in AI and ML.</p><p>As a personal experience, I saw many people at work asking me what is the difference between data science and machine learning engineering. Actually this is a good question helping achieve a better understanding of the concept of machine learning engineering. The difference between data science and machine learning engineering is compared to the difference between science and engineering itself, with data science geared toward research and machine learning engineering geared toward production.</p><p>To generate return out of ML, organizations need more employees with hard skills in cloud computing, data engineering, and machine learning compared to data scientists. This may start</p><blockquote>treating data science as a behavior rather than a job title (just like DevOps!).</blockquote><p>As such, the decade of the 2020s may see an acceleration in the trend toward treating data science as a behavior.</p><p>The success of a machine learning engineering projects can be measured by the number of models that go into production and their impact on the revenue for the business. Advanced technology organizations use tools and processes that decrease the risk of failure, including cloud-native ML platforms, containerized workflows, serverless technology, specialized hardware, big data platforms and tools. Cloud computing is deeply tied to ML due to the massive compute, extensive data, and specialized hardware required. Cloud platforms are building specialized platforms to enhance ML’s operationalization, making cloud integration a natural choice for ML engineering.</p><p>The process of building machine learning systems involves more than just the technical details of machine learning modeling, including data engineering, problem feasibility, and business alignment. However, there is often a lack of automation and a focus on technical details rather than solving business problems. Additionally, academic datasets and software packages that do not scale for large-scale problems are often used. The emergence of MLOps aims to address these issues and automate the machine learning process using DevOps methodologies. MLOps requires full automation of the software engineering, data, and modeling processes, with humans playing a minimal role. Collaboration and transparency between developers, models, and operations are also critical. MLOps addresses the new wrinkle of model training and deployment in the traditional DevOps lifecycle, as well as the need for monitoring and instrumentation to account for potential issues like data drift. Ultimately,</p><blockquote>the goal of MLOps is to automate the entire machine learning process and focus on solving real-world business problems.</blockquote><p>The data science industry’s immaturity is a significant obstacle to implementing machine learning models. Like DevOps which has solved comparable issues in the software industry, MLOps is now being embraced by the machine learning community to overpass this obstacle.</p><h4><strong>DevOps and MLOps</strong></h4><p>DevOps is a collection of technical and management practices that aim to enhance an organization’s ability to release high-quality software quickly, securely, and at scale. Continuous integration (CI), continuous delivery (CD), microservices, infrastructure as code (IaC), monitoring and instrumentation, and effective technical communication are some of the best practices that contribute to the benefits of DevOps. CI and CD (CI/CD) are two of the most critical practices of DevOps, which involve merging code into a source control repository and automatically testing and deploying code changes.</p><p>All members of the MLOps team should participate in developing and maintaining a well-maintained CI/CD system, which is an investment in the team and company’s future. ML systems, which are also software systems with an extra and unique component of a ML model, can benefit from DevOps practices. Automation is the main pillar of DevOps, which is why new approaches like Data Versioning and AutoML are promising in capturing the DevOps mindset.</p><h4><strong>What do we need in MLOps?</strong></h4><p>The needs for MLOps can be seen as an hierarchy (Figure 1).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k94hE159l8RMTgSQR5lDSQ.png" /><figcaption>Figure 1. ML engineering hierarchy of needs (<a href="https://github.com/paiml/practical-mlops-book">source</a>).</figcaption></figure><p>For an ML system to work efficiently and reliably, it needs to be developed with the foundation of DevOps and data engineering best practices. Without this foundation, it is impossible to deliver the full potential of machine learning to an organization. The ML hierarchy of needs is a guide that highlights the steps necessary for operationalizing and building machine learning applications, with DevOps being the first and most crucial step. Once this foundation is established, data automation, platform automation, and finally, true ML automation or MLOps can occur, resulting in a machine learning system that works. Machine learning engineers and data engineers are the people responsible for building and operationalizing these systems.</p><p>Let’s go through the steps of the hierarchy in more detail one-by-one:</p><p><strong>DevOps</strong></p><p>The core of DevOps is based on CI. To achieve DevOps, it’s crucial to have an automated testing system in place. Python has made CI easy. All we need is a good structure for the project, which an example is shown in Figure 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VivuIwNSFndTcc8eYbRRLQ.png" /><figcaption>Figure 2. Python project structure (<a href="https://github.com/paiml/practical-mlops-book">source</a>).</figcaption></figure><p>Focusing more on the above structure, all a <em>Makefile</em> does is run commands. It is an excellent option for simplifying the continuous integration process by keeping track of complicated build steps that are hard to remember and execute accurately. It is a good starting point for a project and will evolve as new automation requirements emerge. Here is an example of a <em>Makefile:</em></p><pre>install:<br>   pip install --upgrade pip &amp;&amp;\<br>      pip install -r requirements.txt<br>lint:<br>   pylint --disable=R,C hello.py<br>test:<br>   python -m pytest -vv --cov=hello test_hello.py</pre><p>The <em>requirements.txt</em> file is a standard used by the python installation tool <em>pip</em> for installing packages.</p><p>At the end, we need to add a source code file and a test file. Let’s have a simple source code in the <em>hello.py </em>script as follows:</p><pre>def add(x, y):<br>    &quot;&quot;&quot;This is an add function&quot;&quot;&quot;<br><br>  return x + y<br><br><br>print(add(1, 1))</pre><p>and the script for the test in <em>test_hello.py</em> file (in the same folder as <em>hello.py</em>) created by using <em>pytest:</em></p><pre>from hello import add<br><br><br>def test_add():<br>    assert 2 == add(1, 1)</pre><p>To start continuous integration, only 4 files are needed: Makefile, requirements.txt, <em>hello.py</em>, and <em>test_hello.py</em>. However, a local python virtual environment should also be created using <em>python3 -m venv ~/.your-repo-name </em>command, and then source it to “activate” using <em>source ~/.your-repo-name/bin/activate</em>.</p><p>When we have the project structure set up, then we can run following commands for doing CI locally:</p><ul><li><em>make install </em>(to install the required libraries for the project)</li><li><em>make lint</em> (to lint the project)</li><li><em>make test</em> (to test the project)</li></ul><p>After successfully running this process on a local environment, it is easy to integrate it with a remote SaaS build server. There are several choices available, such as GitHub Actions, AWS Code Build, GCP CloudBuild, Azure DevOps Pipelines, or a self-hosted build server like Jenkins that is open source.</p><p>The next logical step would be to implement continuous deployment, which means automatically deploying the machine learning project to production. This process would include deploying the code in a specific location using a CD process and IaC, which we are not going into details in this blog post.</p><p><strong>Data Automation (DataOps)</strong></p><p>DataOps refers to a team approach to managing data that aims to enhance communication, integration, and automation of data transfers among data managers and consumers within an organization. The primary objective of DataOps is to provide value quickly by ensuring dependable delivery and management of data, data models, and other associated components. DataOps uses technology to automate the design, deployment, and administration of data transfer with proper governance levels, and it also utilizes metadata to enhance the usability and value of data in an ever-changing environment (<a href="https://www.gartner.com/en/information-technology/glossary/dataops">source</a>).</p><blockquote>Imagine a house without running water, nobody can use an automated dishwashing machine, right?!</blockquote><p>Similarly, If an organization does not have automated data processing, it cannot implement advanced ML methods. Hence, automating and operationalizing data processing is necessary to enable automation and operationalization of ML tasks in later stages, and this is why data automation comes next in ML hierarchy of needs (Figure 1).</p><p>The DataOps field is rapidly evolving, and many commercial tools are emerging to meet the demand. One such example is <a href="https://airflow.apache.org/">Apache Airflow</a>, created by Airbnb and later released as an open-source tool for scheduling and monitoring data processing jobs. Amazon Web Services (AWS) also offers a range of tools for data engineering, including <a href="https://aws.amazon.com/datapipeline/">AWS Data Pipeline</a>, <a href="https://aws.amazon.com/glue/">AWS Glue</a>. AWS Glue, a serverless ETL tool, automatically detects a data source’s schema and stores its metadata. When working with these tools, it is important to consider factors such as data size, frequency of updates, and data cleanliness.</p><p>Many organizations use a centralized data lake for their data engineering activities. A data lake’s scalability, high durability and availability make it an ideal hub for building automation around (including machine learning). Figure 3 shows a cloud data lake-based workflow, highlighting the ability to perform multiple tasks in one place without moving the data. Dedicated job titles, such as data engineer, can focus on building systems to handle various use cases, such as collecting data periodically, processing streaming data, serverless and event-driven data, big data jobs, and data and model versioning for ML engineering tasks. By leveraging these powerful tools and workflows, organizations can streamline their data engineering processes and achieve greater efficiency and accuracy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HoSgJX3dwphFpbPrvDPHzA.png" /><figcaption>Figure 3. Data engineering with a cloud data lake (<a href="https://github.com/paiml/practical-mlops-book">source</a>).</figcaption></figure><p><strong>Platform automation</strong></p><p>After automating the flow of data, organizations should consider using high-level platforms to develop ML solutions. For instance, if an organization already stores data in a cloud platform’s data lake like Amazon S3, it makes sense to integrate machine learning workflows into <a href="https://aws.amazon.com/sagemaker/">Amazon Sagemaker</a>. Similarly, organizations using Google can leverage Google AI Platform or Azure Machine Learning Studio for Azure, while those using Kubernetes can use <a href="https://www.kubeflow.org/">Kubeflow</a>. Figure 4 presents an example of AWS SageMaker, which manages a complex MLOps sequence for a real-world machine learning problem by automating infrastructure steps such as spinning up virtual machines, reading and writing to S3, and provisioning production endpoints. Note that attempting to execute these infrastructure steps manually would be risky in a production scenario. Indeed, an ML platform solves real-world repeatability, scale, and operationalization problems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DVWfJGmD-SpMsFTwFJAGfg.png" /><figcaption>Figure 4. SageMaker MLOps pipeline (<a href="https://github.com/paiml/practical-mlops-book">source</a>).</figcaption></figure><p><strong>MLOps</strong></p><p>Imagine that all the previous layers in ML hierarchy of needs are in place, then MLOps is possible. Now ML engineer can employ MLOps best practices to build ML systems exactly like a software engineer or a DevOps engineer who do tasks using DevOps best practices (remember that MLOps is a behaviour like DevOps!). The MLOps best practices create reproducible models with robust model packaging, validation, and deployment. Moreover, they enable us to monitor and improve model performance continuously (see Figure 5.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4K2uz4IRqLHsw7PA7G_mXg.png" /><figcaption>Figure 5. MLOps feedback loop (<a href="https://github.com/paiml/practical-mlops-book">source</a>).</figcaption></figure><p>Starting from training the model in the loop, we should have this mindset that creating a model only once is insufficient as data, customers, and model creators may change. Thus, we should build, update and retrain models using reusable ML pipelines that can be versioned. The next in the loop is the continuous delivery of ML models, which involves automating all steps, including infrastructure setup using IaC, to make the models deployable at any time to a new environment, including production. This process is similar to continuous delivery of software. In addition, having an audit trail for MLOps pipeline is crucial to address issues such as security, bias, and accuracy in machine learning models. The audit trail serves as a valuable tool for improvement and is akin to logging in software engineering. Finally, we should continuously monitor for model data drift use to improve future models to prevent accuracy issues in production.</p><p>At the end, a critical feature of MLOps is creating a cloud-native platform model, which is deployable to multiple targets, which is important in modern machine learning operations. For instance, a target could be container, API, native mobile, edge device, etc.</p><h4>Conclusion</h4><p>In this blog post we started with discussing definition of MLOps and its importance. Then continued with explaining what is the relation between DevOps and MLOps. Finally, we went through the ML hierarchy of needs and discussed its layers in detail.</p><p>In conclusion, we can think of MLOps based on the rule 25% meaning that DevOps, data engineering, modeling and business problems are equally important. This multidisciplinary nature of MLOps usually makes it a not-easy task in practice.</p><h4><strong>Resources</strong></h4><ul><li><a href="https://github.com/paiml/practical-mlops-book">GitHub - paiml/practical-mlops-book: [Book-2021] Practical MLOps O&#39;Reilly Book</a></li><li><a href="https://www.gartner.com/en/information-technology">Gartner for Information Technology (IT) Leaders</a></li><li><a href="https://aws.amazon.com/sagemaker/">The center for all your data, analytics, and AI - Amazon SageMaker - AWS</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2303648583c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>