4G payload Forecasting Deployment using Streamlit

Syifa Silfiyana
4 min readJul 16, 2020

--

Base Transceiver Station (BTS)

A few months ago, I did a data science project in telecommunication network. My team and I tried to make model for forecasting of 2G, 3G and 4G payload at one of telecommunication operator. Payload is the amount of internet data sent on the network, in this case telecommunication network and usually in bytes (KB, MB, GB, etc). There were many steps in preprocessing the data so the data was really appropriate to make machine learning model, in this case forecasting model. However, those explanation will be described on other post. In this post, I just want to share the part of machine learning model deployment. By deploying it, a machine learning model not just a script on the jupyter notebook but it becomes a system.

Note: In this article, I select a model to forecast 4G payload in certain area, only four area (Bandung, Maluku Tenggara, Kota Bogor, Kota Medan and Kota Kota Pontianak). I transformed the data because of confidential reason.

Save Model

The first step in deploying machine learning model is saving the model. By saving the model, I don’t need to retrain machine learning model every time I want make forecasting or predictions. Save model into file and then restore them in order to reuse them : to make prediction on new data for example. Model can be saved into many types of file like pickle, Joblib, JSON, and .h5. I saved my model into .h5 file.

save machine learning model into h5 file.
summary of model.

To reuse the model, only need to load the model using library from python, because I used keras so just need import load_model from keras.

import load_model library to reuse the saved model.

And then recall the model.

load the model.

Deploy Model

As we know that one of ways to deploy machine learning model is using Flask but I will use Streamlit to deploy my machine learning model. Why Streamlit? Because I wanted to make an interactive visualization with simplest way and Streamlit can afford provide it.

So, what is Streamlit?

Streamlit is open source python library to build beautiful custom web-app for machine learning and data science.

Streamlit is python library so we need to install it for the first time. To install just type pip install streamlit on anaconda prompt and to use it run the script of python with command streamlit run [filename of python].

As soon as issued command above, a local Streamlit server will spin up and app will open in the web browser. With Streamlit can be added text, chart, widgets, tables and more, so that why I like Streamlit :). Some of main concepts of Streamlit are:

  • Development flow

Every time want update the app, just save the source file.

  • Data Flow

Any time updated on the screen, streamlit just rerun entire python script from top to bottom.

  • Chaching

With cache concept, the app will execute quickly even when loading data from the web.

  • Drawing content

Whenever want to draw something to screen just used st.write()

  • Widgets

There are many widgets that can be added like Slider bar, select box, or button.

More information regarding Streamlit can be accessed here.

Lets deploy my forecasting model!!

  1. I’ve already installed the Streamlit so I will skip the installation process.
  2. The second step is create python script which will run using Streamlit. Below, example of my python script, the full script can be accessed on my github.
import libraries and data, add slider on the apps.
add title, text and check box on the apps.
Load model and make forecasting.
Plot the graphic and button with name ‘Forecast’.

3. Run above python script on the anaconda prompt through enter to the folder where the script, data and model are saved and issue the command streamlit run [filename of python], in my case streamlit run 4G_deploy_RNN_edit2.py

Issue command streamlit run 4G_deploy_RNN_edit2.py

Streamlit server will spin up and app will open in the default web browser.

Viola!! below the result:

Result of deployment using Streamlit

It can be seen that my model already deployed with quite pretty view, I can zoom in, zoom out on the graphic, there is also tooltip and so on. So, I can easily present the result of model to other team.

Hopefully this article is useful. Thank you for reading :)

--

--

Syifa Silfiyana

Data Scientist, Traveler and loves writing and reading.