<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Idowuilekura</title>
    <description>The latest articles on DEV Community by Idowuilekura (@idowuilekura1).</description>
    <link>https://dev.to/idowuilekura1</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F694537%2F386237ef-f081-4f62-9054-eea6b56d045f.jpeg</url>
      <title>DEV Community: Idowuilekura</title>
      <link>https://dev.to/idowuilekura1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/idowuilekura1"/>
    <language>en</language>
    <item>
      <title>MLOps: Deploying Machine Learning Models with Docker and Google Cloud Platform (Part 2)</title>
      <dc:creator>Idowuilekura</dc:creator>
      <pubDate>Fri, 01 Oct 2021 08:35:42 +0000</pubDate>
      <link>https://dev.to/idowuilekura1/mlops-deploying-machine-learning-models-with-docker-and-google-cloud-platform-part-2-3024</link>
      <guid>https://dev.to/idowuilekura1/mlops-deploying-machine-learning-models-with-docker-and-google-cloud-platform-part-2-3024</guid>
      <description>&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Introduction&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Model Deployment&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What on earth is Flask?&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Getting Started with Flask&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Getting Started with Swagger&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;strong&gt;Deploying Machine Learning Model with Flask and Swagger&lt;/strong&gt;&lt;/li&gt;

&lt;li&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Reference/ Resources&lt;/strong&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In the previous &lt;a href="https://dev.to/idowuilekura1/mlops-deploying-machine-learning-models-with-docker-and-google-cloud-platform-part-1-37m2"&gt;article&lt;/a&gt;, we learned about Machine Learning, the importance of Machine Learning Operations (MLOps) in the Machine Learning Lifecycle. We also learned how to frame a problem statement, gather required data, build a Machine Learning model, evaluate the model and save the model for future use. &lt;/p&gt;
&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;In this article, we will look into the process of deploying a Machine Learning Model with Flask and Swagger.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Model Deployment&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We have already discussed Model Deployment in the previous article, but to give a recap. Model Deployment is the process of making Machine Learning models accessible to others through different interfaces like Websites, Mobile Phones, Embedded Systems e.t.c. &lt;br&gt;
Flask and Swagger will be used to deploy the model in this article, but what are Flask and Swagger?&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;strong&gt;What on earth is Flask?&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;According to Wikipedia &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Flask is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Flask is simply a framework that helps python developers to build websites, without the need to learn Javascript. With flask, full-fledged websites can be built with python, HTML &amp;amp; CSS  &lt;/p&gt;
&lt;h5&gt;
  
  
  &lt;strong&gt;Getting Started with Flask&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;Now that we understand the functionality of flask, let us dive into a practical example.&lt;br&gt;
