Build a User Interface for your Machine Learning Model

Build a User Interface for your Machine Learning Model

How do data scientists share machine learning models/results?

So, you’ve built your machine learning model, trained, and scored it, it is ready to go! However, you’re now faced with a problem: How do you quickly share the model with the end users? Most models sit on Jupyter notebooks or python files but end users are not python developers so you cannot just email them a Jupyter notebook or a Python file. This leaves you with 3 options:

  1. The first option is to periodically run the model, produce a csv file and email it to the user or drop it in a shared folder for them to pick up when needed. The problem with this option is that the file is static. the user can only take the given results they cannot engage with the model itself.?For example, what happens to the recommendation if an input is changed by 1 unit? The user will not be able to answer this question. If the results look funny the user cannot rerun them, they will just have to override them.?
  2. The second option is to create a dashboard and display the result on it. This solves the emailing of the csv file problem or the need to drop the file on a folder. This eliminates a lot of human error, but the results are still static. The user is still not engaging with the model.
  3. The 3rd option is to build a UI for your model, a UI allows the user to interact with the model in real time, generate their own results and rerun them as they see fit. This also eliminates the need for the developer to run the results every Monday/ month end/ end of the week etc. No more static files. However, most data scientists are not web developers. And why should they be? This is where the Django machine learning user interface (Django ML UI) comes in.

Django Machine Learning User Interface

The Django ML UI is an open source program that allows data scientist to quickly build scalable and customizable front-end user interfaces for machine learning model. Here is a quick example:

Let us build a user interface for the titanic model.

Step 1: Install and Setup

  1. Open up a new working directory and create a virtual environment by running this command?python -m venv env on the command prompt.
  2. Run?env\Scripts\activate?to activate the virtual environment.
  3. ?Install the Django ML UI package by running?pip install django-machine-learning-user-interface.
  4. Run?cd env\Lib\site-packages\src?to find the package files.
  5. Open up the files on a code editor e.g. Vs Code.
  6. Install project requirements by running?pip install -r requirements.txt?on the command prompt.

Step 2: Secrete Key

  1. Generate a secrete key. You can use get one here: https://djecrety.ir/.
  2. ?Create a .env file in src and store you secret key inside.
  3. Make sure to label it?SECRET_KEY.

Step 3: Inputs

  1. Navigate to?src\input.
  2. Inside the input file create a folder and call it?model?then copy your pickle model file (e.g 'titanic.pkl') into this folder.
  3. ?In the?forms.py?file populate the class?IndexForm?as specified in the code comments.
  4. ?In the?params.py?file specify the name of the target variable (e.g. 'Passenger Status') and the name of the model (e.g 'titanic.pkl').

Step 4: Views

  1. Navigate to?src\interface\views.py.
  2. Add the cleaned form data as specified (line 21).
  3. List the x variables as specified (line 30).
  4. ?If your model is a classification model, edit line 41 as specified.

Step 5: Generate the User Interface

  1. On the command prompt run?python manage.py runserver.
  2. Go to local host on your browser(https://127.0.0.1:8000/) and you should see your application and be able to interact with it now. You're done.
  3. You can find the complete example here:


This program is still in it's pre-Alpha phase, and you guys are welcome to contribute. Here is the GitHub link:

要查看或添加评论,请登录

社区洞察

其他会员也浏览了