-
Notifications
You must be signed in to change notification settings - Fork 1
/
AI Model Script
31 lines (24 loc) · 898 Bytes
/
AI Model Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# ai_module.py
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
# Load dataset
df = pd.read_csv('dataset.csv')
# Preprocess data
X = df.drop(['target'], axis=1)
y = df['target']
# Split data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Train random forest classifier
model = RandomForestClassifier(n_estimators=100)
model.fit(X_train, y_train)
def validate_and_record(transaction):
# Preprocess transaction data
data = pd.DataFrame([transaction['data']], columns=['feature1', 'feature2'])
# Make prediction
prediction = model.predict(data)
if prediction[0] == 1:
# Record transaction
return "Transaction recorded"
else:
return "Transaction flagged as anomaly"