Introduction to Embedded Machine Learning 2.4.1 - Anomaly Detection

Edge Impulse
3 May 202208:13

Summary

TLDRThis video delves into anomaly detection in machine learning, highlighting its utility in fraud detection and predictive maintenance. It uses the example of credit card fraud to illustrate how unsupervised learning can flag unusual transactions. The script also discusses its application in embedded systems, like predicting mechanical failures in factories or satellites, using NASA's bearing data as a case study. The tutorial demonstrates setting up anomaly detection using Edge Impulse, showing how to classify and detect anomalies in motion data with a microcontroller, emphasizing its practicality in identifying unexpected behaviors.

Takeaways

  • 💡 Anomaly detection is a vital technique in machine learning, used for identifying unusual patterns or outliers in data.
  • 🔍 It can be implemented through supervised or unsupervised learning methods, depending on the availability and nature of data labels.
  • 🛒 A common application of anomaly detection is in fraud detection, such as identifying suspicious credit card transactions.
  • 📈 The script uses a two-dimensional plot to illustrate how anomaly detection can spot purchases that deviate from a customer's typical spending pattern.
  • 🚫 Anomaly detection can help in flagging transactions that significantly differ from a cluster of 'normal' samples, even if they appear normal in individual dimensions.
  • 🛠️ The technique is not only useful in financial contexts but also in predicting mechanical failures in industrial and aerospace applications.
  • 📊 Historical data, such as vibration readings from bearings, can be analyzed to predict failures before they occur, which is crucial for maintenance and safety.
  • 📱 The script demonstrates how to use a smartphone and Edge Impulse to collect and classify motion data, identifying anomalies in real-time.
  • 🤖 Edge Impulse employs k-means clustering, an unsupervised learning algorithm, to define boundaries around normal data clusters and detect outliers.
  • 🔧 The anomaly detection model assigns an anomaly score to new samples, which helps in determining how far they deviate from expected patterns.
  • 💻 The script guides through deploying an anomaly detection model on a microcontroller, showcasing its practical application in embedded systems.

Q & A

  • What is anomaly detection in the context of machine learning?

    -Anomaly detection is a technique used in machine learning to identify data points that do not conform to expected patterns or other data points, often indicating irregularities or outliers.

  • How can anomaly detection be applied in fraud detection?

    -In fraud detection, anomaly detection can be used by credit card companies to identify unusual purchase patterns that deviate from a customer's typical spending habits, potentially flagging fraudulent transactions.

  • What is the significance of using multiple dimensions in anomaly detection?

    -Using multiple dimensions in anomaly detection allows for the creation of a boundary around clusters of samples, which is more effective than using simple thresholds in one dimension at a time, as it can better capture the complexity of the data.

  • How does the credit card company example illustrate the concept of anomaly detection?

    -The credit card company example shows anomaly detection by comparing a new purchase to a model of normal spending habits. If the new purchase falls outside the expected range in multiple dimensions, it is flagged as an anomaly.

  • What role does anomaly detection play in embedded systems?

    -In embedded systems, anomaly detection is crucial for predicting faults and mechanical failures before they occur, which can prevent significant damage and costs in industries such as manufacturing and aerospace.

  • Why is the NASA bearing data significant for anomaly detection research?

    -The NASA bearing data is significant because it provides a real-world dataset where researchers can test and develop anomaly detection algorithms to predict mechanical failures based on vibration data, before the actual failure occurs.

  • How does the Edge Impulse platform facilitate anomaly detection?

    -Edge Impulse allows users to connect their devices, collect data, and use machine learning models to classify and detect anomalies. It offers tools like spectral feature analysis and k-means clustering for anomaly detection.

  • What is k-means clustering and how is it used in anomaly detection on Edge Impulse?

    -K-means clustering is an unsupervised learning technique used in anomaly detection to find and define the boundaries of clusters in the data. On Edge Impulse, it helps in identifying if new samples are within the expected cluster boundaries or if they are anomalies.

  • How can anomaly detection be implemented on a microcontroller using Edge Impulse?

    -Anomaly detection can be implemented on a microcontroller by adding a k-means anomaly detection block in the Edge Impulse platform, training the model, and then deploying it to the microcontroller to classify and detect anomalies in real-time.

  • What is the purpose of the anomaly score in anomaly detection?

    -The anomaly score in anomaly detection indicates how far a sample is from the expected cluster boundaries. A score above a certain threshold suggests that the sample is an anomaly, which can be useful for alerting or taking corrective actions.