You will need an Integrated Development Environment like &lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;Visual Studio Code&lt;/a&gt;, &lt;a href="https://pycharm-community-edition.en.softonic.com/download" rel="noopener noreferrer"&gt;PyCharm&lt;/a&gt; e.t.c to follow along. You will also need to install Flask, you can install Flask by navigating to your command prompt/terminal and type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;pip&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we have the necessary tools to work with flask, let's dive into flask. We will write a simple program that will return your name with a greeting. The code below will &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Import the Flask class from the flask module&lt;/li&gt;
&lt;li&gt; Initialize a Flask() object with the name of the current file &lt;code&gt;__name__&lt;/code&gt;, &lt;code&gt;__name__&lt;/code&gt; will help python to locate where to load other dependencies into (in this case into our script). You can read this article from &lt;a href="https://stackoverflow.com/questions/39393926/flaskapplication-versus-flask-name#:~:text=1%20Answer&amp;amp;text=__name__%20is%20just,files%2C%20instance%20folder%2C%20etc." rel="noopener noreferrer"&gt;StackOverflow&lt;/a&gt; to understand the purpose of &lt;code&gt;__name__&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; declare a variable to store my name(replace with your name)&lt;/li&gt;
&lt;li&gt; initialize a decorator, the decorator will be called when users click on the homepage URL of the website  (this is what is called when you click on &lt;a href="http://www.google.com" rel="noopener noreferrer"&gt;www.google.com&lt;/a&gt;). You can read this &lt;a href="https://www.datacamp.com/community/tutorials/decorators-python" rel="noopener noreferrer"&gt;article&lt;/a&gt; from Datacamp to learn more about Decorators.&lt;/li&gt;
&lt;li&gt;define a function that binds to the decorator (the decorator will return the function whenever it is called). The function can return a HTML File or just a text.&lt;/li&gt;
&lt;li&gt;write an if conditional statement that restricts the execution of the application to the current script(I.e if you import the script into another script the application won't run). You can read this &lt;a href="https://www.geeksforgeeks.org/what-does-the-if-__name__-__main__-do/#:~:text=if%20__name__%20%3D%3D%20%E2%80%9Cmain%E2%80%9D%3A%20is%20used%20to,run%20directly%2C%20and%20not%20imported." rel="noopener noreferrer"&gt;article&lt;/a&gt; from GeeksForGeeks to understand the importance of &lt;code&gt;if __name__== '__main__'&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Importing the Flask module from flask library
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;

&lt;span class="c1"&gt;# initializing our application with the name of our module
&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# Variable to store my name( change to your name)
&lt;/span&gt;&lt;span class="n"&gt;my_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;idowu&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;# Initializing the homepage route
&lt;/span&gt;&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="c1"&gt;# function that will be returned
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Hello &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;my_name&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;debug&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy the code above and save it inside a file, you can name the file my_flask.py . Now navigate to where you saved the file using the command line, and type python my_flask.py.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="n"&gt;my_flask&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or just by clicking on the run icon if you are using Visual Studio Code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135066441-db79fa6c-41b1-44c6-97a6-e02577eda28e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135066441-db79fa6c-41b1-44c6-97a6-e02577eda28e.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
Fig. 1 How to run python file with VSCode (Image by Author)&lt;/p&gt;

&lt;p&gt;After running the file either with the command line/terminal or with VSCode you will be presented with this screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135067355-dfd5fbfe-59e9-433d-824c-cb2c95643e49.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135067355-dfd5fbfe-59e9-433d-824c-cb2c95643e49.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
Fig. 2 Image displaying information about flask (Image by Author)&lt;/p&gt;

&lt;p&gt;Click on the link (&lt;a href="http://127.0.0.1:5000/),once" rel="noopener noreferrer"&gt;http://127.0.0.1:5000/),once&lt;/a&gt; you click on the link you will see the screen below.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135072139-4e8a7318-257b-4c89-bc83-506836e3ef35.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135072139-4e8a7318-257b-4c89-bc83-506836e3ef35.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
Fig.3 Image showing the output of the greet function (Image by Author)&lt;/p&gt;

&lt;p&gt;When you clicked on the link (&lt;a href="http://127.0.0.1:5000/" rel="noopener noreferrer"&gt;http://127.0.0.1:5000/&lt;/a&gt;), flask automatically called the &lt;code&gt;@app.route('/')&lt;/code&gt; decorator, this is because you are trying to access the homepage (which is &lt;code&gt;/&lt;/code&gt;). The @app.route decorator will automatically call the &lt;code&gt;greet&lt;/code&gt; function and the output of the function will be returned. You will notice that, we hardcoded the variable name into our script, which is not intuitive. What if we want to accept the name from users and return &lt;code&gt;Hello + user_name&lt;/code&gt;, &lt;br&gt;
we can do this by creating another index for the name.&lt;br&gt;
We need to rewrite the programs in our script.&lt;br&gt;
The code below will &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bind a welcome function to the home route (&lt;code&gt;/&lt;/code&gt;) &lt;/li&gt;
&lt;li&gt;Bind a different function greet_name to the &lt;code&gt;/greet/name&lt;/code&gt; decorator. This decorator will allow users to insert their names ( this is similar to &lt;a href="http://www.google.com/search/query" rel="noopener noreferrer"&gt;www.google.com/search/query&lt;/a&gt;). &lt;a href="http://www.google.com" rel="noopener noreferrer"&gt;www.google.com&lt;/a&gt; is the home route url while &lt;code&gt;/search&lt;/code&gt; is for the search route.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;welcome&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Hello welcome to my first flask website&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;

&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/greet/&amp;lt;name&amp;gt;&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;greet_name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Hello &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;debug&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Delete the previous codes in my_flask.py and copy the above code into my_flask.py (ensure you save the file)&lt;/p&gt;

&lt;p&gt;Now try to run &lt;code&gt;my_flask.py&lt;/code&gt; and click on the homepage url.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python my_flask.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will be presented with the screen below&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135098506-fd19dad8-11de-4ad6-9d5c-78c94183e589.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135098506-fd19dad8-11de-4ad6-9d5c-78c94183e589.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
Fig. 4 Home page of the website (Image by Author)&lt;/p&gt;

&lt;p&gt;Now, for users to insert their names, the users will need to add &lt;code&gt;/greet/their_name&lt;/code&gt; after the homepage url i.e (&lt;a href="http://127.0.0.1:5000/greet/their_username" rel="noopener noreferrer"&gt;http://127.0.0.1:5000/greet/their_username&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;While still on the homepage, try and add &lt;code&gt;/greet/your_name[replace with your name]&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135100295-ee41b9b9-31c0-4750-92ec-8e7ef79c6946.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135100295-ee41b9b9-31c0-4750-92ec-8e7ef79c6946.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
Fig. 5 Image showing the response from greet route&lt;/p&gt;

&lt;p&gt;You will agree with me that this process is quite tedious. What if we have an interface that accepts responses from users using forms, sends the responses to flask and return the responses. To achieve this, we can build a form with HTML that accepts parameters. Luckily, instead of writing a HTML program, we can leverage the Swagger module to do that.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Swagger allows you to describe the structure of your APIs so that machines can read them. The ability of APIs to describe their own structure is the root of all awesomeness in Swagger. Why is it so great? Well, by reading your API’s structure, we can automatically build beautiful and interactive API documentation.&lt;br&gt;
&lt;a href="https://swagger.io/docs/specification/2-0/what-is-swagger/" rel="noopener noreferrer"&gt;Source&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5&gt;
  
  
  &lt;strong&gt;Getting Started with Swagger&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;You will need to install flasgger module, which can be done with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;pip&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="n"&gt;flasgger&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code below will&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Import the request and Flask module from flask. &lt;/li&gt;
&lt;li&gt;Import swagger from flasgger&lt;/li&gt;
&lt;li&gt;Initialize the Flask object &lt;/li&gt;
&lt;li&gt;Wrap the flask object application with Swagger. This helps our application to inherit properties from Swagger.&lt;/li&gt;
&lt;li&gt;create a decorator for our homepage url&lt;/li&gt;
&lt;li&gt;create a decorator for our greet url. If you notice we have something different from what we have been defining previously. The &lt;code&gt;@app.route()&lt;/code&gt; decorator for the greet url takes in a methods parameter with the value Get. There are two major methods that &lt;code&gt;@app.route&lt;/code&gt; receives

&lt;ul&gt;
&lt;li&gt;The Get Method (The get method is used when you want to receive something, when you navigate to &lt;a href="http://www.google.com" rel="noopener noreferrer"&gt;www.google.com&lt;/a&gt; you are indirectly calling the Get method to return the HTML file for the homepage)&lt;/li&gt;
&lt;li&gt;The Post Method is used to send information to a server. You can read this &lt;a href="https://www.geeksforgeeks.org/get-post-requests-using-python/" rel="noopener noreferrer"&gt;article&lt;/a&gt; from GeeksforGeeks to learn more about Post and Get Methods.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Inside the &lt;code&gt;greet_name()&lt;/code&gt; function, you will have to use docstring to define the Swagger interface. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The interface expects the;&lt;/li&gt;
&lt;li&gt;title of the query&lt;/li&gt;
&lt;li&gt;information about the query&lt;/li&gt;
&lt;li&gt;parameters that will be inputted. The parameter fields expects

&lt;ul&gt;
&lt;li&gt;the name of the field&lt;/li&gt;
&lt;li&gt;the mode in which the parameter will be entered, it can be manually inserted as values(query) or by inserting a path to the value.&lt;/li&gt;
&lt;li&gt;the type of the parameter ( it can be an integer or string)&lt;/li&gt;
&lt;li&gt;if the parameter is compulsory or not( if it is required then the parameter can't be omitted) &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;the responses. &lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;em&gt;N.B&lt;/em&gt; Make sure you indent the docstring with four spaces, also you will need to indent the details under the parameters and responses else swagger won't render the display.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;To access the user_name under the parameters, you will need to use the request module to access the parameter&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Lastly, you can return the greeting and the user_name.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Copy the code below into my_flask.py&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt; 
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flasgger&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Swagger&lt;/span&gt; 
&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nc"&gt;Swagger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;welcome&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Hello, welcome to my first flask website&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;


&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/greet&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;methods&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Get&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;greet_name&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Greetings
    This is using docstrings for specifications.
    ---
    parameters:
        - name: user_name
          in: query
          type: string
          required: true
    responses:
      200:
         description: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;greetings with user&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;

    &lt;span class="n"&gt;user_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user_name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;user_name&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;debug&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, try to run my_flask.py with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="n"&gt;my_flask&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135226479-150500d8-8e41-46e9-80d2-33d2eb986939.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135226479-150500d8-8e41-46e9-80d2-33d2eb986939.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
Fig. 6 Image showing the homepage (Image by Author)&lt;/p&gt;

&lt;p&gt;To access the Swagger User Interface, append &lt;code&gt;/apidocs&lt;/code&gt; after the homepage url i.e &lt;code&gt;http://127.0.0.1:5000/apidocs&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135227423-a33e3573-1585-4c68-8169-3701cb696601.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135227423-a33e3573-1585-4c68-8169-3701cb696601.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
Fig. 7 Image showing the Swagger UI (Image by Author)&lt;/p&gt;

&lt;p&gt;To interact with the UI, click on the GET button, which will present you with this screen &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135227925-9fa390c7-f847-48c8-add8-7a6937adf95c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135227925-9fa390c7-f847-48c8-add8-7a6937adf95c.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
Fig. 8 Image showing the UI under the GET button. &lt;/p&gt;

&lt;p&gt;If you notice, you can't insert any parameter inside the user_name, to insert value into the user_name field you will need to click on the Try it out button. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135227925-9fa390c7-f847-48c8-add8-7a6937adf95c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135227925-9fa390c7-f847-48c8-add8-7a6937adf95c.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can now insert any name into the user_name field and once you are done click on the &lt;code&gt;Execute&lt;/code&gt; button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135229761-36f5881f-f2bd-4072-aac4-be759ac5c752.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135229761-36f5881f-f2bd-4072-aac4-be759ac5c752.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
Fig. 9 Image showing the Response &lt;/p&gt;

&lt;p&gt;The response body display's the response from the greet function. Now that we have all the prerequisite for deploying our model, we can move on to cracking our main task which is to deploy a house price prediction model for Mowaale. &lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Deploying Machine Learning Models with Flask and Swagger&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;To successfully deploy the model, we will need to build a simple pipeline that will receive users inputs and make prediction.&lt;br&gt;
We need to rewrite our Swagger program, to accommodate more information.&lt;br&gt;
The code below will&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;import Flask &amp;amp; request from flask&lt;/li&gt;
&lt;li&gt;import Swagger from flasgger&lt;/li&gt;
&lt;li&gt;import joblib(this will be useful later)&lt;/li&gt;
&lt;li&gt;load the previously saved label-encoder for sale condition and save into lb_salecond variable &lt;/li&gt;
&lt;li&gt;load the previously saved label-encoder for sale type and save into lb_saletype variable&lt;/li&gt;
&lt;li&gt;load the previously saved linear regression model and save into model variable&lt;/li&gt;
&lt;li&gt;Initialize our Flask application object&lt;/li&gt;
&lt;li&gt;Wrap the application object with Swagger &lt;/li&gt;
&lt;li&gt;define a route for the homepage.&lt;/li&gt;
&lt;li&gt;define another route for the predict_price index.&lt;/li&gt;
&lt;li&gt;define the name of each parameters and other information that was discussed previously. The default is to specify a default parameter and the enum is to create a dropdown list of values.&lt;/li&gt;
&lt;li&gt;use the request module to get each parameters that was inputted.&lt;/li&gt;
&lt;li&gt;transform the salecondition from a string to a number (this was discussed in part 1)&lt;/li&gt;
&lt;li&gt;transform the sale type from a string to a number.&lt;/li&gt;
&lt;li&gt;store all the parameters into a list&lt;/li&gt;
&lt;li&gt;use the model to make predictions and return the predicted price for the house.
Copy the code below into my_flask.py
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt; 
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flasgger&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Swagger&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;joblib&lt;/span&gt; 
&lt;span class="n"&gt;lb_salecond&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;joblib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;lb_sc&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;lb_saletype&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;joblib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;lb_st&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;joblib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;lr_model&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nc"&gt;Swagger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;welcome&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Hello welcome to my first flask website&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Normal&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Partial&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Abnorml&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Family&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Alloca&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;AdjLand&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/predict_price&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;methods&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Get&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;predict_prices&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Welcome to Moowale House Prediction Website
    This is using docstrings for specifications.
    ---
    parameters:
        - name: MSSubClass
          in: query
          type: integer
          required: true
        - name: LotFrontage
          in: query
          type: integer
          required: true
        - name: Year_sold
          in: query
          type: integer
          required: true
        - name: Sale_type
          in: query
          type: string
          required: true
          default: New
          enum: [&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;WD&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;New&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;COD&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ConLD&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ConLI&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ConLw&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;CWD&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Oth&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Con&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;]
        - name: Sale_condition
          in: query
          type: string
          default: Normal
          enum: [&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Normal&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Partial&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Abnorml&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Family&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Alloca&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;AdjLand&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;]
    responses:
      200:
         description: House Price Prediction
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;

    &lt;span class="n"&gt;mssubclass&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;MSSubClass&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;lotfrontage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;LotFrontage&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;year_sold&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Year_sold&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;saletype&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Sale_type&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;salecondition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Sale_condition&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;label_encode_sc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;lb_salecond&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;salecondition&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="n"&gt;label_encode_st&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;lb_saletype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;saletype&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

    &lt;span class="n"&gt;columns_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;mssubclass&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;lotfrontage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;year_sold&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;label_encode_sc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;label_encode_st&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;columns_list&lt;/span&gt;&lt;span class="p"&gt;])[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;The predicted price is $&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;debug&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run my_flask.py,click on the url and attach &lt;code&gt;/apidocs&lt;/code&gt; after the homepage url. You will see the screen below,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135260572-c54e24f5-6a57-4adc-98f9-94d6af7ce503.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135260572-c54e24f5-6a57-4adc-98f9-94d6af7ce503.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
Fig. 10 Image showing the UI of moowale (Image by Author) &lt;/p&gt;

&lt;p&gt;Click on Try it out, and insert these values for MSSUbClass insert 20, for Lotfrontage insert 80, for Year_sold insert 2007, for Sale type &amp;amp; SaleCondition leave as the default and click on Execute.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135262953-c9f028e6-eec0-48f8-9371-012a5651a94d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F135262953-c9f028e6-eec0-48f8-9371-012a5651a94d.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
Fig.11 Image showing the prediction (Image by Author)&lt;/p&gt;

&lt;p&gt;Now that we have our model deployed, we have come to the end of the second article in this series.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This article has introduced you to the process of deploying machine learning models with flask and building interactive visuals with Swagger. In part 3 of this series, you will learn how to containerize the Api with Docker and Deploy on Google Cloud Platform. &lt;br&gt;
You can connect with me on &lt;a href="https://www.linkedin.com/in/ilekuraidowu/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt;  &lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Reference/ Resources&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Video from Krish Naik &lt;a href="https://www.youtube.com/watch?v=8vNBW98LbfI&amp;amp;list=PLZoTAELRMXVNKtpy0U_Mx9N26w8n0hIbs&amp;amp;index=3" rel="noopener noreferrer"&gt;channel&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/flasgger/flasgger" rel="noopener noreferrer"&gt;Flasgger&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>devops</category>
      <category>python</category>
      <category>googlecloud</category>
    </item>
    <item>
      <title>MLOps: Deploying Machine Learning models with Docker and Google Cloud Platform (Part 1)</title>
      <dc:creator>Idowuilekura</dc:creator>
      <pubDate>Thu, 09 Sep 2021 19:39:15 +0000</pubDate>
      <link>https://dev.to/idowuilekura1/mlops-deploying-machine-learning-models-with-docker-and-google-cloud-platform-part-1-37m2</link>
      <guid>https://dev.to/idowuilekura1/mlops-deploying-machine-learning-models-with-docker-and-google-cloud-platform-part-1-37m2</guid>
      <description>&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Introduction&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;MLOps Introduction&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Design Phase&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Requirements Engineering&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ML Use Cases and Prioritization&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data Availability Check&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Model Development Phase&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Data Engineering&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ML Model Engineering&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Model Testing and Validation&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Operations Phase&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;ML Model Deployment&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CI/CD Pipeline&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Monitoring and Triggering&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;strong&gt;Articles Focus&lt;/strong&gt;&lt;/li&gt;

&lt;li&gt;&lt;strong&gt;Problem Statement&lt;/strong&gt;&lt;/li&gt;

&lt;li&gt;&lt;strong&gt;Data Gathering/Data Engineering&lt;/strong&gt;&lt;/li&gt;

&lt;li&gt;&lt;strong&gt;Model Building&lt;/strong&gt;&lt;/li&gt;

&lt;li&gt;&lt;strong&gt;Model Evaluation&lt;/strong&gt;&lt;/li&gt;

&lt;li&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Machine Learning is the process of training machines to become intelligent and solve tasks with minimal supervision. You might be amazed at how YouTube intelligently recommends videos for you or how Spotify magically suggests new songs to you. What powers the intelligent recommendation or magically suggested songs is simply machine learning. Humans learned how to walk by observing how others walked and tried to replicate the process. Similarly, machines learn to perform tasks by iteratively following the patterns in a given dataset and then forming a mathematical function. Data scientists can use the mathematical function to make predictions on new datasets. As shown in the image below, training datasets are fed into the machine learning model. The model learns the patterns and develops a mathematical function (h). The mathematical function is then applied to a new dataset to make predictions. You can read this &lt;a href="https://www.analyticsvidhya.com/machine-learning/" rel="noopener noreferrer"&gt;article&lt;/a&gt; to gain a better understanding of machine learning.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F132355664-318bf4a5-81f2-40ef-b18f-4cf9cf5a6122.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F132355664-318bf4a5-81f2-40ef-b18f-4cf9cf5a6122.png"&gt;&lt;/a&gt;&lt;/p&gt;
Fig.1 How machine learning works &lt;a href="https://www.google.com/url?sa=i&amp;amp;url=https%3A%2F%2Fmachinelearningmedium.com%2F2017%2F08%2F10%2Fmodel-representation-and-hypothesis%2F&amp;amp;psig=AOvVaw2-DcUOC1eomtACOEfe_cUb&amp;amp;ust=1631108564271000&amp;amp;source=images&amp;amp;cd=vfe&amp;amp;ved=0CAsQjRxqFwoTCPiwkIP_7PICFQAAAAAdAAAAABAI" rel="noopener noreferrer"&gt;source&lt;/a&gt;



&lt;p&gt;### &lt;strong&gt;MLOps Introduction&lt;/strong&gt;&lt;br&gt;
 The Youtube recommendation model was built and then deployed on Youtube for users to enjoy. Imagine if Google built the recommendation model without deploying it on Youtube? That would be awkward, and we wouldn't be able to enjoy Youtube recommendations today. Unfortunately, most data scientists are comfortable with just building models without deploying them to production for end-users to enjoy. Machine Learning Operations (MLOps) is simply the process of shipping your machine learning models to production (this is just a basic definition). According to Wikipedia MLOps is  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;MLOps is a set of practices that aims to deploy and maintain machine learning models in production reliably and efficiently.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As shown in the image below, MLOps is an iterative method, that encompasses the:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Design Phase&lt;/li&gt;
&lt;li&gt;Model Development Phase&lt;/li&gt;
&lt;li&gt;Operations Phase&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F132360717-0fed95b8-e37b-4795-b298-f7c9d6b21af5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F132360717-0fed95b8-e37b-4795-b298-f7c9d6b21af5.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
Fig.2 MLOps Phases &lt;a href="https://www.google.com/url?sa=i&amp;amp;url=https%3A%2F%2Fml-ops.org%2Fcontent%2Fmlops-principles&amp;amp;psig=AOvVaw1SVPdhuwUk_caQVpTfQJNm&amp;amp;ust=1631110733104000&amp;amp;source=images&amp;amp;cd=vfe&amp;amp;ved=0CAsQjRxqFwoTCKC-uo2H7fICFQAAAAAdAAAAABAD" rel="noopener noreferrer"&gt;source&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;strong&gt;Design Phase&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Under the Design Phase we have other sub-phases, which are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Requirement Engineering&lt;/li&gt;
&lt;li&gt;ML Use-Cases and Prioritization&lt;/li&gt;
&lt;li&gt;Data Availability Check&lt;/li&gt;
&lt;/ol&gt;
&lt;h5&gt;
  
  
  &lt;strong&gt;Requirements Engineering&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;According to Javatpoint&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Requirements Engineering (RE) refers to the process of defining, documenting, and maintaining requirements in the engineering design process.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Requirement engineering helps an individual/ company understand the desires of the customers. It involves understanding the customers' needs through analysis, assessing the feasibility of a solution/product, settling for a better solution, clearly framing the solution, validating the specifications, managing any requirements before transforming it into a working system.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F132573929-5e729bd6-d3ec-46d0-846d-e686830ca741.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F132573929-5e729bd6-d3ec-46d0-846d-e686830ca741.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Fig.3 Requirement Engineering Process &lt;a href="https://www.javatpoint.com/software-engineering-requirement-engineering" rel="noopener noreferrer"&gt;source&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first step in any Data Science/ Machine learning lifecycle is requirement engineering. This phase is where you understand your customers' needs. For instance, Spotify was able to build a recommendation model because this is what most customers need. You can read more about requirements engineering &lt;a href="https://www.javatpoint.com/software-engineering-requirement-engineering" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  &lt;strong&gt;ML Use Cases and Prioritization&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;This phase is where Machine Learning practitioners prioritize the impact of any proposed machine learning solution on their business. This phase is concerned with analyzing the importance of a proposed machine learning solution towards their goals. The truth is some proposed machine learning solutions aren't profitable to an organization. In this phase, companies drop those solutions.&lt;br&gt;
You can read this &lt;a href="https://www.linkedin.com/pulse/identifying-prioritizing-artificial-intelligence-use-cases-srivatsan/" rel="noopener noreferrer"&gt;article&lt;/a&gt; from Srivatsan Srinivasan,a Google Developer Expert; the report will give you more understanding of prioritizing Machine Learning Use Cases.&lt;/p&gt;
&lt;h5&gt;
  
  
  &lt;strong&gt;Data Availability Check&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;This phase deals with the process of checking if there are available datasets to train the model. You can't train any machine learning model without data&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;strong&gt;Model Development Phase&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The model development phase encompasses these sub-phases;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data Engineering&lt;/li&gt;
&lt;li&gt;ML Model Engineering&lt;/li&gt;
&lt;li&gt;Model Testing and Validation&lt;/li&gt;
&lt;/ul&gt;
&lt;h5&gt;
  
  
  &lt;strong&gt;Data Engineering&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;The Data Engineering phase deals with collecting relevant datasets that will be used to train the model. Data validation is also carried out here; this ensures that the data is valid and clean. If you feed poor data into a sophisticated model, you will get a poor result. You can read this &lt;a href="https://www.precisely.com/glossary/data-engineering#:~:text=Data%20engineering%20is%20the%20complex,and%20groups%20within%20an%20organization.&amp;amp;text=In%20addition%20to%20making%20data,short%2D%20and%20long%2Dterm." rel="noopener noreferrer"&gt;article&lt;/a&gt; to learn more about data engineering&lt;/p&gt;
&lt;h5&gt;
  
  
  &lt;strong&gt;ML Model Engineering&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;The model engineering phase deals with training the model with the data, performing feature engineering. Data Scientist/Machine Learning engineers sometimes try out other models, stack up two or more models together at this phase. &lt;/p&gt;
&lt;h5&gt;
  
  
  &lt;strong&gt;Model Testing and Validation&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;After you have trained your model, there is a need to test and evaluate the model's performance. You wouldn't want to deploy a model that is performing terribly on unseen data. The model testing and Validation phase deals with testing and evaluating the model on unseen data. While the model might perform better on the training dataset, you want to make sure that the model also performs well on an unseen dataset(test).&lt;br&gt;
Different metrics can be used to evaluate your model; if you are working on a regression task, you can use mean squared error, mean absolute error, e.t.c, while working on classification tasks, you can use accuracy, f1 score, recall, precision e.t.c. &lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;strong&gt;Operations Phase&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Ml model deployment, CI/CD Pipelines and Monitoring &amp;amp; Triggering&lt;br&gt;
Under the operations phase, we have these sub-phases;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ML Model Deployment&lt;/li&gt;
&lt;li&gt;CI/CD Pipelines&lt;/li&gt;
&lt;li&gt;Monitoring and Triggering&lt;/li&gt;
&lt;/ul&gt;
&lt;h5&gt;
  
  
  &lt;strong&gt;ML Model Deployment&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;This phase deals with deploying the model to production; the production environment can be a website, mobile phones, or edge computing devices like embedded systems.&lt;/p&gt;
&lt;h5&gt;
  
  
  &lt;strong&gt;CI/CD Pipeline&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;CI/CD means Continuous Integration and Continuous Deployment. CI/CD is a set of practices that enables developers to change codes and deliver the code to production frequently and safely. CI/CD helps data scientists/ machine learning engineers continuously make changes to their model training, testing the newly trained model and deploying it frequently and safely. You can read this &lt;a href="https://www.infoworld.com/article/3271126/what-is-cicd-continuous-integration-and-continuous-delivery-explained.html" rel="noopener noreferrer"&gt;article&lt;/a&gt; to learn more about CI/CD  &lt;/p&gt;
&lt;h5&gt;
  
  
  &lt;strong&gt;Monitoring and Triggering&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;This phase involves monitoring the model's performance in the production environment, triggering the CI/CD pipeline if the model performance drops below a threshold. The performance of a machine learning model can reduce due to changes in the production datasets; there can be a difference in the data used to train the model and data fed into the model during predictions in the production environment. &lt;/p&gt;

&lt;p&gt;If the model performance falls below a certain threshold, then the model needs to be retrained and redeployed; the model retraining is done by triggering the CI/CD pipeline. &lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Articles Focus&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The focus of the articles in this series is on building a machine learning model and deploying the model with Docker and Google Cloud Platform.&lt;/p&gt;

&lt;p&gt;Machine Learning models are built to solve problems; hence, a problem statement needs to be defined before building any machine learning model.&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;strong&gt;Problem Statement&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;You just resumed as a data scientist at moowale; moowale is a real estate company that lists houses for sale. You have been tasked with building a machine learning model that can be used to predict the price of any building based on some given parameters. The model will be deployed to make it easy for customers to get predicted prices based on information they input into the moowale website.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;N.B moowale is a Yoruba word meaning I am searching for a house [to buy].&lt;/em&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;strong&gt;Data Gathering/Data Engineering&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Now that you have a well-defined problem statement, the next stage is to gather the data used to train the model. You can source datasets from public dataset repositories or talk to the data engineer to deliver the needed dataset to you. An existing dataset can be used to train the model; the house price prediction dataset on Kaggle will be used to train the model. You can access the dataset with this &lt;a href="https://www.kaggle.com/c/neolen-house-price-prediction" rel="noopener noreferrer"&gt;link&lt;/a&gt;; the train.csv dataset will be used to train the model.&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;strong&gt;Model Building&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;It's time to build our model, but we will need to explore the dataset (exploratory data analysis). To follow along, you will need to have an Integrated Development Environment like Jupyter Notebook/Lab (which most data scientists use). You can learn more about Jupyter Notebooks with this &lt;a href="https://www.youtube.com/watch?v=HW29067qVWk" rel="noopener noreferrer"&gt;link&lt;/a&gt;.&lt;br&gt;
Now that you have Jupyter Notebook, you can open it and follow along.&lt;br&gt;
To explore the dataset, we will be using some python libraries, which we will import.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# importing necessary libraries
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pandas&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;plt&lt;/span&gt;
&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;matplotlib&lt;/span&gt; &lt;span class="n"&gt;inline&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pandas will be used to read the dataset, NumPy is a numerical module, matplotlib is a plotting module and %matplotlib inline helps Jupyter notebook render plots within the notebook.&lt;/p&gt;

&lt;p&gt;Now that the necessary modules have been imported, the next step is to load and visualize the dataset.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# reading the dataset with pandas
&lt;/span&gt;&lt;span class="n"&gt;dataset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;train.csv&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Exploring the first five rows
&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;head&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F132589280-efbb4a6e-82c3-4ede-8e60-14c4eeb8432e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F132589280-efbb4a6e-82c3-4ede-8e60-14c4eeb8432e.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
Fig. 4 Image of the first five rows of the dataset (Image by Author)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# printing the number of columns
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;There are &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;columns&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; columns in the dataset&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F132666670-3cde770a-9fc6-4724-94ed-560729fb6ecb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F132666670-3cde770a-9fc6-4724-94ed-560729fb6ecb.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
Fig. 5 Printing the number of columns in the dataset (Image by Author)&lt;/p&gt;

&lt;p&gt;There are 81 columns(or features) in the dataset; not all are useful for model building. You will need to rely on picking the necessary columns to be used to train the model. Data scientist either relies on domain knowledge gained from experience or consulting with a domain expert in the field of interest to choose valuable columns. For this task, I will just pick columns based on assumptions. Columns that will be chosen are &lt;code&gt;'MSSubClass',"LotFrontage','YrSold','SaleType','SaleCondition','SalePrice&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data_new&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;MSSubClass&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;LotFrontage&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;YrSold&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;SaleType&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;SaleCondition&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;SalePrice&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# checking for missing values
&lt;/span&gt;&lt;span class="n"&gt;data_new&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F132671268-d46c1d17-b2f9-4cff-97b1-e8d9296a159a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F132671268-d46c1d17-b2f9-4cff-97b1-e8d9296a159a.png" alt="Information about the dataset"&gt;&lt;/a&gt;Fig. 5 Information about the dataset. (Image by Author)&lt;/p&gt;

&lt;p&gt;The LotFrontage has missing values; since the column is of float datatype, the missing values can be filled with the column mean, column median, or a constant number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Filling with a constant number
&lt;/span&gt;&lt;span class="n"&gt;data_new&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;LotFrontage&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data_new&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;LotFrontage&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;fillna&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;9999&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# check for missing values again
&lt;/span&gt;&lt;span class="n"&gt;data_new&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F132673332-ea688182-a712-45e9-b0c3-3cea297d6e34.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F38056084%2F132673332-ea688182-a712-45e9-b0c3-3cea297d6e34.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are no more missing values, the next phases is model building.&lt;/p&gt;

&lt;p&gt;Looking closely at the &lt;code&gt;data_new.info()&lt;/code&gt; result, you will notice that we have two columns with object data type.&lt;br&gt;
Machine Learning models expect all columns to be in numerical format, hence converting the columns to numeric. LabelEncoder is widely used to convert categorical columns to numeric columns; you can read more about LabelEncoder &lt;a href="https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.LabelEncoder.html" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# using label encoder to encode the categorical columns
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.preprocessing&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;LabelEncoder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;StandardScaler&lt;/span&gt;

&lt;span class="c1"&gt;# saletype label encoder
&lt;/span&gt;&lt;span class="n"&gt;lb_st&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;LabelEncoder&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;# salecondition label encoder
&lt;/span&gt;&lt;span class="n"&gt;lb_sc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;LabelEncoder&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;lb_st&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data_new&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;SaleType&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="n"&gt;lb_sc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data_new&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;SaleCondition&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="n"&gt;data_new&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;SaleType&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;lb_st&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data_new&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;SaleType&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="n"&gt;data_new&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;SaleCondition&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;lb_sc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data_new&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;SaleCondition&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;.fit()&lt;/code&gt; method encodes each category to a number, and the &lt;code&gt;.transform()&lt;/code&gt; method transforms the category to number (you need to fit before you can transform).&lt;/p&gt;

&lt;p&gt;Now that all columns are in numerical format, it's time to build the machine learning model. Machine Learning Engineers/ Data scientists usually split the dataset into train and test sets (the train set is used to train the model while the test set is used to evaluate the model's performance). To split the dataset into train and test, the features used to train the model must be separated from the target.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Separating the dataset into features(X) and target(y)
&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data_new&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;SalePrice&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;axis&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data_new&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;SalePrice&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The features are named X, and the target is named y because machine learning is basically mathematical functions applied to data. Recall from mathematics that *f*X= y, the target(y) is computed by applying a mathematical function on your features (X) (this is what happens in machine learning or during model training).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# splitting the dataset into train and test set
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.model_selection&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;train_test_split&lt;/span&gt;
&lt;span class="n"&gt;X_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;y_test&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;train_test_split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we have our train and test dataset, it's time to build our model. There are two significant types of machine learning tasks, Classification and Regression. Regression deals with numerical targets, while classification deals with categorical targets.&lt;br&gt;
The target is SalePrice which is numerical; hence a regression model will be used.&lt;br&gt;
There are different regression models; Linear Regression is the simplest to understand and beginner-friendly regression model. LinearRegression model will be used in this project to keep it simple); you can use other regression models like RandomForestRegressor etc.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.linear_model&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;LinearRegression&lt;/span&gt;

&lt;span class="n"&gt;lr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;LinearRegression&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;# training the model
&lt;/span&gt;&lt;span class="n"&gt;lr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;y_train&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;Model Evaluation&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Recall that after building your model, you need to evaluate the performance of the model. Several metrics can be used to evaluate machine learning models; for regression models, metrics include mean squared error, mean absolute error, root mean squared error e.t.c. Root Mean Squared Error metric will be used to evaluate the model.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.metrics&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;mean_squared_error&lt;/span&gt;

&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;mean_squared_error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;y_test&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="c1"&gt;# this will give approximately 73038
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Root Mean Squared Error is quite large; machine learning engineers/ data scientists tries to reduce the error by trying other models and applying feature engineering. I won't be diving into that; the article's aim is not to minimize the error.&lt;/p&gt;

&lt;p&gt;Now that we have our model, to use the model in production, you will need to save the model and the two label encoder that was initialized earlier.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# joblib is for saving objects for later use
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;joblib&lt;/span&gt;
&lt;span class="n"&gt;joblib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dump&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;lr_model&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;joblib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dump&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lb_sc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;lb_sc&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;joblib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dump&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lb_st&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;lb_st&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;joblib.dump()&lt;/code&gt; accepts two default parameters: the object you want to save and the name you wish to save the object with.&lt;/p&gt;

&lt;p&gt;Now that we have our model saved, we have finally come to the end of the first article in this series.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This article has introduced you to machine learning, the importance of machine learning operation in the Machine Learning Lifecycle. How to frame a problem statement, gather data, build a linear regression model, evaluate the model and finally save the model for future use. In Part2 of this series, you will learn how to build machine learning APIs with flask, test the APIs and containerize the API with Docker.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>docker</category>
      <category>python</category>
      <category>flask</category>
    </item>
  </channel>
</rss>
