Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -107,13 +107,20 @@ def get_roc_curve():
|
|
| 107 |
def get_anomaly_samples():
|
| 108 |
"""Returns formatted top, middle, and bottom 10 records based on anomaly score."""
|
| 109 |
sorted_df = df.sort_values("Anomaly_Score", ascending=False)
|
|
|
|
| 110 |
# Top 10 anomalies
|
| 111 |
top_10 = sorted_df[sorted_df["Anomaly_Label"] == "Anomaly"].head(10)
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
# Bottom 10 normal records
|
| 116 |
bottom_10 = sorted_df[sorted_df["Anomaly_Label"] == "Normal"].tail(10)
|
|
|
|
| 117 |
return top_10, middle_10, bottom_10
|
| 118 |
|
| 119 |
# Create Gradio interface
|
|
|
|
| 107 |
def get_anomaly_samples():
|
| 108 |
"""Returns formatted top, middle, and bottom 10 records based on anomaly score."""
|
| 109 |
sorted_df = df.sort_values("Anomaly_Score", ascending=False)
|
| 110 |
+
|
| 111 |
# Top 10 anomalies
|
| 112 |
top_10 = sorted_df[sorted_df["Anomaly_Label"] == "Anomaly"].head(10)
|
| 113 |
+
|
| 114 |
+
# Middle 10 (mix of anomalies and normal)
|
| 115 |
+
mid_start = len(sorted_df) // 2 - 50 # Get a broader middle slice
|
| 116 |
+
middle_section = sorted_df.iloc[mid_start: mid_start + 100] # Consider a larger middle slice
|
| 117 |
+
middle_anomalies = middle_section[middle_section["Anomaly_Label"] == "Anomaly"].sample(n=5, random_state=42)
|
| 118 |
+
middle_normals = middle_section[middle_section["Anomaly_Label"] == "Normal"].sample(n=5, random_state=42)
|
| 119 |
+
middle_10 = pd.concat([middle_anomalies, middle_normals]).sort_values("Anomaly_Score", ascending=False)
|
| 120 |
+
|
| 121 |
# Bottom 10 normal records
|
| 122 |
bottom_10 = sorted_df[sorted_df["Anomaly_Label"] == "Normal"].tail(10)
|
| 123 |
+
|
| 124 |
return top_10, middle_10, bottom_10
|
| 125 |
|
| 126 |
# Create Gradio interface
|