Data Science, ML and Analytics Engineering

Model deployment with Google Cloud Functions

In this note, I will tell you how to deploy a model for free up to a certain level of use and not bother with writing a microservice. I note that such a solution is easily integrated, for example, into a web service. All you need is to use Google Cloud Functions.

Google Cloud Functions is a serverless approach, i.e. server services are provided without renting or purchasing equipment. With this approach, the provider manages infrastructure resources, configures and maintains them.

The main advantage of Google Cloud Functions is automatic scalability, high availability and fault tolerance.

Read more

BentoML – Faster Machine Learning Prototype

In this post, I’ll show you how to create a working prototype of a web application with a working machine learning model in 50 lines of Python code. Imagine you have a cool project idea. Now you need to implement MVP (minimum viable product) and show it to your manager / partner / investor or just show off to your friends.

We will be using BentoML. It is a flexible, high-performance platform that is ideal for building an MVP.

BentoML features:

  • supports multiple machine learning frameworks including Tensorflow, PyTorch, Keras, XGBoost, and more.
  • own cloud deployment with Docker, Kubernetes, AWS, Azure and many more
  • high performance online service via API
  • web dashboards and APIs for managing model registry and deployment

Read more

Machine Learning Models in production: Flask and REST API

A trained machine learning model alone will not add value for business. The model must be integrated into the company’s IT infrastructure. Let’s develope REST API microservice to classify Iris flowers. The dataset consists of the length and width of two types of Iris petals: sepal and petal. The target variable is Iris variety: 0 – Setosa, 1 – Versicolor, 2 – Virginica.

Saving and loading a model

Before moving on to develope API, we need to train and save the model. Take the RandomForestClassifier model. Now let’s save the model to a file and load it to make predictions. This can be done with pickle or joblib.

import pickle filename = 'model.pkl'
pickle.dump(clf, open(filename, 'wb'))

We’ll use pickle.load to load and validate the model.

loaded_model = pickle.load(open(filename, 'rb'))
result = loaded_model.score(X_test, y_test) 

The code for training, saving and loading the model is available in the repository — link

Read more