Isolation Forest is an ensemble-based unsupervised anomaly detection algorithm that excels in financial crime compliance contexts like money laundering detection, where supervised learning is impractical due to lack of labeled data; unlike traditional distance/density-based methods, it isolates anomalies by building extremely randomized decision trees and calculating anomaly scores based on the average number of edges traversed to isolate each data point, making it robust to parameter settings and effective for detecting subtle anomalies hidden in normal transaction patterns.
Isolation Forest for Unsupervised Anomaly Detection | PyData London 2018
Added:hello everyone thank you for well welcome my name is Elena Neves scientist at create Swiss I work in a financial crime compliance team and this talk is about using isolation forest for anomaly detection with application to you AM L AM L stands for antimony wondering can I have a quick show of hands of who in the audience works with in financial crime compliance or otherwise in the in this area okay that's good so in this talk I will briefly introduce what is anomaly detection and what kind of methods are used we'll look at the application of anomaly detection to banking so Walker will cover the three most often used areas then we'll talk about specifically for AML if supervised purses and supervised methods are applicable and then we'll look at the isolation forests so we'll step away from the topic of AML and look at the actual algorithm I'll describe police resolution first I will describe how it's implemented the Sackett learn and we'll compare performance on the public data set key to carp 99 most of you probably have used that before and will compare the performance to a local I'd laugh actor then we'll move to isolation force performance on a synthetic data set that has been put together specifically with a few antimony ml red flags embedded in it and then we'll conclude here's a quick disclaimer for you to read okay so what is an anomaly anomaly is a data point of interest in in this case it's something that stands out it's it's an unusual an unusual data point when a data generating process behaves and usually it results in an anomaly anomaly as an anomaly detection as a topic is a well researched subject there is a lot of publications out there in basta testicle and data science the real challenge for us who practice data science is to essentially define construct the right data model for the subject at hand to separate outliers from noise and from from the actual normal data what kind of methods are used well the methods are broadly speaking fall into three categories the density based methods the distance based methods or parametric you probably used most of these before the density based and the distance based they fall into the spacial proximity type of algorithms and the examples here are DBC and vocal a factor K nearest neighbor k-means or something like a distance to a regression hip of languages in regression the parametric passes they would usually assume some sort of form to your data so assuming that when you're working with so what you have observed so far is normal and models like garden mixture model or single classes Williams I use there of course there are other methods which are not kind of machine learning methods like z-score which will assume normality and many more in terms of application to banking so many of you probably have heard of anomaly detection is used in credit card for detection that's a very very well-known area where it's used other other areas such as market abuse and private banking so much taboos by clients Oh market abused by both clients and traders in investment banking I'm highlighting the ml as the money laundering as a subject of detection for all three retail private and Bank and what is important to understand is that the the way manual wandering is done using these three types of banks is actually different and therefore different methods of detection and different types of red flags exist in in in these banking types so here if you learn one thing from this talk this should be the one so another point to be aware of is that also mate is money learning detection is very it's actually an inherently different problem from optimizing detection tradecraft cray-pas forward or automatic detection of market abuse and why is it so well in credit card fraud we often well we have a luxury of actually having data when we have true positive cases or labels and why because often customers worksheet tell us if certain transaction wasn't actually done by them it market abuse it's slightly hard but still you have you have a signal in the data so for example the P&L positive P&L or huge changes in piano or huge changes in the price move can be used as a self-revealing class in case of automatic money laundering detection it's much harder because most of the times especially from the from the banking perspective from the banks we don't really have any data that can be used as a true positive set of cases or labels what banks do they if they suspect money laundering they will file a star to the National Crime Agency and often it may actually never hear back from them or if they do here it takes years so it's not really practical so for detecting money laundering for for banking we're pretty much left with just unsupervised methods so why is it difficult well the royalty papers they're actually quite well described why is it difficult but of course there is severe class imbalance this is an outlier detection problem what we also deal with Steve Mira class overlap what that means is that money-laundering is is when it comes from a single stream of financial transactions actually be mixed with with normal normal activity so what criminals do they will use front companies sometimes banks and it makes it much harder to detect another thing that we have to deal with is called concept drift so how money is laundered even by the same criminal organization changes over time and of course there is our certainty around the day tomorrow so if you choose to use your suspicious activity report as an indication for what what whether certain transaction of such transactions were actually money laundering then you have a lot of uncertainty as Angelus so you have a picture of a candle in the dark most of the time there is actually no candle either so let's step aside from the problem of money laundering and let's look at the isolation forest isolation forest is an ensemble regressor and it is different from other types of distance or density based method is that it doesn't profile normal cases and it doesn't calculate distances foreign-based distances for the food item instead what it does it essentially tries to separate away data points or explain away anomalies from normal normal data points underneath it is building extremely randomized decision tree and it uses that as a base estimator isolation forest why is so good for anomaly detection well because of campus work post as a supervisor or an unsupervised classifier it calculates an anomalous score which is 2 to the power of minus a ratio of expected number of edges in the trees for in the trees in the forest for particular data point normalized by a constant in the supervised setting you are going to use a threshold which is a contamination ratio to to create a binary classification problem in the if you can actually use use it without the threshold and turn it into a soft classifier so as the number of edges the average number of edges in the trees goes to zero the higher is the anomaly score so the reason is that actually anomalous data points they are easier to explain away from normal data points the the model isolation force was introduced in 2008 and became available in scikit-learn in 2016 so in the previous version to the current one it extends the booster activity regressor and it's possible to use it as both with and without replacement by default is without and it's as I said already it's based estimator is the extremal random strain regret sir so both the attribute to split and the displease value will be chosen randomly this allows you to overcome building very greedy trees in practice in the implementation circuit lien it will return a value of 0.5 minus the anomalous score so smaller scores or negative scores will be indicative to two anomalies so let's take a look at the performance of this this classifier on a public dataset kgt up 99 we're going to quickly switch to hopefully you can see so I'm going to use schizocarp 99 and this will be downloaded from the secular datasets module and there are a few options for downloading this modulus let me just briefly scroll through the helper methods and about the datasets so we'll use SI + SF dataset sa has only four four attributes and herself has 41 the kg Cup 1994 so don't know contains loads of offline intrusion detection system it's been around for quite a while the SF anomaly rate in this case is 0.5% so I point 5 percent of data points will contain actual attempts of hacking attempts and I say I'm only loading 10% of the data and here the anomaly rate is higher it's three point four percent so we're going to perform some pre-processing so what we're going to do is we're going to save all of these all of the attacks and turn them into one class and everything which is not an attack will be probably a negative class only states a positive class and for the sake of local at live factor I've also normalized the data and fields that are not numeric fields have been turned in numeric using the label and folder in terms of training isolation forests and the local life factor we're going to split the test set and the training set at 33% and if you look at the setting the features I'm pretty much using the default recommended features number of estimators I'll talk about what this parameter does number of estimates is a hundred we will use in this case because we have a label in in the data set will use contamination rate of 15% so much higher than the natural rate of anomalies in this case and max sample set 25 okay so it takes about 20 seconds to Train only as this is the SI data set so this is a smaller one and when a normalized States a local I fact the training is faster but let's you take a look at the results so I'm going to show you the output of the of the year classification report as well as the confusion matrix in terms of anomaly detection what we are always interested in is we are really interested in the recall which is which is this upper left-hand corner and you can see that only trainings that this relation Forest performs actually quite well and it gets about 12 percent false positive right I also calculate I you see also in this case it may not always be relevant for you and it's a pretty high I will see the local knife factor on these dates that doesn't do very well it only achieves a recall rate of 8 and a half percent and much higher false positive rate so one more question so why is no qualifier fact that doesn't do very well perhaps it's the number of attributes in this data set is quite a lot is 41 and it may be it's just getting the dimensionality Kherson here so let's take a look at the SF data set some data set has only four attributes and it's a slightly bigger one in this case again we are going to split test and reset three percent and we're going to test a solution force was exactly same parameters take slightly longer to train and the results are very similar to the previous set so it's eves very high recall which is exactly what we're interested in and not a very high false positive right I can look at the fact that didn't do very well perhaps it's the dataset itself I've also tested it on non normalize dataset the log of that factor and I didn't see much difference so in this case my well might say that you might play with the number K which is which is irrelevant k nearest neighbor setting for local of that factor in order to try to get a perform better but this talk is not about LOF so let's move on it never performance on the test set what is surprising is that isolation forest does work pretty well and tested as well so we have a 99% recall very similar to the training set and a hundred percent for the SF okay so now let's talk about the estimators what I find is that isolation forest is actually very robust to parameter setting and estimators will control how many trees get built in the isolation forest and we're going to see how sensitive it is to this parameter for the sake of this particular test I'm turning my my scorer into a recall score and I turned the minus 1 so the anomaly into a positive label so we'll test the performance on any where estimated so number of trees in forests between 20 to 230 and what we see is that both recall and I see a quite insensitive to this and this actually matches to what the original or have published in their paper about the algorithm being very robust after about 20 it achieves a very good recall mark samples will control how much of the data gets sampled to build the trees in the other nation forest and the idea here is that it's the sub sampling that helps to explore these hidden layers or subsets of the data so we'll look at the performance of isolation forest always max sample between 10% to going up to 100 so what we see is that it does serve starts to suffer if you increase sampling size and it is actually also something that resonates back to the original paper now the contamination rate so if you choose to use a solution forest as a supervised to classify it was used the contamination rate as a threshold to define on a set of all the anomaly scores for all the data points were to cut off in order to make it anomaly versus not anomaly so this is the parameter that the algorithm is actually quite sensitive to and you can see that we are going to test it for anywhere between 1% so this is still higher than the natural contamination rate to 25 and after about 10 percent of contamination it achieves a recall of 100 so we have looked at in terms of parameterization so I said it's a it's it's pretty robust to parameters and in complexity it compares quite well complexity to K K nearest neighbor and other distance based or density based algorithm so it's pretty you could say that it's linear in its complexity so let's go back to the topic of money laundering I have said I started this talk by saying what is an outlier what is an anomaly but the truth is that most of the automated money laundering detection is actually not a simple anomaly detection problem and it's not really an outlier detection problem and why is that well it's because many hundreds of transactions that are associated with money laundering they differ very little from normal transactions so as Liars are they are hidden in the unusual behavior of low dimensional subspaces and if you do learn a second thing from this talk this should be the one so I have put together a data set which is well which is a synthetic data set it's made up of fake transactions but it has some money laundering red flags embedded into it the first Jupiter notebook is available for you from my github page and I can share with you the second Jupiter notebook if you want to you can contact me through my blog the link is at the bottom so the idea here is that we we have to take our clients transactions and trades and we have to essentially optimize it for a set of red flags the red flags they are they there are publications about them your local financial financial crime subject-matter experts will know more about them but if you if you're interested to read than consult financial action task force website or DFS or join my new learning group of walls back row so I'm going to switch to my synthetic data set and I'll talk about it a little bit more the synthetic data set is very small in this case it has only 200 data points and I have created four strategies in there and first strategy the anomalies essentially at five percent rate so what does it look like it looks about like this what we've put in the data point in in the data set we have a client ID we have a made-up security name it can be anything a stock or bond or anything each client in this case has ten transactions one transaction per day we have a notional amount which is purely random source from uniform distribution we have a flag for whether to buy or sell we have a flag for whether this transaction is followed by an asset transfer so if it's a pile and it may be followed by an asset transfer out if it's a sell it may be followed by an asset transfer in sorry preceded by a asset transfer in and then there is some sort of currency pay in this case were not looking at the currency pair of the foreign exchange type of strategy but this is a fake currency pair in most cases and we also have a flag for settlement to offshore legal entity so most of you who work with transactional data will already immediately recognize that this is one step or many a few steps after the raw data set so in this case what I'm what I'm kind of getting to is to the idea of summarizing no data for a specific type of off anomaly over over at flag so our niska's isolation force max sample I'm setting to 50% because this is a very small data set and what we're going to do is we're just going to feed the raw synthetic data into isolation forests in this case and after doing that we will compare what is the mean anomaly score for those records that were created to mimic a particular money learning strategy versus those that haven't and what we see here is not isolation forest does managed to assign a more negative score on average two data points that were designed to mimic money laundering visually this will look like this so these are the points this is the first set of trades sorry this is the first set of race so this is index 0 and mirror out mirror Ian and then offshore also isolation forest manages to get quite a few false positive in this case so let's go one step further we are now going to actually do what we said we're going to fold our data set and to optimize it for looking for a particular round flag in this case was trading I'm not going to talk about what it is if you want to know more about the strategies talk to me after this call after this presentation so we will summarize activity as a ratio of bias versus cells in the same security and this is what gets fed into the pass elation forest again was very much the same the same parameter settings in this case were not using contamination rate this is not a supervised classification problem and in my de said we only had one one example which was a true positive for sure and isolation forest dust find this data point let's look at another strategy as a transfer strategy so if you go on a DFS website and search for Mira we will find documents that are specific to this this is a very well known case and what we are looking for we are looking for activity where which is preceded or followed by as a transpose this is what gets summarized I folded into the summary and gets fed into the isolation for us there were two data points not two data points two trading strategies at all 20/20 records in a data set and they are index 1 and the index so again isolation forest does manage to find it so far I hope you understood that the idea for using anomaly detection algorithm is to be able to explore these sub samples of a data set and another extension to application to anomaly detection would be to use what's called a risk-based approach which is often what the financial crime compliance teams tend to do but the idea here is that to actually focus on a particular group of high-risk clients focus on particular client network for example all legal entities that share the same beneficial owner or all legal entities that actually share the same big code and anything else and for the other so and then the this this extra parameter this extra feature will be then introduced into the isolation forests so in conclusion the anomalous activity in AML is Bank type specific different strategies are used for different types of Bank isolation Forest is a promising robust classifier that can be used for in within the AML space the successful automatic detection starts with asking the right question and then optimizing the data set for the data model that that you want to construct thank you very much [Applause] [Music] any questions thank you very much for the presentation I'd be interested so an isolation forest doesn't scale terribly well typically doesn't do out of core so I'd be interested if in the applications you're interested in that's a challenge both in terms of memory or in terms of CPU usage so as I said the quite often financial crab plants team they will focus on a particular risk or group of clients in order to do a risk based approach that in itself minimizes the type of Records you have to look through and another thing is that unlike in prey crowd for detection in my eulogy detection we have a luxury of doing it offline it doesn't have to be immediate or as fast as possible it can take you can take a few days or weeks in order to do it offline so typically the problem is the memory usage so can I ask whether you're using like hardware where the large large amount of memory or not the reason I'm asking is that people often tell us it's too expensive to buy hardware with one terabyte of RAM and then I get a fight worthy where the person's like it's not that expensive and I just can't do isolation forest out of court so do you run specific hardware or just small computers yeah and firstly I cannot us answer the the specifications of the machine that we use at the bank I didn't put it together I know it's a supercomputer yeah thanks to that you so initially you showed really good recall it was sort of in the demonstration really good recall but quite poor LOF I'm not really familiar with that we'll just have a quick look now it's like presumably just something for anomaly detection can you just give some more intuition like why do you think that is or because it sounds like you're spreading quite a wide net but then you're missing possible anomalies so I don't know that's what it seemed like maybe yeah I'm not sure exactly why LOF didn't do very well on this task I think it's just this particular dataset it doesn't perform very well I have seen very similar performance of LOF on this data set reported in other papers so I just gave up and try to optimize it I think it's the it's the fall of decay the number of neighbors is very it's very sensitive to that parameter and I think that's probably where if you wanted to optimize if you would you would play with that parameter Thanks would you be able to say anything more about the metric which isolation forest is using you mentioned about the number of edges about the metrics about the about the expectation number of edges number of edges it's sorry if the question it's not very clear the metric question okay so what happens is that isolation forest has two stages the training stage and the testing stage in the training stage it will build the trees in the in the in the forest and in the testing stage it will pass each data point through each tree and it will code it will record at what stage hits the external load and then the number of edges it has to travel through for each tree gets averaged over and the shorter is that traveling through for a data point the more likely it is to be the anomaly I hope their answers thank you very much for the talk quick question so because the datasets have labels that you that you can use to calculate recall and metrics how do you apply that in practice when you don't have the labels and how do you tune your model since you can't you know calculate recalling metrics yeah you're right in practice we don't have labels and so what we have in the financial Chrome team we have analysts who the cases that are seemed of interest they get followed forwarded to and they essentially have it's it's it's a humans looking at transactions and trades and trying to understand whether they are of interest or not that's how it's used in practice oh I think you mentioned that false-positive rate is about 12% right but in practice what can you do if you have such a high positive false positive rate I mean you probably get referred such a large amount of cases and what can you do how can you look through all of that for young yeah it's actually a false positive rate of 12% for AML is actually very low most of the time most of the time the false positive rate is close to 100 so it's very promising thank you [Applause]
Up Next

Isolation Forest Anomaly Detection in Python & Scikit-Learn
@alisterluiz
9.2K views•2024-06-22

Building Real-Time ML Pipelines with Feature Stores and MLOps Frameworks
@ODSCAI
5.1K views•2022-02-20

Neural Networks for Recommender Systems (PyData 2017)
@PyDataTV
21.1K views•2017-04-25

Neural Networks Explained: Math, Layers, and Learning Fundamentals
@3blue1brown
21.9M views•2017-10-05
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Artificial Intelligence











![[핵심 머신러닝] Anomaly Detection (개요, 확률분포기반)](https://i.ytimg.com/vi/TqSwuCX7Lds/maxresdefault.jpg)






















![[Webinar] Translating ML to Business Value in Financial Services](https://i.ytimg.com/vi/HcAp5ax1q4A/maxresdefault.jpg)




