cover-img

Step-by-step tutorial to deploy a Machine Learning model with Streamlit.

Forecasting closing price of Ethereum from past data using Neural Prophet and deploy it using Streamlit.

17 November, 2022

9

9

4

What is Streamlit?

Streamlit is an open-source and free framework to build web apps for Machine Learning and Data Science. It is a Python library. As we know, Machine Learning engineers and Data Scientist are not much good at the front end, so using Streamlit one can build a cool web app in just few lines of code. It's easy to use and learn.
In this blog, I will build one basic machine learning model and then deploy it on Streamlit which has a nice front-end built using Streamlit library.

Create a simple Machine Learning model

First, we create a simple Machine Learning model so that later we can deploy it on Streamlit.
Here, we'll create a simple crypto price prediction with the Neural Prophet. Neural Prophet is a simple machine learning model which is used to predict time series data. We are forecasting price of Ethereum using this model.

Data Collection

Here I'm using historical price data of Ethereum, which is downloaded from Crpto Data Download. Data is from 13-09-2015 to 13-09-2021 which include Open and Close price, High, Low, Volume of Ethereum.
img

Historical data of Ethereum

Now using Pandas library to read csv file.

Model Building

The data we are using has no null values, so here, we don't need of data cleaning. And also Neural Prophet accepts values without scaling, so we don't need to do scaling of data.
Now create dataframe of just two columns, Date and Closing price, because we need only these 2 columns to create a model. Also, we have to change the name of the column Date to ds and Close to y. Because our model accepts it only if it has these names as columns.
So we have dataframe which has only 2 columns named ds and y where ds is date and y is closing price on that day.
Now create a model and train it on this data, as shown below.
For forecasting price, first create future dataframe and then predict price for that data, code is shown below. Pass number of days as periods, which show size of future dataframe. It means we are going to forecast the price for the next 30 days.
Now save the model, so we can use it in deployment with Streamlit.
So we have a model, and now we are going to make a nice web app using Streamlit.

Create a web app using Streamlit

Python code for building front end using Streamlit

Import libraries which we are going to use in code.
You can check out how your web app looks by running it on localhost by typing it in terminal > streamlit run your_script.py
Create the title of our web app and put an image.
Create a sidebar in which the user can enter starting and ending date and period of forecasting price.
Showing first and last 5 rows of data of particular time period entered by user.
Showing chart of closing price and Volume of Ethereum of particular time period entered by user.
Forecasting price using the Neural prophet model. Also showing the predicted price and line chart.
So now, after creating code, it's time to deploy it.

Deploy on Streamlit Cloud

For deploying first, we need to make a repository in GitHub. So upload all the files and other than this create one 'requirements.txt' file which includes which libraries we have used for creating streamlit web app
Here our requirements file contains these all libraries as shown below.
pandas==1.4.3 matplotlib==3.5.2 streamlit==1.9.0 Pillow==8.2.0 neuralprophet==0.3.2
Now go to the Streamlit and create an account or log in if you already have one.
After log in screen is looking like this:
img
Now click on 'New app' for deploying our app. By clicking on it, it'll lead to this screen. Select your repository, branch, and main file path of python file. Or you can just paste a link of a Python file by clicking in 'Paste GitHub URL'.
img
Now click on 'Deploy!' and that's it. It will take some time for deployment, so wait for some time.
This is how web app looks:
img
Here's the GitHub repository of this project, also you'll find a streamlit web app link there.
You can make a front end of your choice, you can add more things by writing some line of code. You can check out docs of Streamlit here.
Here is Cheat Sheet of some of the code of Streamlit as a summary of docs.
Thank you for reading it!! If you enjoyed it then like and share it
Connect with me on Showwcase and Twitter for more Machine Learning and Deep Learning related content.

python

tutorial

develevate

streamlit

9

9

4

python

tutorial

develevate

streamlit

Kishan Modasiya
Data Engineer | Machine Learning & Deep Learning Enthusiastic | Python

More Articles

Showwcase is a professional tech network with over 0 users from over 150 countries. We assist tech professionals in showcasing their unique skills through dedicated profiles and connect them with top global companies for career opportunities.

© Copyright 2024. Showcase Creators Inc. All rights reserved.