Reader small image

You're reading from  Practical Guide to Azure Cognitive Services

Product typeBook
Published inMay 2023
PublisherPackt
ISBN-139781801812917
Edition1st Edition
Right arrow
Authors (3):
Chris Seferlis
Chris Seferlis
author image
Chris Seferlis

Chris Seferlis is an Account Technology Strategist at Microsoft. He has over 20 years of experience working in IT and solving technology challenges to accomplish business goals. Chris has an MBA from UMass, bringing a mix of business acumen, with practical technology solutions, focusing on the Microsoft Data Platform and Azure.
Read more about Chris Seferlis

Christopher Nellis
Christopher Nellis
author image
Christopher Nellis

Christopher Nellis is a Senior Infrastructure Engineer and is experienced in deploying large-scale infrastructure for organizations. He has a passion for automation and MLOps and enjoys working with people to solve problems and make things better.
Read more about Christopher Nellis

Andy Roberts
Andy Roberts
author image
Andy Roberts

Andy Roberts is a seasoned Data Platform and AI Architect. He has dawned many hats in his career as a developer, dba, architect, project lead, or more recently a part of a sales organization, the heart of his job has always revolved around data. Acquiring it, shaping it, moving it, protecting it and using it to predict future outcomes, processing it efficiently.
Read more about Andy Roberts

View More author details
Right arrow

Identifying Problems with Anomaly Detector

As we've seen so far in this book, there are many opportunities where we can use artificial intelligence (AI) with the help of Cognitive Services for a variety of purposes to improve business operations and add value. When we look at the Anomaly Detector service, we will change our focus a bit and examine how Ocean Smart was able to reduce the risk of inventory and raw materials being spoiled. Through the years, millions of dollars worth of product has had to be written off due to spoilage that could potentially have been avoided. With better monitoring and notifications, these unfortunate and costly occurrences could be avoided.

The Anomaly Detector service allows us to monitor streams of data for unexpected or irregular events. We will examine how we can do this with single and multiple, univariate and multivariate, streams of data to recognize and alert about these events as part of daily operations. Our example will take us through...

Technical requirements