Outlines

00:00

🔍 Introduction to Anomaly Detection

This paragraph introduces anomaly detection as a vital technique in machine learning, applicable in both supervised and unsupervised learning contexts. It highlights its utility in scenarios where exact labels are unavailable or the nature of the data is uncertain. A practical application in fraud detection within credit card companies is discussed, where purchase histories are analyzed to identify unusual transactions. The concept is further illustrated through a two-dimensional plot representing customer purchases, emphasizing the challenge of detecting anomalies that don't fit typical patterns when viewed in isolation. The paragraph concludes with an overview of anomaly detection's broader applications, such as predicting mechanical failures in industrial settings and the use of historical vibration data from NASA's experiments to improve predictive models.

05:03

🛠️ Implementing Anomaly Detection in Embedded Systems

The second paragraph delves into the application of anomaly detection in embedded systems, focusing on the prevention of mechanical failures. It references a 2005 study where vibration data from bearings was collected until their failure, with the data now available for research and competition. The paragraph then transitions to a practical demonstration using a smartphone connected to an Edge Impulse project. The process involves classifying motion patterns and using spectral features to identify anomalies. The concept of anomaly detection through clustering is introduced, with k-means clustering being the chosen method. The steps to set up anomaly detection in Edge Impulse, including selecting axes and training the model, are outlined. The paragraph concludes with a discussion on deploying the trained model on a microcontroller, demonstrating how anomaly detection can be integrated into hardware to classify and respond to unexpected motion patterns.

Mindmap

Keywords

💡Anomaly Detection

Anomaly detection is a technique used in machine learning to identify data points that deviate from the norm, often indicating problems or unusual behavior. In the context of the video, anomaly detection is crucial for identifying fraudulent activities, such as unusual credit card transactions, by analyzing patterns and flagging outliers. The video uses the example of a credit card company monitoring customer purchase histories to illustrate how anomaly detection can help detect potentially fraudulent transactions that deviate from a customer's typical spending habits.

💡Supervised Learning

Supervised learning is a type of machine learning where the model is trained on labeled data, allowing it to learn from examples and make predictions or classifications. The video mentions that anomaly detection can be accomplished using either supervised or unsupervised learning, depending on the availability of labeled data. Supervised learning would be applicable if there are known examples of anomalies to train the model on.

💡Unsupervised Learning

Unsupervised learning, in contrast to supervised learning, involves training models on data without explicit labels. The goal is to find patterns or structures within the data. The video discusses using unsupervised learning for anomaly detection when exact labels are not available, such as in the case of detecting mechanical failures before they occur in embedded systems.

💡Fraud Detection

Fraud detection is the process of identifying and preventing unauthorized or illegitimate activities, often for financial gain. The video highlights fraud detection as a common application of anomaly detection techniques, particularly in the financial sector. By monitoring patterns in credit card transactions, anomaly detection can help flag unusual activities that may indicate fraudulent use.

💡Dimensionality Reduction

Dimensionality reduction is a technique used to reduce the number of variables under consideration, often to simplify the analysis or visualization of complex data. The video uses a hypothetical scenario where multiple features of a customer's purchase history are compressed into two dimensions for easier visualization on a two-dimensional plot.

💡Clustering

Clustering is an unsupervised learning technique that groups data points into clusters based on their similarity. In the video, clustering is used to create a boundary around normal samples, helping to identify anomalies by determining if new samples fall outside the acceptable range of the cluster.

💡Feature Compression

Feature compression is a method of representing complex data with a smaller set of variables. The video discusses compressing multiple features into two dimensions to visualize customer purchase data, which simplifies the process of identifying anomalies by reducing the complexity of the data.

