Card Fraud Watch
Part of the Unsupervised Learning section of Coddy's Machine Learning journey. Lesson 49 of 51.
A credit union's card team can check only a few payments a day by hand. Last month, the frauds hid at the edges:
But nobody knows a fraud until a customer complains, weeks later. So two detectors must find the odd payments with no labels at all.
This week's complaints are in. Which detector would have caught more?
Challenge
HardThis week's 400 payments are in payments.csv; the program reads how many the team can check, budget.
- Scale the four features.
- Flag
budgetpayments with an isolation forest (random_state=0) and with a local outlier factor (20 neighbors). - Only now open
fraud: print what each list caught, and how many honest payments it had the team check. - Send the team the list that caught more:
the isolation forest's listorthe local outlier factor's list, elseeither list, they tie.
For last month and a budget of 10:
Budget: 10 of 300 payments
Isolation forest: caught 6 of 12 frauds, 4 honest payments checked
Local outlier factor: caught 10 of 12 frauds, 0 honest payments checked
Send the team: the local outlier factor's listTry it yourself
import pandas as pd
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import IsolationForest
from sklearn.neighbors import LocalOutlierFactor
# One row per card payment; fraud is 1 for the ones customers reported weeks later
payments = pd.read_csv("payments.csv")
features = ["amount_eur", "hour", "km_from_home", "minutes_since_last"]
# How many payments the team can check by hand
budget = int(input())
# Write your code below
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Unsupervised Learning
1Finding Groups
Learning Without LabelsMeasuring SimilarityK-Means by HandK-Means in scikit-learnRecap: Gym Members7PCA in Practice
Seeing 64 DimensionsComponents as PatternsCompress and RebuildPCA Before a ModelRecap: Face Scanner10Project: Digit Explorer
Look at the DigitsShrink with PCACluster the DigitsName the ClustersFind the Odd OnesPractice on your own: Online Python compiler