Untitled

Detect anomalies in your data.

Anomaly detection, such as fraud detection is crucial for preventing financial losses. ML models can be trained on e.g. historical credit card transaction data, and then used to identify and prevent fraudulent transactions. Peliqan's platform also supports the regular updating and fine-tuning of models to ensure their effectiveness in detecting fraud.

Here is an example on how to build an ML model in Peliqan.io with a few lines of Python code.

Import required modules

We will be using IsolationForest Algorithm to perform the anomaly detection. More on IsolationForest here.

import numpy as np
import pandas as pd
from sklearn.metrics import classification_report, accuracy_score
from sklearn.ensemble import IsolationForest
from joblib import dump

Load a dataset

Load data from a table into a dataframe (df).

# Load Data
dbconn = pq.dbconnect('dw_123')
df = dbconn.fetch('db_name', 'schema_name', 'transactions', df = True)

Using Streamlit to build an app

We use the Streamlit module (st), built into Peliqan.io, to build a UI and show data.

# Show a title (st = Streamlit module)
st.title("Anomaly/fraud detection")

# Show some text
st.text("Sample data")

# Show the dataframe
st.dataframe(df.head(), use_container_width=True)

Untitled

Understanding data

the dataset we are using contained 28 compressed features which are the result of a PCA transformation. Feature 'Time' contains the seconds elapsed between each transaction and the first transaction in the dataset. The feature 'Amount' is the transaction Amount. Feature 'Class' is the response variable and it takes the value 1 in case of fraud and 0 otherwise.

Let’s have a look if the data is balanced by plotting the Number of frauds in transactions vs non-frauds.