💡Vibration Data

Vibration data is information collected from sensors that measure the vibrations of machinery or equipment. The video references a study where vibration data was recorded from bearings as they wore out, and this data is used to predict mechanical failures before they occur, showcasing the application of anomaly detection in predictive maintenance.

💡Embedded Systems

Embedded systems are computer systems designed to perform specific functions within a larger system, often in devices or machinery. The video explains how anomaly detection in embedded systems can predict faults and mechanical failures, which is particularly useful in industries like manufacturing or aerospace where equipment reliability is critical.

💡K-means Clustering

K-means clustering is an unsupervised learning algorithm that partitions data into K distinct non-overlapping subsets or clusters. The video describes using k-means clustering for anomaly detection, where the algorithm attempts to find the boundaries of feature clusters to determine if new samples are anomalies based on their proximity to these clusters.

💡Anomaly Score

An anomaly score is a measure of how much a data point deviates from the norm, often used to determine if it should be flagged as an anomaly. The video explains that after training an anomaly detection model, each new sample is given an anomaly score, which can be compared to a threshold to decide if the sample is an anomaly. This is demonstrated in the context of classifying phone motion data.

Highlights

Anomaly detection is a valuable technique in machine learning for identifying unusual patterns or errors.

Supervised or unsupervised learning can be applied depending on the availability and nature of data labels.

Anomaly detection is instrumental in fraud detection, such as identifying unusual credit card transactions.

Data features can be visualized in a two-dimensional plot to simplify the identification of anomalies.

Creating a boundary around clusters in multiple dimensions is a technique to flag anomalies.

Anomaly detection can prevent fraud by alerting credit card companies to unusual transactions.

Predicting mechanical failures in advance is crucial for maintaining equipment in factories and spacecraft.

Vibration data from worn-out bearings can be used to train models for predicting equipment failures.

Anomaly detection in embedded systems can prevent costly damage by identifying potential faults early.

Edge Impulse is a platform that can be used to connect smartphones for live classification of motion data.

K-means clustering is an unsupervised learning technique used for anomaly detection in spectral features.

Anomaly detection models assign a score to new samples to determine how close they are to known clusters.

Thresholds can be set to flag anomalies based on the anomaly score derived from the model.

The RMS values of each axis provide the best separation for anomaly detection in motion data.

Anomaly detection can be implemented on microcontrollers for real-time monitoring of equipment.

Anomaly detection systems can identify motions that are outside the expected norm, enhancing classification accuracy.

Anomaly detection is beneficial for ensuring the correct classification of data and identifying potential errors.

Transcripts

play00:02

[Music]

play00:06

anomaly detection is an incredibly

play00:08

useful technique in the world of machine

play00:10

learning we can use supervised or

play00:13

unsupervised learning to accomplish it

play00:15

depending on the type of data we might

play00:16

have if we don't have exact labels for

play00:19

things or we don't quite know what we're

play00:21

looking for anomaly detection can help

play00:23

us determine if something has gone wrong

play00:25

with our system a common use of anomaly

play00:27

detection techniques is in fraud

play00:29

detection let's say a credit card

play00:31

company keeps track of its customers

play00:33

purchase history it knows what kinds of

play00:35

things people buy on what days and it

play00:37

creates a model of each person's

play00:39

spending habits to make this easier to

play00:41

visualize let's pretend that all of

play00:43

these features can be compressed into

play00:45

just two dimensions that allows us to

play00:47

imagine the features as a

play00:48

two-dimensional plot with points each

play00:50

representing a purchase by the customer

play00:52

let's say that a new purchase happens to

play00:55

our eyes this doesn't look quite right

play00:58

we can intuitively see that this sample

play01:00

doesn't quite belong with the group

play01:02

however if a computer were to compare

play01:04

this with the group in any one dimension

play01:06

the sample would be acceptable it's less

play01:09

in the x direction than the rightmost

play01:11

normal sample and it's certainly less in

play01:13

the y direction than the highest

play01:15

purchase so what can we do to flag this

