From 2d1c0c58afe27adaba0a3045a41220540fbba46b Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Mon, 2 Dec 2024 12:27:35 +0700 Subject: [PATCH] Create fraud_detection.py --- .../components/fraud_detection/fraud_detection.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 blockchain_development_integration/pi_network/components/fraud_detection/fraud_detection.py diff --git a/blockchain_development_integration/pi_network/components/fraud_detection/fraud_detection.py b/blockchain_development_integration/pi_network/components/fraud_detection/fraud_detection.py new file mode 100644 index 000000000..a2748e218 --- /dev/null +++ b/blockchain_development_integration/pi_network/components/fraud_detection/fraud_detection.py @@ -0,0 +1,9 @@ +# fraud_detection.py +import pandas as pd +from sklearn.ensemble import IsolationForest + +def detect_fraud(transactions): + model = IsolationForest(contamination=0.01) + model.fit(transactions[['amount', 'time', 'location']]) + transactions['is_fraud'] = model.predict(transactions[['amount', 'time', 'location']]) + return transactions[transactions['is_fraud'] == -1]