Jump to content
  • Case study in Anomaly Detection using Autoencoder-based Spotfire Template


    Introduction

    Here’s a walkthrough of using the Spotfire anomaly detection template on the Case Western University Ball Bearing data. This dataset is commonly used as a benchmark for bearing fault classification algorithms, which contains vibration signal data of normal and anomalous bearings. It has been widely studied - see the references here for example: Lite and Efficient Deep Learning Model for Bearing Fault Diagnosis Using the CWRU Dataset - PMC - Yoo et al.

    Additional information is available at https://www.kaggle.com/code/brjapon/crwu-bearings-svm-fault-classification

    The data is actually oriented towards classification of anomalies. We have repurposed it here to include unsupervised anomaly detection and clustering.

    Part 1: Split The Data

    The data consists of 33 columns of data. The first column is a sequence number. The other 32 are measurements from various sensors. There was no timestamp, so we generated an artificial one to identify each row.

    There are 147,201 rows.

    Note - we have renamed the columns so that each column number has a 2-digit identifier. The reason for this will become clear below.

    Here’s a snippet from Spotfire:

    7wc77uDuCcX88OEDUSFqb9Ui6ar1l5e4Fk76icfbFZ4lprTMeAbBUzZ7kfQjFjomWNXFcUWZ6BmO3dEqeNvkOcjymBkspjGiCBXiU59NNP8IoYjFM8MuJryBrnsqEHpqYhYhAianVcmfZMhm1_ghkBg

    The data is available from https://www.kaggle.com/datasets/brjapon/cwru-bearing-datasets/download?datasetVersionNumber=1 (registration at Kaggle.com required and free)

    Unlike a raw dataset, this is organized into 10 sections, each representing measurements adjacent in time. The first 9 are each examples of specific anomalies, while the last section is the golden batch, aka Normal Operating Conditions. The labels for these sections are available in a separate file, but were not used here, because part of our purpose was to test unsupervised anomaly detection.

    The Golden batch can be seen clearly in the visualizations of the raw data. For example:

    4XOQZsrT32Ef_gZUwB24GpOTA34vdmFXbZrUSMMtDJTsUhYRFZ5U0rZVgx1vNTAYJFs5OoM56PlvK8hciE4lOgPHC_h3-hiyQnI5X231U5_2KUt58TscumVmoJWMuLiBzDpbgQMXuGI9VdOv7uwEkL8

    Note that the Anomaly Detection dxp also can work with data that does not have a defined subset for NOC, accomplished by using robust methods. Here, we select the Training and Validation samples from the NOC to get the best possible model that describes the NOC. The test sample can then be used to predict the reconstruction error in the test sample.

    These figures show how we did this:

    1. Mark a date range within the NOC portion of the sample:

    _P1TP4j6gMtFr2xF92A66uMDMBsyiSjd9M_gpHaij0w7p2JTEce3sg7DSM3lxkYupZo2tZay1D9BhvV8c-TIMyxrofrmoC-HRUAU_LX_4o1p9Xd7PGnrIX6EwCaKId2bLxc1z8ghJXT5Y-hNFdRpeHg

    1. Then press the “Training Sample” button to assign these points to the training sample.

    RzhJV0KEvHWEObSqwQEFpxheU-AbJeVXI59_IxPDJZsrVwKkgWXFI2MFQjlH-t3EvsK5TKQ66JIc-h5RH9fBpID2OhQV74s4xIlaLKf9ozDu2Nf4GW9J3QjUSKkK942HJFxExqXX87uyahuoVZIWWlA

    1. Define the validation sample similarly, still within the NOC.

    wbh3KSlU6Sfmch49NQa31kbU0gPMMfTveHk-dwXI7P14nbtZzm9b9lh67VLhq30OU9rSaSXkeo9uTJ0rWCHyr9d8nkKkoY1j46UfGuq76YWD7aDaAPaOhwBJ5ohgkNW_SIBfw1vKK6ZIi3P68pEmaoo

    4. Press the “Validation Sample” button.

    8Z5WzbKavzXFHKbfhP5y6veYheV1HMFk5QijXzxZoF9lh4rViWywsmBwd6cTxEXi9vCZYo4aL-k9RlVqxTZLZkHJW7LRL6BPpHHuNeqno8oesnRMqKYLdE3-9PaLiED66hwuDty1WvgNtSbJ78--gwk

    5. Define the Test Sample; this should be outside the NOC. Here I’m using all the rest of the data, but you can use a subset, which may help speed up the processing.

    z8AwFh4irK6NGXoeOw-KEQZU5XXB4Dt-aQQ2-ftHHfWwj8RLad9PCC7cHYMsnKci8XkoG6K-MbxzXnm1ZuUBOmZ-jeet0f7ZFXLxVooiNtW-0qlPqr4f1rA2WFah4FNvg-2hTKev4Bm5irMdpGQZxRQ

    6. Press the “Test Sample” Button to register your choice.

    5BB1zTwaC4wdUC-X9bh4s0Px-vsS6fGRiu29qB5BGAVBhnd5EyC4-vaHyL_h5GxywzfxqSVrR4HG1SF02pRWCJXtPwnQBfsoBonyooK0jR-IHNq-I8Kpxa5eSsO3jVux2WdeK9vIPf5B-lXw_L1ZHO4

    This ensures that the model is trained and validated on NOC, while also scoring and reporting on a test sample known to have anomalies.

    Part 2: Select and Configure Predictors

    The dxp is configured to allow selection of which variables to include in the analysis. We want all the variables to be included in the analysis with the exception of the label and the timestamp. The table of variables looks like this:

    Top:

    aGySrDwcWvwZU5NBTT8h_ifOXD1ef16lsue07FDKIt73tG8F3wEJscjUrsgNdzwg7qyfAo6AcXy65qCIdeE3IYXmwdcrxVeFx15cQmCW_KUMA4LnBLUiMjBW-_GKj7XCoxnPhWM8jA6Y_1vW8w3VdAs

    Bottom:

    8R2IyXMNKxyn7-DFX3AnvScqrUt2RBfFz3VKaZaw6aGA6gXonFaB2wNryZ1eCSx2DayIqxBi7u-dMzs5jzAC33zUhyvjiiO9-X8uhsPG5IYZTLWzhvy8YZK4q0Y2Vi3cWQWOvNr1ZjcfL__GHkabblk


    We then created 5 sets of parameters (including LSTM as well as Autoencoder modeling techniques) which resulted in the fitting of 5 models:

    fKrA4oR_ie3b19TtCBp-b_8ofE5R84nHtHnbA82iosk2MoHcWU9sYb54lY_qczp-GYhhfVzR11wg4DVXqnQ6qslJQxOUdISpqoWhB5bLKh7INlWpt7SBkJHO63xAeIIUx2_xzzCLFV5hiOePtoWtFBE

    Part 3: Compare Fitted Models

    6rV-Rw9x5TEoxIKP7IfvH5ltDJ0kRlw-KbT9API2OyTW9b-JNFPrBFmrTUPKEb3QuV8DA0uCXzTuQEoNnwLIzUGwcVaS3ui8JOkY38I4MFcwYaBV_XM6De-pDZYIkhjGNWBY1f_GFSA--UX-4zXBfFQ

    The table above shows some summary statistics for the 5 models. In addition, we show 5 learning curves, with trajectories for the Training and Validation samples. For LSTM method, increasing the lookback parameter shows only a small reduction (improvement) in the validation error. Autoencoder method with the same neuron structure as LSTM is better, which means introducing lookback does not bring value. It seems that looking at individual time points instead of looking also at the previous points is sufficient. Therefore, for our purposes, we will select Model1AE and see what we can learn from it.

    Remark: Further training may improve the fit. Also, additional improvements may be possible by exploring the hyperparameters. 

    Part 4: View Results

    Reconstruction Error Time Series

    b14rqFGhU_1lKDVx8hU0TFAvgODn1zudO6_LTzYui0bsQmeMq9tmoAhb-I6uivDkVPCyPeYDMXN7Yknbza-MRHaHMc_5Xt9SRcePyOwi61zkqgoekOVmIPFMB1VtjDcSmhwOKocVg3Fr75z9LXttRx4

    The colors show the sample (Train, Validation, Test) for each point; the training and validation samples are the points on the far right. Recall that these represent NOC. As such, the reconstruction errors are quite small since this is where the model was trained and validated. The majority of the points are from the test sample. These show higher reconstruction errors, indicating that they are anomalous versus the baseline.

    Let us zoom in to the Training and Validation set first. We can see that all reconstruction error values are comfortably below the value 4. Please, compare the scale of this graph and the graph above which includes the validation set as well. 

    EbCQeidmVOBm0cruz-W8VuefvjqGqr7qYc0nQEs0ltsNRIP_cRmidZDZRJ-PSfpPUTPD8aTTI5XOl7cIgHOQHWM4KlZ2SksLoiZvwg3Bl6dvT2CcoJLrb131S8KGi6jbVYr1FCJwtznue9_nh8p2P74

    Now, let us focus on the anomalies section. There are 9 different anomaly situations, so let us display some of them (notice the scale is different for these):JJU-grE6JTWcPiV02HYyUnw3jodhfkCfQIkIAik8x_pLtfUWiEUcpfGyAzoys88pwbhxLtYRAzucA-sGRaAGuopXpKgmiJnc_pILKMPuipTIwI-yfLseYcGi5oJyIFqcoPK21mGOnC70If2fppSHoOoZB8GhJ-_00it2YWXdRhM6THvuu8rvvWbVSNjCdPEdNtknEWGDQg-MXK2EgG6YRnu0eLL4i6FD0xF3t6c_eBpao0rJDX8jkDkTC2vVhflPugzdXBYboP_eBf9Hkzv7znwQsGb0COzdoXoCBVOBZsHjFQ0ZW02CiqiFJVZ4ixzvBEhyn2tMxvLF1Z6UUFuLw3NMUSH0eQlhTpc6pdgVE3s8xk7IaHLDPUYK60NFODjIsz-3nR46EbG4UpjdFCc0vtHiYWFuZ_fvvu-QrTmkYHW57iBosHHTvRIfyZ-I64qiul67QRxOLmdBe1WOXUJ-Z4IRDPi6fatDCKzENXJEcE77QuVo_rJ1n7gaWRR5et94h0WXApZA5yc6lhe0zEOKF-wJykfys43lAS2g3QqBil_RgoMyrnb2BCScQsMZdBLtcRtXOW86qm3iTRrjfqf7cZ15ko4AgtdkBiZO4bET7rWahDHN9MVgamluCyj0NTB8j5dkdw-90jVh7bA8SA98jey0KZ5bxBpC_YXH3pgKTmkDGcWA57rtuwtcLTChaKZfcBsKIMiHvIqjhJkuKcKDNtQIxETb1eiNVSBCQ0mXM3D0BWnS2CI

    We see for different types of anomalies that the high reconstruction errors appear in separate incidents, where they are elevated over the threshold for a period of time and then subside back to a lower level. Because of the nature of this dataset, where measurements were taken on known anomalies,  these incidents are quite frequent; in many cases, with more typical data, they would be relatively rare. In addition, we can observe some kind of periodicity and some profile of incidents (by incident is meant several consecutive points above threshold). This profile is different for different anomalies.

    Let’s mark the points in one of these incidents:

    ftqFErAfLxoLw-EXYpv2foMsaUItx7e35dpxtiGADxmgO0Z96z3Tf8clZYFd1D6TphJDz_nuRBetE5qVhO75rLiAEiRGxyn8O8gWVFwm4FG0TqyvDCc64P3AIvi_THIDd9nigogQwRspTo5V5rYsvvw

    What is causing these anomalies? Spotfire summarizes the components of these marked points;

    We see the sensor measurements which contribute the most to the overall reconstruction error for the 5 points in this incident. We also see that the largest contributions are from sensors with adjacent numbers- 06 and 07, likely indicating nearby sensors.

    If we mark all incidents for this type of anomaly, we will get a bit different graph: eU0Bf15YVvvD0FY4A0KquRbZz7X14BgPuSH1NA7bRTXCzXcwzhgz3CZIz6zeJuO-gahISAsj_zVCdD29td5w9UwxLBM0euMknI3LBdNGuhZK5LaHBC9wJBfiAn8I5kCTMS7kr2t5UNQOMENaAQX4Yw0

    This indicates that even for one type of an anomaly (which looks from the reconstruction error graph like the repeated pattern of incidents) the different sensors are influenced for different  incidents. This is a very important finding for understanding the results which will follow.

    This is useful in itself, but it may be important to understand the full range of incidents which are in the data. In order to do this, we automate the identification of incidents. 

    First, we select only Testing data, where we would like to do clustering of anomalies. Using the slider at left, we select a cutoff that identifies 70% of the observations as normal and 30% as anomalous.This results in a cutoff of 4.28 which seems reasonable concerning the ranges of the reconstruction errors for Training and Validation data. When the mean squared reconstruction error is greater than 4.28, we identify the point as anomalous (We used this threshold already before in the screenshots to give you the same reference line).

    Uupq8LskmUOJbilsIzu0elKQ_WzQS7OP26xb8mYtTs1nrgbDA86G1pWu5lEnnCnaafZPlWS5SYHZLluLyFEJ2VyUQDurLqDa3oa5ADJUA1ogMePGNuU8ysNcvr_sMlu84IADDil2FEbWxRQQoG-jpH4

    In order to reduce false positives, we further test to see whether at least 5 consecutive points are above the cutoff point. These are counted as Incidents; in the figure, we have identified 12,461 incidents.

    Clustering Analysis

    We next cluster these incidents to get a better idea of what features are driving each type of anomaly. We will use kmeans. Kmeans requires a target number of clusters, so we create an elbow plot:

    tXIGWmqNDuks6tIMiITnkMuYXek8CuGSgCp8th73lU_v7eq0PtiP406nGOBkiGmlWs3fFJ--G32wgEbtG3eQGAgSyGPn9juAXBxcp8fOLBKxCMYxJ5akg3VhGL783RObsFcAgaFCmBF4AjZ1Xj4UwvE

    The inflection point is 2 suggesting that this is a reasonable choice. 

    If we examine resulting clusters we can conclude that the clusters are distinguished simply to low and high error incidents. 

    3Uj0WNEi67tNMG0RjNs6UYtPvl4C0vxL5-ImWRcblYSlzLVozd2kl6IxPEj1MjPWLWAV2WZE8PzetZta_Jhj5lgDJiTZQzk7yImoeie8hHEmG_zODsOCUTuay5Q2BLb7AL_NHHQAbNyv1euuPe55z-w

    Yl7wNPMqhKZJJwr_nN9gCR7_fg5zGeYZe8vms-xYBtqD_91YwJB4ks1p22K3Jgw3_oqQevnC0duamSugVZVIvnjqB94yMwjdaIbvDXW1ONOQLnAWMMca-CfbM_Iv8sbWY9WmNX5XE1JS_giJbLIC2nE

    wE13f_jhPNtoqlbTUsH-EtF7p_ogl0PEp_5HV3h7L_X5LKethYKqUTfaacaNQLosFK-JMu65CS0vSxIDSNuCpEKvcAHjBGMHSVm9jHixrtG6PWn1ZBKf55gpfNJDsA359o_CIqJK1HlmNj8PmG5UaMU

    This is not distinguishing anomalies per label as we would expect (we need to mention that still we are doing unsupervised analysis, but if the labels are consistent with our clusters, we might get great interpretation for different clusters of anomalies). For curiosity let us increase the number of clusters to 9, which is number of different anomalies we have in the data.  

    Let’s examine the resulting clusters in a few ways:f7DaJBNdaUdfriQGouIeUFPJmFWA79qutp7IJIcacKK2dl8IZu-D8l1woOP_IJwbLeYfW-7L3V8hC9I8DTLuS96cF1yVnVM3m96ojE4su0JHcwa8k5_ecHsaxNsWDkm75zI3o2EeKCHYCzN3chOhq0cYf1uhxTbIvxDmJs0sN574y20jEPLOsd_vjC_UNULiYO6AnS4-8siv7WKys-whjARTjhFfp_3_Jk-aVKcJ0SJ_vy1MvPA598S8gYQHNjLfgKLnOYtlXdBetdslHqhAqS1igeMLXyJnbtGednzQJhCUsU

    We can see that again, clusters are more focused on the value of reconstruction error rather than different types of anomalies. We also have more clusters within the same levels of reconstruction error, this is the consequence of the finding we made earlier where for the same type of anomaly (the same label) we do not have always the same sensors responsible for that anomaly. 

    This is even more clear from the graph below where are the profiles of clusters per sensors. Each cluster is characterized by the means of the 32 features. We show them as a line chart:

    eOqxbkOoHnGWVBmQViCdQf8ARx9Qrd1YbGG1cN67-yaFBpHGxgIntoBW8AjgkymDM5Jb0WTsqOCC4krCx3atexSBa0QLdDa8rQk_ute1M-kDofqOsSJkWcI7sY7Kv-AkU8WuzoZuNXHAR5v55ssssqg

    This is somewhat hard to read; but if we focus on one cluster, we can clearly see a specific structure over the set of sensors on the x-axis (this was the reason for introducing leading zeros in the naming convention, as we mentioned):

    mN5lASeICpEXy7DBYTzpFcQE3SASs9sTpm03NbLA9yVxKACwRykXI-biPkkB3AiHipPhwEpHlmx99wYym6nh4xoSZYtEd_ZDEtxVkfN7A0PGGttff-Xu3eJr6RsRmgXjKFaoZSubLKLC6Zc514v4-0g

    Note that the x-axis here represents the 32 sensors in sequence by the numbering system provided. We don’t know their positions or types, but we can assume that those nearby in the numbering system are similar in some way. The clustering validates this, since it tends to group together measurements with similar patterns in the values.

    Unfortunately, but not surprisingly, the clusters we discovered do not correspond to the labels, which are grouped in consecutive times. One reason (as was already mentioned) is that anomalies can manifest on different sensors even for anomalies with the same label. The reason behind might be that the problem occurs in different places in the ball bearing or manifest in different time intervals (we do not know if the sensors are space or time related).

    Another reason why clustering in the application does not work is the fact that we expect an incident to be a set of consecutive anomalies of the same kind, here we always have some profile which is changing during the time of an incident.

    Conclusion

    The approach of training the model on normal operating conditions led to the model which is able to properly reveal that anomalous behavior is present in the testing data and that anomaly manifests itself in time separated incidents. This is true for all types of anomalous behavior. In that context the model is doing exactly what we would expect from a good anomaly detector.

    Concerning clustering of found anomalies (which could bring additional value for anomaly detection) the default approach is not working well and cannot be used for the benefit of analysis. The reason is in the special correlation structure of sensor measurements which are clearly depending on each other in periodic/cyclic way and at the same time there is a complication that anomaly can manifest on different sensors.

    Now that we know better the structure and behavior of the data, we would most probably suggest some alternative approaches to do better the job mainly in clustering of anomalies. We could investigate some time-frequency representation of the data; we could analyze some aggregated time segments instead of raw sensor data; or we can use matrix profiling on the reconstruction error time series in order to classify profiles of incidents.


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...