play01:17

as an anomaly one technique involves

play01:20

creating a boundary around the cluster

play01:22

of samples in multiple dimensions rather

play01:24

than using simple thresholds in one

play01:26

dimension at a time here we can see that

play01:28

our new sample is outside of this

play01:30

acceptable range and we can flag it as

play01:33

an anomaly in the case of our credit

play01:35

card company we might ask the customer

play01:37

if they really made this purchase or if

play01:39

the anomaly was bad enough maybe cancel

play01:41

the card and ship out a new one

play01:43

automatically this is a broad overview

play01:45

of what anomaly detection does there are

play01:48

many different techniques and algorithms

play01:49

that can be used to detect anomalies

play01:52

when it comes to embedded systems

play01:54

predicting faults and mechanical

play01:56

failures before they happen is extremely

play01:58

useful for things like factories large

play02:01

equipment and space faring vehicles back

play02:03

in 2005 researchers set up bearings to

play02:06

rotate for days and wore them out to the

play02:09

point of breaking they recorded the

play02:10

vibration data which you can see in

play02:12

these charts at some point about 30 days

play02:15

out all of the bearings broke

play02:17

this data has been made freely available

play02:19

on nasa's site and there have been lots

play02:21

of research and competitions using this

play02:23

data the idea is to try and predict

play02:25

anomalies in the vibration data long

play02:27

before the bearings break

play02:29

imagine applying this to things like

play02:31

large motors bearings or compressors in

play02:33

places like factories or maybe on a

play02:36

satellite if you could detect when

play02:38

something was about to break you might

play02:41

have the chance to repair it before it

play02:44

causes thousands or millions of dollars

play02:46

of damage

play02:47

this is why anomaly detection is so

play02:50

interesting in the world of embedded

play02:52

machine learning connect your phone to

play02:54

your edge impulse project by heading to

play02:56

smartphone.edgeimpulse.com

play02:59

in your project head to live

play03:01

classification start classifying and

play03:03

when your phone says it's collecting

play03:05

data start moving the phone in a known

play03:06

pattern like left to right then move it

play03:09

in a pattern that does not match

play03:10

something we've done before i'll move

play03:12

mine forward and backward when it's done

play03:14

you'll see that the model classified the

play03:16

left to right motions successfully but

play03:18

it attempted to classify the forward and

play03:20

backward motions as idle that makes

play03:22

sense because the x and z axes weren't

play03:25

moving which were the only axes that

play03:27

made any difference for the other

play03:28

motions however if you look at the

play03:30

spectral features plot you can see that

play03:32

our forward and backward samples seem to

play03:35

create their own cluster outside of

play03:37

other samples note that these are the x

play03:39

y and z rms values just like our credit

play03:42

card example we can clearly see that

play03:44

something is not right but our

play03:46

classifier isn't trained to pick up this

play03:49

motion so it classifies it as one of the

play03:51

four possible categories

play03:54

head to impulse design we can see that

play03:56

there's enough information present in

play03:58

the spectral features to separate

play03:59

anomalies so we can keep the spectral

play04:01

analysis block what we need is some form

play04:04

of anomaly detection so let's add that

play04:06

as a second learning block note that

play04:08

edge impulse is using k-means clustering

play04:11

which is an unsupervised learning

play04:13

technique that attempts to find the

play04:14

boundaries of each set of feature

play04:17

clusters save the impulse and head to

play04:19

the newly added anomaly detection page

play04:21

cluster count gives us the number of

play04:23

clusters that the k-means algorithm will

play04:25

look for in the data you should have at

play04:27

least as many clusters as you do classes

play04:30

but in practice you want more to account

play04:32

for variations in the data for example

play04:34

if one of your motions has the phone in

play04:36

different positions like pointing down

play04:38

instead of up you will likely have a few

play04:40

clusters in that one class feel free to

play04:43

play around with this number and take a

play04:44

look at where the clusters form in the

play04:46

output plot once we train the anomaly

play04:48

detection model any new sample will be

play04:51

given an anomaly score which determines

play04:53

