Sign inGet started
← Back to all guides

Anti-money laundering in Python

By Filip Žitný

Updated on August 5, 2024

Money laundering involves disguising the origins of illegally obtained money. Anti-Money Laundering (AML) refers to the procedures and processes put in place to detect and prevent such activities. In this guide, we'll walk through building an AML system in Deepnote, utilizing Python for data analysis and machine learning.

Data import and exploration

Upload your dataset to Deepnote via the "Files" tab or link to a Google Drive/Cloud Storage.

Load the data using Pandas:

import pandas as pd
data = pd.read_csv('path_to_dataset.csv')

Data exploration:

Display basic statistics and data types:

data.info()
data.describe()

Visualize the distribution of data:

import seaborn as sns
import matplotlib.pyplot as plt

sns.countplot(x='label', data=data)
plt.show()

Data preprocessing

Handling missing values:

Check and handle missing values:

data.isnull().sum()
data.fillna(method='ffill', inplace=True)

Feature engineering:

Create new features and normalize/standardize data:

from sklearn.preprocessing import StandardScaler

scaler = StandardScaler()
data_scaled = scaler.fit_transform(data[['feature1', 'feature2', ...]])

Splitting the data:

Split the dataset into training and test sets:

from sklearn.model_selection import train_test_split

X = data.drop('label', axis=1)
y = data['label']

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)

Model building and evaluation

Choosing a model:

Select a model, e.g., Logistic Regression, Random Forest, etc.

Example with Random Forest:

from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report, confusion_matrix

model = RandomForestClassifier(random_state=42)
model.fit(X_train, y_train)

y_pred = model.predict(X_test)

Evaluating the model:

Assess the model’s performance:

print(confusion_matrix(y_test, y_pred))
print(classification_report(y_test, y_pred))

Additional tips

  1. Visualization: Utilize Deepnote's rich visualization capabilities to create interactive plots and dashboards or Deepnote apps.
  2. Collaboration: Leverage Deepnote's collaboration features for teamwork and sharing results.
  3. Version control: Use Deepnote’s integration with Git for version control.

Conclusion

This guide covered the basic steps for setting up an AML detection system in Deepnote. The process involved data import, exploration, preprocessing, model building, evaluation, and deployment considerations. Deepnote’s features streamline these tasks, making it an excellent platform for data projects.

Filip Žitný

Data Scientist

Follow Filip on Twitter, LinkedIn and GitHub

That’s it, time to try Deepnote

Get started – it’s free
Book a demo

Footer

Solutions

  • Notebook
  • Data apps
  • Machine learning
  • Data teams

Product

Company

Comparisons

Resources

  • Privacy
  • Terms

© Deepnote