Reader small image

You're reading from  Machine Learning with the Elastic Stack - Second Edition

Product typeBook
Published inMay 2021
Reading LevelBeginner
PublisherPackt
ISBN-139781801070034
Edition2nd Edition
Languages
Right arrow
Authors (3):
Rich Collier
Rich Collier
author image
Rich Collier

Rich Collier is a solutions architect at Elastic. Joining the Elastic team from the Prelert acquisition, Rich has over 20 years' experience as a solutions architect and pre-sales systems engineer for software, hardware, and service-based solutions. Rich's technical specialties include big data analytics, machine learning, anomaly detection, threat detection, security operations, application performance management, web applications, and contact center technologies. Rich is based in Boston, Massachusetts.
Read more about Rich Collier

Camilla Montonen
Camilla Montonen
author image
Camilla Montonen

Camilla Montonen is a Senior Machine Learning Engineer at Elastic.
Read more about Camilla Montonen

Bahaaldine Azarmi
Bahaaldine Azarmi
author image
Bahaaldine Azarmi

Bahaaldine Azarmi, Global VP Customer Engineering at Elastic, guides companies as they leverage data architecture, distributed systems, machine learning, and generative AI. He leads the customer engineering team, focusing on cloud consumption, and is passionate about sharing knowledge to build and inspire a community skilled in AI.
Read more about Bahaaldine Azarmi

View More author details
Right arrow

Chapter 13: Inference

In this chapter, we will take an in-depth look at all of the fascinating things you can do with trained supervised models in the Elastic Stack. First, we will see how to use the Trained Models API to view information about the models available in our cluster, to see details about individual models, and to export models so that they can be ported to other Elasticsearch clusters. We will also take a brief look at how to use eland to import external models, such as those trained by third-party machine learning libraries, into Elasticsearch.

In the second part of this chapter, we will go in-depth into how to use trained supervised models with inference in a variety of contexts to enrich data. To do this, we will learn about inference processors and ingest pipelines and how these can be combined with continuous transforms, reindexing, and at ingest time when using various beats or otherwise ingesting data into Elasticsearch.

In this chapter, we will cover the...

Technical requirements

The material in this chapter will require an Elasticsearch cluster version 7.10 or later, and an installation of Python 3.7 or later with the eland, elasticsearch-py, and scikit-learn libraries installed. For detailed instructions on how to configure your Python installation to work with this chapter, please see the README section in the Chapter 13 - Inference and Advanced Transforms folder in the book's GitHub repository: https://github.com/PacktPublishing/Machine-Learning-with-Elastic-Stack-Second-Edition/tree/main/Chapter%2013%20-%20Inference.

Examining, exporting, and importing your trained models with the Trained Models API

You have prepared your dataset, trained your classification or regression model, looked at its performance, and determined that you would like to use it to enrich your production datasets. Before you can dive into ingest pipelines, inference processors, and the multitude of other components that you can configure to use your trained models, it is good to become familiar with the Trained Models API (https://www.elastic.co/guide/en/elasticsearch/reference/7.10/get-trained-models.html), a set of REST API endpoints that you can use to find out information about your models and even export them to other clusters. Let's take a tour of this API to see what it can tell us about our models.

A tour of the Trained Models API

In this section, we will take a practical look at using the Kibana Dev Console to examine things about our trained supervised models:

  1. Let's start in the Kibana Dev...

Understanding inference processors and ingest pipelines

You have a trained machine learning model, so now what? Remember from Chapter 11, Classification Analysis, and Chapter 12, Regression, that one of the exciting things about machine learning models is that they learn from a labeled training dataset and then, in a way, encode the knowledge so that they can be used to make predictions on previously unseen data points. This process of labeling or making predictions for previously unseen data points is what we call inference.

How does this happen in practice in the Elastic Stack?

There are a multitude of different architectures that you might build to make use of inference in the Elastic Stack, but the basic building blocks of all of them are inference processors and ingest pipelines. These are the main subjects of our exploration in this chapter.

An ingest pipeline is a special component that lets you manipulate and transform your data in various ways before it is written...

Importing external models into Elasticsearch using eland

Suppose you already have a model trained using one of the other frameworks. Is it possible to re-use the building blocks we discussed in the previous section to deploy your own externally trained models? The answer is yes, with a few limitations. In this section, we will take a look at how to use the eland library, along with scikit-learn, another machine learning library for creating and training external machine learning models and importing them into Elasticsearch for inference.

Learning about supported external models in eland

Unfortunately, the inference functionality in the Elastic Stack does not yet have support for importing an externally trained machine learning model from any library (though it might at some point in the future!). Instead, the eland documentation (https://eland.readthedocs.io/en/7.10.1b1/reference/api/eland.ml.MLModel.import_model.html#eland.ml.MLModel.import_model) contains a list of third...

Summary

In this chapter, we have looked at the various options available for using supervised models trained in Elasticsearch and external libraries such as scikit-learn. We have learned about the Trained Models API, which is useful when managing and examining trained supervised learning models in an Elasticsearch cluster and how to make use of these models to make predictions on previously unseen examples with the help of inference processors and ingest pipelines. In the appendix following this chapter, we will provide some tips and tricks that make it easier to work with the Elastic Machine Learning stack.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Machine Learning with the Elastic Stack - Second Edition
Published in: May 2021Publisher: PacktISBN-13: 9781801070034
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (3)

author image
Rich Collier

Rich Collier is a solutions architect at Elastic. Joining the Elastic team from the Prelert acquisition, Rich has over 20 years' experience as a solutions architect and pre-sales systems engineer for software, hardware, and service-based solutions. Rich's technical specialties include big data analytics, machine learning, anomaly detection, threat detection, security operations, application performance management, web applications, and contact center technologies. Rich is based in Boston, Massachusetts.
Read more about Rich Collier

author image
Camilla Montonen

Camilla Montonen is a Senior Machine Learning Engineer at Elastic.
Read more about Camilla Montonen

author image
Bahaaldine Azarmi

Bahaaldine Azarmi, Global VP Customer Engineering at Elastic, guides companies as they leverage data architecture, distributed systems, machine learning, and generative AI. He leads the customer engineering team, focusing on cloud consumption, and is passionate about sharing knowledge to build and inspire a community skilled in AI.
Read more about Bahaaldine Azarmi