how close it is to one of those clusters

play04:55

anything over zero is considered outside

play04:57

the cluster boundary and we can set the

play04:59

threshold here which is 0.3 by default

play05:02

you can select any number of axes to

play05:04

perform the k-means clustering algorithm

play05:07

on but as you saw earlier the rms values

play05:10

of each axis gives us the best

play05:11

separation so check each of the x y and

play05:15

z axes for rms and click start training

play05:18

when it's done the clusters should be

play05:20

assigned head to live classification

play05:23

repeat the same test as before moving

play05:25

the phone left to right and then some

play05:27

other motion like forward and backward

play05:29

when it's done take a look at the output

play05:31

there's a new anomaly column which tells

play05:33

you how much each sample is outside the

play05:35

norm for that class negative numbers are

play05:38

well within the normal limits for the

play05:39

class but anything over 0.3 is flagged

play05:42

as an anomaly sure enough if you look at

play05:44

the spectral features plot you can see

play05:46

where we started in the left right

play05:47

cluster and then moved out to our own

play05:50

cluster click on one of the anomaly

play05:52

predictions and it should highlight the

play05:53

sample showing you that it's far outside

play05:56

of one of the clusters feel free to try

play05:58

this again for any of the other motions

play06:00

but i'd like to show you this in action

play06:02

on a microcontroller open your arduino

play06:04

motion project in edge impulse and head

play06:06

to impulse design add a k-means anomaly

play06:09

detection block and click save impulse

play06:11

head to the newly created anomaly

play06:13

detection page and select all three rms

play06:16

axes click start training and wait a few

play06:18

moments for the clustering algorithm to

play06:19

complete when it's done head to the

play06:21

deployment page and download the arduino

play06:23

library

play06:26

you might need to delete the old library

play06:28

from your arduino libraries folder so

play06:30

that it does not conflict with your

play06:31

earlier one even if you are able to

play06:33

install both it makes it easier to keep

play06:35

track of which one you're using in

play06:36

arduino if you only have one

play06:39

start the arduino ide and include the

play06:41

newly downloaded.zip library go to file

play06:44

examples and open the accelerometer

play06:46

sketch we won't use the continuous one

play06:48

this time to keep things simple select

play06:50

the serial port and begin uploading this

play06:52

to your board this sketch should

play06:54

actually be the same as before the only

play06:55

difference now is that ei classifier has

play06:58

anomaly should be set to 1 and we should

play07:01

see an anomaly score printed to the

play07:02

console in your own application you can

play07:04

now use this result.anomaly value to

play07:07

determine if a particular motion is

play07:09

outside of what your model expects to

play07:11

see remember that in edge impulse we

play07:13

looked for this number to be over 0.3 to

play07:16

determine if something should be

play07:17

classified as an anomaly when uploading

play07:20

is done select your port again and open

play07:22

a serial monitor you should see the

play07:23

program sample for two seconds perform

play07:25

inference and then let you know what the

play07:27

results are notice that we also have an

play07:29

anomaly score now try performing one of

play07:31

the trained motions and you should see

play07:32

that it classifies the motions and gives

play07:34

you a negative anomaly score letting you

play07:36

know that it's quite sure the motion

play07:38

falls within the expected norm now try a

play07:41

motion that you didn't train for like

play07:43

forward and backward it should attempt

play07:44

to classify the motion but it should

play07:46

also give you a high anomaly score try

play07:49

some other motions that you did not

play07:50

train the model on or try performing one

play07:53

of the motions erratically to see what

play07:54

happens when it comes to classifying

play07:56

motion an anomaly detection system can

play07:59

be great for determining if something

play08:00

seems off or letting you know that

play08:02

something might not have been classified

play08:04

correctly

play08:10

[Music]

play08:12

you

Rate This

5.0 / 5 (0 votes)

相关标签
Anomaly DetectionMachine LearningFraud PreventionPredictive MaintenanceData AnalysisEdge ImpulseEmbedded SystemsK-means ClusteringUnsupervised LearningVibration Analysis
您是否需要英文摘要?