In this 3-part series we’ll explore how three machine learning algorithms can help a hypothetical financial analyst explore a real data set of credit card transactions to quickly and easily infer relationships, anomalies and extract useful data.
The data set we’ll use in this hypothetical scenario is a real data set released from the UK government, specifically the London Borough of Barnet. The full dataset can be downloaded from here:
In a nutshell, the dataset contains raw transactions (one per row) which contain the following information:
- Transaction ID and Date
- Type of account making the payment
- Type of service paid for
- Total amount paid
Algorithms & Workflow
For the purposes of this article, we will process the data set using an excellent python toolset from the University of Ljubljana, called Orange. For more details please have a look at their site: https://orange.biolab.si/. I won’t delve into Orange’s details in this post, it’s enough to display the workflow used to obtain our results:
Note how we first load our data from the CSV file, and do one of two things:
- Discretize the data. Correspondence analysis only accepts categorical data, so we split the “total” column – which is numeric – into categories, for example:
- Continuize the data. Conversely, PCA and clustering accept only numerical values, so we use this function to perform “one-hot encoding” on categorical data, and we also normalize our data. We then feed this data into PCA and view the results there, before feeding the results into our clustering algorithm to make it easier to spot anomalies.
We first explore “correspondence analysis“, which is an unsupervised method akin to a “PCA for categorical data”. It is extremely useful in exploring a data set and quickly discovering relationships in your data set. For example, in our financial data set we get the following result:
- The red dots are the “type of service paid for”
- The blue dots are the “type of account”
- The green dots are the amount of money, or “total”
Overall results, most observations are clustered in the bottom left of the graph, however a few observations stand out.
On the top right corner of the graph, we see three points which are set apart:
This suggests that “Fees and Charges” is closely related to the “Customer Support Group”, as is “Legal and Court Fees”. This is in deed the case, since:
- all “fees and charges” were made by “customer support group”
- all “legal and court fees” were made either by “Customer Support Group” or “Children’s Family Services”. It is interesting to note that “Legal and Court Fees” is pulled closer to the other points since it is connected to “Children’s Family Services” which in turn is responsible for many different transactions within the data set.
Towards the bottom of the graph we see the following cluster:
So we expect to find some sort of “special” relationship between these observations. In fact, upon verification we find that:
- All “operating leases – transport” transactions were made by “Streetscene”:
- 95% of all “Vehicle Running costs” were made by “Streetscene”
- Over 53% of all “Streetscene” transactions were of type “operating leases – transport” and “vehicle running costs” – explaining why the blue “Streetscene” observation is “pulled” towards these two red dots.
Towards the middle of the graph we see two particular observations grouped together:
Upon investigation we find that the above clustering is justified since:
- All “grant payments” were above 217.99:
As can be seen, Correspondence Analysis allows us to quickly and easily make educated conclusions about our data. In this particular case, it allows our hypothetical financial analyst to spot relationships between accounts, the type of services they use, and the amount of money they spend. In turn, this allows the financial auditor to determine of any of these relationships are “fishy” any warrant further investigations.
Principal Component Analysis
Watch this space for a link to our next article exploring this data set using Hierarchical Clustering!