Anomaly Detection Models
Apply unsupervised anomaly detection methods — Isolation Forest, Local Outlier Factor, and One-Class SVM — to detect fraudulent transactions.
3
Anomaly Detection Models
python • Step 3
Apply unsupervised anomaly detection methods — Isolation Forest, Local Outlier Factor, and One-Class SVM — to detect fraudulent transactions.
isolation_forestlocal_outlier_factorone_class_svmanomaly_detection
Learning Objectives
- →Train Isolation Forest for anomaly detection
- →Use Local Outlier Factor for density-based detection
- →Build a One-Class SVM for boundary-based detection
- →Compare all three methods on the same test set
Dataset
View on Kaggle Matches Kaggle
~284k transactions, PCA-anonymized features (V1–V28), severe class imbalance.
*bleep* Load the dataset in the browser terminal:
from pyodide.http import open_url
import pandas as pd
df = pd.read_csv(open_url("/datasets/creditcard.csv"))
print(df.shape)
print(df.columns.tolist()) Running locally? The file inside the Kaggle download is already named creditcard.csv — drop it into the notebook's working directory and the code above runs unchanged (swap open_url(...) for "creditcard.csv").
Dataset Columns
V1V2V3V14V17AmountClass- Write your solution in the Try It Yourself editor below — matplotlib/seaborn figures and pandas tables render inline.
- Stuck? Expand a section and click ↑ Send to editor to stack its snippet into the editor, notebook-style.
- Hit ▶ Run (or ⌘↵) — once your output matches the expected result, the step is marked solved.
- Use ↺ Reset to restore the starter code at any time.
Try It Yourself
Python
Loading editor...
*bleep* Output will appear here after running your code. Figures from matplotlib/seaborn render inline.
Expected output:
Detected anomalies: Actual fraud:
0/3
Export to GitHub
Cross-verse learning
Bleepx skills build on each other. Continue your learning path across Query, Lab, and Cloud.