-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathOutlier_detection_PO
More file actions
30 lines (19 loc) · 1.16 KB
/
Copy pathOutlier_detection_PO
File metadata and controls
30 lines (19 loc) · 1.16 KB
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
import pandas as pd
from sklearn.neighbors import LocalOutlierFactor
# Load purchase order data into a pandas DataFrame
data = pd.read_csv('purchase_order_data.csv')
# Preprocess the data if needed (e.g., handle missing values, adjust data types)
# Select features for anomaly detection
features = ['amount', 'vendor', 'date'] # Adjust the column names according to your data
# Create a new DataFrame with only the selected features
data_selected = data[features]
# Create a Local Outlier Factor model
lof_model = LocalOutlierFactor(contamination=0.05) # Adjust the contamination parameter based on your requirements
# Fit the model to the selected data
lof_model.fit_predict(data_selected)
# Obtain the anomaly scores
anomaly_scores = lof_model.negative_outlier_factor_
# Add the anomaly scores as a new column in the original DataFrame
data['anomaly_score'] = anomaly_scores
# Analyze the anomalies (e.g., identify and investigate the data points with low anomaly scores)
# Once the model is trained and anomalies are identified, you can integrate the anomaly detection system into your ERP accounting system to flag and handle potential anomalies in purchase orders.