Skip to content

Commit

Permalink
Merge pull request #27 from KOSASIH/deepsource-transform-dab6e7e3
Browse files Browse the repository at this point in the history
style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, isort, PHP CS Fixer, Prettier, RuboCop, Rustfmt, Scalafmt, StandardJS, StandardRB and Yapf
  • Loading branch information
KOSASIH authored Jan 19, 2024
2 parents 120e8e5 + f82dfda commit c22afd1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions detect_anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
from sklearn.ensemble import IsolationForest

# Load historical user data
data = pd.read_csv('user_data.csv')
data = pd.read_csv("user_data.csv")

# Train anomaly detection model
model = IsolationForest(contamination=0.01)
model.fit(data)


# Real-time monitoring
def detect_anomaly(user_data):
# Predict anomaly score
anomaly_score = model.decision_function(user_data)

# Set anomaly threshold
threshold = -0.5

# Check if anomaly score exceeds threshold
if anomaly_score < threshold:
# Send alert message
Expand All @@ -24,8 +25,9 @@ def detect_anomaly(user_data):
else:
return None


# Sample user data
user_data = pd.DataFrame({'transaction_amount': [1000, 200, 3000, 500]})
user_data = pd.DataFrame({"transaction_amount": [1000, 200, 3000, 500]})

# Detect anomaly
alert = detect_anomaly(user_data)
Expand Down

1 comment on commit c22afd1

@vercel
Copy link

@vercel vercel bot commented on c22afd1 Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.