Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Machine Learning with the Elastic Stack - Second Edition

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

Product type Book
Published in May 2021
Publisher Packt
ISBN-13 9781801070034
Pages 450 pages
Edition 2nd Edition
Languages
Authors (3):
Rich Collier Rich Collier
Profile icon Rich Collier
Camilla Montonen Camilla Montonen
Profile icon Camilla Montonen
Bahaaldine Azarmi Bahaaldine Azarmi
Profile icon Bahaaldine Azarmi
View More author details

Table of Contents (19) Chapters

Preface Section 1 – Getting Started with Machine Learning with Elastic Stack
Chapter 1: Machine Learning for IT Chapter 2: Enabling and Operationalization Section 2 – Time Series Analysis – Anomaly Detection and Forecasting
Chapter 3: Anomaly Detection Chapter 4: Forecasting Chapter 5: Interpreting Results Chapter 6: Alerting on ML Analysis Chapter 7: AIOps and Root Cause Analysis Chapter 8: Anomaly Detection in Other Elastic Stack Apps Section 3 – Data Frame Analysis
Chapter 9: Introducing Data Frame Analytics Chapter 10: Outlier Detection Chapter 11: Classification Analysis Chapter 12: Regression Chapter 13: Inference Other Books You May Enjoy Appendix: Anomaly Detection Tips

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 2021 Publisher: Packt ISBN-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.
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}