{"id":46656,"date":"2021-08-06T00:00:00","date_gmt":"2021-08-06T07:00:00","guid":{"rendered":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/"},"modified":"2025-11-13T12:55:28","modified_gmt":"2025-11-13T20:55:28","slug":"performing-real-time-predictions-using-machine-learning-griddb-and-python","status":"publish","type":"post","link":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/","title":{"rendered":"Performing Real-Time Predictions Using Machine Learning, GridDB and Python"},"content":{"rendered":"<h2>Outline<\/h2>\n<p>In this tutorial, we will see how we can turn our Machine Learning model into a web API to make real-time predictions using Python. The outline of the article will be as follows:<\/p>\n<ol>\n<li>Prerequisites and Environment setup<\/li>\n<li>Creating a Machine Learning Model<\/li>\n<li>Serialization and Deserialization of the Machine Learning Model<\/li>\n<li>Developing an API using Python&#8217;s Flask<\/li>\n<li>Making real-time predictions<\/li>\n<\/ol>\n<h2>Prerequisites and Environment setup<\/h2>\n<p>This tutorial is carried out in Anaconda Navigator (Python version &#8211; 3.8.3) on Windows Operating System. The following packages need to be installed before you continue with the tutorial &#8211;<\/p>\n<ol>\n<li>Pandas<\/li>\n<li>NumPy<\/li>\n<li>Scikit-learn<\/li>\n<li>Flask<\/li>\n<li>Joblib<\/li>\n<\/ol>\n<p>You can install these packages in Conda&#8217;s virtual environment using <code>conda install package-name<\/code>. In case you are using Python directly via terminal\/command prompt, <code>pip install package-name<\/code> will do the work.<\/p>\n<p>Note that to access <a href=\"https:\/\/github.com\/griddb\/python_client\">GridDB&#8217;s database through Python<\/a>, the following packages will be required &#8211;<\/p>\n<ol>\n<li>GridDB C-client<\/li>\n<li>SWIG (Simplified Wrapper and Interface Generator)<\/li>\n<li>GridDB Python-client<\/li>\n<\/ol>\n<p>Great! Our environment is all set up and ready to use. Let&#8217;s create a Machine Learning model.<\/p>\n<h2>Creating a Machine Learning Model<\/h2>\n<p>We will be using the Linear Regression model from one of our previous posts on <a href=\"https:\/\/griddb.net\/en\/blog\/create-a-machine-learning-model-using-griddb\/\">Machine Learning using GridDB<\/a>. The full source code is available on <a href=\"https:\/\/github.com\/griddbnet\/Blogs\/tree\/main\/Create%20A%20Machine%20Learning%20Model%20using%20GridDB\">Github<\/a>. We will modify the code as we move forward to inculcate the new changes. You can either download the source code to follow along or we will be attaching the python file at the end of this tutorial as well.<\/p>\n<p>The Linear Regression Model for CalCOFI dataset looks like &#8211;<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-py\">import numpy as np\nimport pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LinearRegression\nimport joblib\n\ndataset = pd.read_csv(\"bottle.csv\")\ndataset=dataset[[\"Salnty\",\"T_degC\"]]\ndataset = dataset[:500]\ndataset=dataset.dropna(axis=0)\ndataset.reset_index(drop=True,inplace=True)\n\nx_label=np.array(dataset['Salnty']).reshape(493,1)\ny_label=np.array(dataset['T_degC']).reshape(493,1)\nx_train, x_test, y_train, y_test = train_test_split(x_label, y_label, test_size = 0.2, random_state = 100)\nregression_model=LinearRegression()\nregression_model.fit(x_train,y_train)<\/code><\/pre>\n<\/div>\n<p>Note that we have removed the last few lines where we&#8217;re making predictions on the test dataset as we don&#8217;t need them here. The model accuracy is <code>87%<\/code> as we saw in the previous post. If you plot the resulting model, it will look like &#8211;<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-py\">plt.figure(figsize=(12,10))\nplt.scatter(x_label, y_label,  color='aqua')\nplt.plot(x_train, regression_model.predict(x_train),linewidth=\"4\")\nplt.xlabel(\"Temperature\",fontsize=22)\nplt.ylabel(\"Salinity\",fontsize=22)\nplt.title(\"Linear Regression\",fontsize=22)<\/code><\/pre>\n<\/div>\n<p><img decoding=\"async\" src=\"linear_regression_model.png\" alt=\"\" \/><\/p>\n<h2>Serialization and Deserialization of the Machine Learning Model<\/h2>\n<p>Our model is now ready to make predictions, but we will need to store the trained model so that we don&#8217;t have to execute the same steps every time we receive a request from the server. This process of storing a Python object into a byte stream so that it can be utilized later is called Serialization. Deserialization, as the name suggests, is the reverse of Serialization, i.e. converting a byte stream back into a Python object. Serialization and Deserialization in Python can be done via packages like <code>joblib, pickle,<\/code> etc.<\/p>\n<p>Let&#8217;s go ahead and save our model.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-py\">joblib.dump(regression_model, 'regression_model.pkl')\nprint('Model dumped')\nregression_model = joblib.load('regression_model.pkl')\nregression_model_columns = list(x_train)\njoblib.dump(regression_model_columns, 'regression_model_columns.pkl')<\/code><\/pre>\n<\/div>\n<p>Our file after adding those code snippets will finally look like &#8211;<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-py\">import numpy as np\nimport pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LinearRegression\nimport joblib\n\ndataset = pd.read_csv(\"bottle.csv\")\ndataset=dataset[[\"Salnty\",\"T_degC\"]]\ndataset = dataset[:500]\ndataset=dataset.dropna(axis=0)\ndataset.reset_index(drop=True,inplace=True)\n\nx_label=np.array(dataset['Salnty']).reshape(493,1)\ny_label=np.array(dataset['T_degC']).reshape(493,1)\nx_train, x_test, y_train, y_test = train_test_split(x_label, y_label, test_size = 0.2, random_state = 100)\nregression_model=LinearRegression()\nregression_model.fit(x_train,y_train)\n\njoblib.dump(regression_model, 'regression_model.pkl')\nprint('Model dumped')\nregression_model = joblib.load('regression_model.pkl')\nregression_model_columns = list(x_train)\njoblib.dump(regression_model_columns, 'regression_model_columns.pkl')<\/code><\/pre>\n<\/div>\n<p>Let&#8217;s go ahead and save our <code>regression_model.py<\/code> in the same directory. To execute the code in the command line, type <code>python regression_model.py<\/code>. After execution, our directory structure will look like this &#8211;<\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/07\/directory-structure.png\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/07\/directory-structure.png\" alt=\"\" width=\"718\" height=\"258\" class=\"aligncenter size-full wp-image-27654\" srcset=\"\/wp-content\/uploads\/2021\/07\/directory-structure.png 718w, \/wp-content\/uploads\/2021\/07\/directory-structure-300x108.png 300w, \/wp-content\/uploads\/2021\/07\/directory-structure-600x216.png 600w\" sizes=\"(max-width: 718px) 100vw, 718px\" \/><\/a><\/p>\n<p>The <code>ipynb<\/code> file is optional if you are running your files in the terminal\/command prompt.<\/p>\n<p>Great! Now that our model is saved, we are all set to create an API for making real-time predictions.<\/p>\n<h2>Developing an API using Python&#8217;s Flask<\/h2>\n<p>We first need to import our model and convert it into a python object when our application starts. We can do that with the following lines of code &#8211;<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-py\">lr = joblib.load(\"regression_model.pkl\")\nprint ('Model loaded')\nmodel_columns = joblib.load(\"regression_model_columns.pkl\")\nprint ('Model columns loaded')<\/code><\/pre>\n<\/div>\n<p>Now we need to create an API endpoint that actively listens to requests, processes them in a Python object and pass them to the model for making predictions. We also need to take care of runtime exceptions in case the input is not in the desired JSON format. The following script should do the work &#8211;<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-py\">@app.route('\/predict', methods=['POST'])\ndef predict():\n    if lr:\n        try:\n            json_ = request.json\n            query = pd.DataFrame(json_)\n            print(query)\n\n            prediction = list(lr.predict(query))\n\n            return jsonify({'prediction': str(prediction)})\n\n        except:\n\n            return jsonify({'trace': traceback.format_exc()})\n    else:\n        print ('Train the model first')\n        return ('No model here to use')<\/code><\/pre>\n<\/div>\n<p>By default, a flask application runs on http:\/\/127.0.0.1:5000. Let&#8217;s customize this setting if the user wants to provide a specific port number during execution. The compiled file now looks like &#8211;<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-py\">from flask import Flask, request, jsonify\nimport joblib\nimport traceback\nimport pandas as pd\nimport numpy as np\nimport sklearn\n\n# Your API definition\napp = Flask(__name__)\n\n@app.route('\/predict', methods=['POST'])\ndef predict():\n    if lr:\n        try:\n            json_ = request.json\n            query = pd.DataFrame(json_)\n            print(query)\n\n            prediction = list(lr.predict(query))\n\n            return jsonify({'prediction': str(prediction)})\n\n        except:\n\n            return jsonify({'trace': traceback.format_exc()})\n    else:\n        print ('Train the model first')\n        return ('No model here to use')\n\nif __name__ == '__main__':\n    try:\n        port = int(sys.argv[1])\n    except:\n        port = 12345\n\n    lr = joblib.load(\"regression_model.pkl\")\n    print ('Model loaded')\n    model_columns = joblib.load(\"regression_model_columns.pkl\")\n    print ('Model columns loaded')\n\n    app.run(port=port, debug=True)<\/code><\/pre>\n<\/div>\n<p>Note that in the <code>load()<\/code> function, we have provided just the file name because we&#8217;re saving everything in the same directory. In case you encounter a <code>FileNotFoundError<\/code> during compilation, provide a full path instead.<\/p>\n<p>Let&#8217;s go ahead and compile the file to see if everything&#8217;s working correctly. We get the following output &#8211;<\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/07\/api-file-compile.png\"><img decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/07\/api-file-compile.png\" alt=\"\" width=\"793\" height=\"357\" class=\"aligncenter size-full wp-image-27657\" srcset=\"\/wp-content\/uploads\/2021\/07\/api-file-compile.png 793w, \/wp-content\/uploads\/2021\/07\/api-file-compile-300x135.png 300w, \/wp-content\/uploads\/2021\/07\/api-file-compile-768x346.png 768w, \/wp-content\/uploads\/2021\/07\/api-file-compile-600x270.png 600w\" sizes=\"(max-width: 793px) 100vw, 793px\" \/><\/a><\/p>\n<p>This means that our server is now active at http:\/\/127.0.0.1:12345. We now need a third-party application to send it a request and see what output are we getting.<\/p>\n<h2>Making real-time predictions<\/h2>\n<p>To send a request to our server, we will be using <a href=\"https:\/\/www.postman.com\/downloads\/\">Postman&#8217;s Desktop application<\/a>. There are several tools available for API testing, you can use whichever you prefer. The console will typically look like &#8211;<\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/07\/console_postman.png\"><img decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/07\/console_postman.png\" alt=\"\" width=\"1440\" height=\"887\" class=\"aligncenter size-full wp-image-27653\" srcset=\"\/wp-content\/uploads\/2021\/07\/console_postman.png 1440w, \/wp-content\/uploads\/2021\/07\/console_postman-300x185.png 300w, \/wp-content\/uploads\/2021\/07\/console_postman-1024x631.png 1024w, \/wp-content\/uploads\/2021\/07\/console_postman-768x473.png 768w, \/wp-content\/uploads\/2021\/07\/console_postman-600x370.png 600w\" sizes=\"(max-width: 1440px) 100vw, 1440px\" \/><\/a><\/p>\n<p>Let&#8217;s make the following changes &#8211;<\/p>\n<ol>\n<li>Change the method to <code>POST<\/code><\/li>\n<li>Within the <code>Body<\/code> tab, select <code>raw<\/code> and <code>JSON<\/code> as the Request format.<\/li>\n<li>Pass input as a list such as <code>[{\"Salnty\":34}, {...}]<\/code><\/li>\n<li>Hit <code>Send<\/code><\/li>\n<\/ol>\n<h3>Few things to note<\/h3>\n<ol>\n<li>Your <code>api.py<\/code> needs to run in the background, otherwise, the server will not be active and you&#8217;ll receive an error in the console.<\/li>\n<li>The input we&#8217;re sending is in a JSON format which uses a combination of lists and dictionaries. Therefore, it is important to pass your input in a <code>{key: value}<\/code> pair. In case of multiple attributes, your input will look like <code>{\"attribute1\": value1, \"attribute2\": value2, ...}<\/code><\/li>\n<\/ol>\n<p>We get the following output in the console &#8211;<\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/07\/prediction.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/07\/prediction.png\" alt=\"\" width=\"1920\" height=\"917\" class=\"aligncenter size-full wp-image-27656\" srcset=\"\/wp-content\/uploads\/2021\/07\/prediction.png 1920w, \/wp-content\/uploads\/2021\/07\/prediction-300x143.png 300w, \/wp-content\/uploads\/2021\/07\/prediction-1024x489.png 1024w, \/wp-content\/uploads\/2021\/07\/prediction-768x367.png 768w, \/wp-content\/uploads\/2021\/07\/prediction-1536x734.png 1536w, \/wp-content\/uploads\/2021\/07\/prediction-600x287.png 600w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/><\/a><\/p>\n<p>To double-check the input we got from the Postman console, check your terminal. It should have printed out the JSON query like &#8211;<\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/07\/console.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/07\/console.png\" alt=\"\" width=\"778\" height=\"443\" class=\"aligncenter size-full wp-image-27658\" srcset=\"\/wp-content\/uploads\/2021\/07\/console.png 778w, \/wp-content\/uploads\/2021\/07\/console-300x171.png 300w, \/wp-content\/uploads\/2021\/07\/console-768x437.png 768w, \/wp-content\/uploads\/2021\/07\/console-150x85.png 150w, \/wp-content\/uploads\/2021\/07\/console-600x342.png 600w\" sizes=\"(max-width: 778px) 100vw, 778px\" \/><\/a><\/p>\n<p>Congratulations, You just deployed your Machine Learning Model to make predictions in real-time! Check out <a href=\"https:\/\/griddb.net\/en\/blog\/\">similar posts on our webpage<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Outline In this tutorial, we will see how we can turn our Machine Learning model into a web API to make real-time predictions using Python. The outline of the article will be as follows: Prerequisites and Environment setup Creating a Machine Learning Model Serialization and Deserialization of the Machine Learning Model Developing an API using [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":26620,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[121],"tags":[],"class_list":["post-46656","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Performing Real-Time Predictions Using Machine Learning, GridDB and Python | GridDB: Open Source Time Series Database for IoT<\/title>\n<meta name=\"description\" content=\"Outline In this tutorial, we will see how we can turn our Machine Learning model into a web API to make real-time predictions using Python. The outline of\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Performing Real-Time Predictions Using Machine Learning, GridDB and Python | GridDB: Open Source Time Series Database for IoT\" \/>\n<meta property=\"og:description\" content=\"Outline In this tutorial, we will see how we can turn our Machine Learning model into a web API to make real-time predictions using Python. The outline of\" \/>\n<meta property=\"og:url\" content=\"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/\" \/>\n<meta property=\"og:site_name\" content=\"GridDB: Open Source Time Series Database for IoT\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/griddbcommunity\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-06T07:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-13T20:55:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/wp-content\/uploads\/2020\/06\/artificial-intelligence-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1280\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"griddb-admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@GridDBCommunity\" \/>\n<meta name=\"twitter:site\" content=\"@GridDBCommunity\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"griddb-admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/\"},\"author\":{\"name\":\"griddb-admin\",\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/person\/4fe914ca9576878e82f5e8dd3ba52233\"},\"headline\":\"Performing Real-Time Predictions Using Machine Learning, GridDB and Python\",\"datePublished\":\"2021-08-06T07:00:00+00:00\",\"dateModified\":\"2025-11-13T20:55:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/\"},\"wordCount\":881,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/griddb.net\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/#primaryimage\"},\"thumbnailUrl\":\"\/wp-content\/uploads\/2020\/06\/artificial-intelligence-1.jpg\",\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/\",\"url\":\"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/\",\"name\":\"Performing Real-Time Predictions Using Machine Learning, GridDB and Python | GridDB: Open Source Time Series Database for IoT\",\"isPartOf\":{\"@id\":\"https:\/\/griddb.net\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/#primaryimage\"},\"thumbnailUrl\":\"\/wp-content\/uploads\/2020\/06\/artificial-intelligence-1.jpg\",\"datePublished\":\"2021-08-06T07:00:00+00:00\",\"dateModified\":\"2025-11-13T20:55:28+00:00\",\"description\":\"Outline In this tutorial, we will see how we can turn our Machine Learning model into a web API to make real-time predictions using Python. The outline of\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/#primaryimage\",\"url\":\"\/wp-content\/uploads\/2020\/06\/artificial-intelligence-1.jpg\",\"contentUrl\":\"\/wp-content\/uploads\/2020\/06\/artificial-intelligence-1.jpg\",\"width\":1920,\"height\":1280},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/griddb.net\/en\/#website\",\"url\":\"https:\/\/griddb.net\/en\/\",\"name\":\"GridDB: Open Source Time Series Database for IoT\",\"description\":\"GridDB is an open source time-series database with the performance of NoSQL and convenience of SQL\",\"publisher\":{\"@id\":\"https:\/\/griddb.net\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/griddb.net\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/griddb.net\/en\/#organization\",\"name\":\"Fixstars\",\"url\":\"https:\/\/griddb.net\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png\",\"contentUrl\":\"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png\",\"width\":200,\"height\":83,\"caption\":\"Fixstars\"},\"image\":{\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/griddbcommunity\/\",\"https:\/\/x.com\/GridDBCommunity\",\"https:\/\/www.linkedin.com\/company\/griddb-by-toshiba\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/person\/4fe914ca9576878e82f5e8dd3ba52233\",\"name\":\"griddb-admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5bceca1cafc06886a7ba873e2f0a28011a1176c4dea59709f735b63ae30d0342?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5bceca1cafc06886a7ba873e2f0a28011a1176c4dea59709f735b63ae30d0342?s=96&d=mm&r=g\",\"caption\":\"griddb-admin\"},\"url\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/author\/griddb-admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Performing Real-Time Predictions Using Machine Learning, GridDB and Python | GridDB: Open Source Time Series Database for IoT","description":"Outline In this tutorial, we will see how we can turn our Machine Learning model into a web API to make real-time predictions using Python. The outline of","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/","og_locale":"en_US","og_type":"article","og_title":"Performing Real-Time Predictions Using Machine Learning, GridDB and Python | GridDB: Open Source Time Series Database for IoT","og_description":"Outline In this tutorial, we will see how we can turn our Machine Learning model into a web API to make real-time predictions using Python. The outline of","og_url":"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/","og_site_name":"GridDB: Open Source Time Series Database for IoT","article_publisher":"https:\/\/www.facebook.com\/griddbcommunity\/","article_published_time":"2021-08-06T07:00:00+00:00","article_modified_time":"2025-11-13T20:55:28+00:00","og_image":[{"width":1920,"height":1280,"url":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/wp-content\/uploads\/2020\/06\/artificial-intelligence-1.jpg","type":"image\/jpeg"}],"author":"griddb-admin","twitter_card":"summary_large_image","twitter_creator":"@GridDBCommunity","twitter_site":"@GridDBCommunity","twitter_misc":{"Written by":"griddb-admin","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/#article","isPartOf":{"@id":"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/"},"author":{"name":"griddb-admin","@id":"https:\/\/griddb.net\/en\/#\/schema\/person\/4fe914ca9576878e82f5e8dd3ba52233"},"headline":"Performing Real-Time Predictions Using Machine Learning, GridDB and Python","datePublished":"2021-08-06T07:00:00+00:00","dateModified":"2025-11-13T20:55:28+00:00","mainEntityOfPage":{"@id":"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/"},"wordCount":881,"commentCount":0,"publisher":{"@id":"https:\/\/griddb.net\/en\/#organization"},"image":{"@id":"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2020\/06\/artificial-intelligence-1.jpg","articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/","url":"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/","name":"Performing Real-Time Predictions Using Machine Learning, GridDB and Python | GridDB: Open Source Time Series Database for IoT","isPartOf":{"@id":"https:\/\/griddb.net\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/#primaryimage"},"image":{"@id":"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2020\/06\/artificial-intelligence-1.jpg","datePublished":"2021-08-06T07:00:00+00:00","dateModified":"2025-11-13T20:55:28+00:00","description":"Outline In this tutorial, we will see how we can turn our Machine Learning model into a web API to make real-time predictions using Python. The outline of","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/griddb.net\/en\/blog\/performing-real-time-predictions-using-machine-learning-griddb-and-python\/#primaryimage","url":"\/wp-content\/uploads\/2020\/06\/artificial-intelligence-1.jpg","contentUrl":"\/wp-content\/uploads\/2020\/06\/artificial-intelligence-1.jpg","width":1920,"height":1280},{"@type":"WebSite","@id":"https:\/\/griddb.net\/en\/#website","url":"https:\/\/griddb.net\/en\/","name":"GridDB: Open Source Time Series Database for IoT","description":"GridDB is an open source time-series database with the performance of NoSQL and convenience of SQL","publisher":{"@id":"https:\/\/griddb.net\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/griddb.net\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/griddb.net\/en\/#organization","name":"Fixstars","url":"https:\/\/griddb.net\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/griddb.net\/en\/#\/schema\/logo\/image\/","url":"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png","contentUrl":"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png","width":200,"height":83,"caption":"Fixstars"},"image":{"@id":"https:\/\/griddb.net\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/griddbcommunity\/","https:\/\/x.com\/GridDBCommunity","https:\/\/www.linkedin.com\/company\/griddb-by-toshiba"]},{"@type":"Person","@id":"https:\/\/griddb.net\/en\/#\/schema\/person\/4fe914ca9576878e82f5e8dd3ba52233","name":"griddb-admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/griddb.net\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5bceca1cafc06886a7ba873e2f0a28011a1176c4dea59709f735b63ae30d0342?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5bceca1cafc06886a7ba873e2f0a28011a1176c4dea59709f735b63ae30d0342?s=96&d=mm&r=g","caption":"griddb-admin"},"url":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/author\/griddb-admin\/"}]}},"_links":{"self":[{"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/posts\/46656","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/comments?post=46656"}],"version-history":[{"count":1,"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/posts\/46656\/revisions"}],"predecessor-version":[{"id":51331,"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/posts\/46656\/revisions\/51331"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/media\/26620"}],"wp:attachment":[{"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/media?parent=46656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/categories?post=46656"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/wp-json\/wp\/v2\/tags?post=46656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}