To build your Anomaly Detector solution, you will need to have an Azure subscription with at least Contributor rights to the subscription for deploying services. You will need an Azure Storage Account for storing your documents pre- and post-processing. If you plan to deploy the solution to a Docker container or an Azure Web App, you will need experience with those technologies to ensure proper deployment. You will need to have Visual Studio Code (VS Code) (https://code.visualstudio.com/Download) with the node.js extension installed (https://nodejs.org/en/download/package-manager).

Some other services you may use for your deployment are as follows:

  • Azure Function: This is for building functions and executing code.
  • Azure Data Factory or similar: This is for data orchestration and transformation.
  • Azure Logic App: This is for workflow and triggering mechanisms.
  • Azure Database: This is for storing output data post-processing.
  • Azure Stream...

Overview of the Anomaly Detector service

Anomaly detection is notably one of the most difficult activities presented to any data scientist or AI developer. Many will opt to not work on anomaly detection projects at all due to their inconsistent nature. This is the best way we can think to preface this chapter; it is daunting to get it right, and seemingly even when we get it right, it changes very quickly, as with all technology. As we navigate through the features of this Cognitive Service, try to keep this sentiment in the back of your head to ensure we are approaching the subject in a sobering fashion.

Merriam-Webster defines anomaly as something different, abnormal, peculiar, or not easily classified: https://www.merriam-webster.com/dictionary/anomaly.

So, when setting out to build the Anomaly Detector Cognitive Service, Microsoft determined its customers could leverage an API where any stream or collection of streams of data might occasionally contain anomalous behavior...

Using the Anomaly Detector algorithms with your data

When looking at options for detecting anomalies using the Multivariate service, we can use the Async or Sync API. Your use case will dictate which one you choose, but typically the Async process is used for looking at a batch of data and pointing out the anomalous data points. The Sync process is typically used for real-time data monitoring for anomalies. This can be determined based on your particular need depending on the latency of the data and the number of data points. Let’s start with the Async API first.

Async API

To get the status of the detection activity with the Async API, you must request the status from the service by choosing the proper API. To do so, you must use the Request URL to display your Anomaly Detector service with models created earlier. After your model has been trained and you are ready for inferencing with another dataset, you can use the same process of sending your request through the API...

Configuring and refining monitoring of data in your environment

Now that we have had a chance to look at what the Async and Sync APIs offer in the way of anomaly detection and the differences between the Univariate and Multivariate services, let’s look at how to put this detailed understanding of the APIs into practice.

In the example we built for later in this chapter, you will find that we wanted to provide a simple example of how to send data from our freezer into Azure to leverage the service using an Event Hub. If we did not have the option to send the data to the cloud because of security reasons, or unavailability of internet connectivity, we could have used the Univariate service in a Docker container deployed to an IoT device. This could present other challenges for how to report on the anomalies and trend analysis but could be handled with other Microsoft products that can still be deployed on-premises, such as Power BI Report Server. Currently, only the Univariate...

Defining and detecting anomalies in your organization

Beyond giving examples of how the services can be deployed, this book intends to provide some insight on how to apply AI, hopefully helping to streamline operations and other related benefits. When you start to analyze activities where you might be able to use AI, it helps to look at where unexpected events can occur and how you can better predict the potential for failure. Even if the prediction is especially challenging, there is likely an opportunity to monitor equipment and other capital resources for unexpected events and develop predictability over time.

An area of interest where Ocean Smart could expand is to use the Multivariate detector to look at the overall freezer health, including some of the various elements of a freezer. Then taking that example, similar logic could be applied across locations for all freezers and chillers. This could potentially save significant electricity overhead costs and extend the life of...

Building the complete solution in Azure

Here, we will use the Anomaly Detector service to look for anomalies in refrigerator temperature readings. This example is a slice of what might exist in a real-world implementation; however, we have simplified the flow so we may concentrate on the Cognitive Service and not a full-blown IoT implementation. For our example, we will use the following diagram as our reference architecture:

Figure 9.2 – Reference architecture for the example of building an anomaly detector in an operational service

Figure 9.2 – Reference architecture for the example of building an anomaly detector in an operational service

The basic building blocks of this solution include the following:

  • An Azure function to simulate the refrigerator readings.
    • For ease of deployment and to keep things in one place, for this example, we have implemented the simulator as an Azure function. You could take the same basic code and implement it outside of Azure as well – as long as you have connectivity to the Azure Event Hub.
  • An Azure Event...

Summary

As stated earlier in this chapter, anomaly detection can be a very challenging activity for any organization. As with the story of “The boy who cried wolf,” when too many false positives occur, it can impact our decision-making. If we become complacent with our responses, it can cause tremendous issues in the way of costs and safety. With this in mind, it is recommended to ensure a deep analysis of pros and cons is performed for the example you want to test the service with. However, as we have displayed throughout this chapter, there are many of these considerations that have been taken into account for the service, and many options are available to hopefully avoid an abundance of false positives. Alternatively, there are certainly many advantages to having a finely tuned anomaly detection service in place that can help augment human monitoring of specified conditions. We have our typical return on investment (ROI) and total cost of ownership (TCO) analysis,...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Practical Guide to Azure Cognitive Services
Published in: May 2023Publisher: PacktISBN-13: 9781801812917
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
Chris Seferlis

Chris Seferlis is an Account Technology Strategist at Microsoft. He has over 20 years of experience working in IT and solving technology challenges to accomplish business goals. Chris has an MBA from UMass, bringing a mix of business acumen, with practical technology solutions, focusing on the Microsoft Data Platform and Azure.
Read more about Chris Seferlis

author image
Christopher Nellis

Christopher Nellis is a Senior Infrastructure Engineer and is experienced in deploying large-scale infrastructure for organizations. He has a passion for automation and MLOps and enjoys working with people to solve problems and make things better.
Read more about Christopher Nellis

author image
Andy Roberts

Andy Roberts is a seasoned Data Platform and AI Architect. He has dawned many hats in his career as a developer, dba, architect, project lead, or more recently a part of a sales organization, the heart of his job has always revolved around data. Acquiring it, shaping it, moving it, protecting it and using it to predict future outcomes, processing it efficiently.
Read more about Andy Roberts