Spaces:
Runtime error
Runtime error
Update models/energy_anomaly_detection.py
Browse files
models/energy_anomaly_detection.py
CHANGED
|
@@ -27,7 +27,7 @@ def detect_energy_anomalies(file_path):
|
|
| 27 |
Returns:
|
| 28 |
- anomaly (str): Energy anomaly detection result
|
| 29 |
"""
|
| 30 |
-
# Load energy generation data
|
| 31 |
if not os.path.exists(file_path):
|
| 32 |
raise FileNotFoundError(f"Error: Data file {file_path} not found.")
|
| 33 |
try:
|
|
@@ -57,7 +57,7 @@ def detect_energy_anomalies(file_path):
|
|
| 57 |
prediction = model.predict(X)
|
| 58 |
last_predicted_value = prediction[-1][0] # Get last prediction
|
| 59 |
|
| 60 |
-
# Define threshold for anomaly
|
| 61 |
threshold = 0.1
|
| 62 |
anomaly = "Anomaly Detected" if abs(last_predicted_value - energy_data[-1][0]) > threshold else "No Anomaly"
|
| 63 |
|
|
|
|
| 27 |
Returns:
|
| 28 |
- anomaly (str): Energy anomaly detection result
|
| 29 |
"""
|
| 30 |
+
# Load energy generation data
|
| 31 |
if not os.path.exists(file_path):
|
| 32 |
raise FileNotFoundError(f"Error: Data file {file_path} not found.")
|
| 33 |
try:
|
|
|
|
| 57 |
prediction = model.predict(X)
|
| 58 |
last_predicted_value = prediction[-1][0] # Get last prediction
|
| 59 |
|
| 60 |
+
# Define threshold for anomaly
|
| 61 |
threshold = 0.1
|
| 62 |
anomaly = "Anomaly Detected" if abs(last_predicted_value - energy_data[-1][0]) > threshold else "No Anomaly"
|
| 63 |
|