Habilelabs-Logo
Blog

A Complete Guide- Machine Learning model to API

September 2nd, 2022 . 3 minutes read
Blog featured image

Machine learning is the new over-the-top technology.

Python is used to create the Flask framework for web applications. The Werkzeg WSGI toolkit and the Jinja2 template engine serve as the foundation for Flask. They’re both Pocco projects.

Why Flask?

Unlike the Django framework, Flask is very Pythonic. It’s easy to start with Flask because it doesn’t have a learning curve.

Run it with python app.py

A web server that is exclusively accessible from your computer is subsequently started. You may view “Hello World” by visiting localhost on port 5000 in a web browser.

Save and Load Machine Learning Models

The Joblib component of the SciPy ecosystem provides tools for pipelining Python jobs. It provides resources for efficiently storing and loading NumPy-based Python objects.

For machine learning algorithms that need to preserve the entire dataset or have several parameter needs, this might be useful (like K-Nearest Neighbors).

Load Your Model

Final Step: Creating API

You may now host your API. But first, let’s review everything you did up to this moment.

Load Dataset and Select Features

  • Create a logistic regression model, save it to a file, and then load it to generate predictions on the unknown test set.
  • Then, using Flask, created a straightforward API that could determine, the Pima Indians onset of diabetes dataset.

Separate the code for your Logistic Regression model (model.py) and Flask API (app.py).

Consequently, your model.py should be as follows-

Your api.py file should be as follows-

Compile both Files-

Go on then see the terminal snapshot below, which was captured after both the.py

Testing API

  • After successfully launching the Flask server, you must input the correct URL and port number. It ought to resemble the following:

Now your client may use it to process the API output into something intriguing by using it from their front-end code.

Author: Divya Bhandari
Share: