ai_anomaly_detection
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| ai_anomaly_detection [2025/05/24 14:34] – [3. Advanced Example: High Variance Dataset] eagleeyenebula | ai_anomaly_detection [2025/06/26 18:20] (current) – [AI Anomaly Detection] eagleeyenebula | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== AI Anomaly Detection ====== | ====== AI Anomaly Detection ====== | ||
| - | * **[[https:// | + | [[https:// |
| The **AI Anomaly Detection** system is a Python-based utility that identifies outliers in datasets using statistical principles like standard deviation. This function is essential for finding anomalous data points that deviate significantly from the dataset' | The **AI Anomaly Detection** system is a Python-based utility that identifies outliers in datasets using statistical principles like standard deviation. This function is essential for finding anomalous data points that deviate significantly from the dataset' | ||
| + | |||
| + | |||
| + | {{youtube> | ||
| + | |||
| ===== Overview ===== | ===== Overview ===== | ||
| Line 23: | Line 28: | ||
| **Threshold for Anomalies**: | **Threshold for Anomalies**: | ||
| Data points are considered anomalies if they fall outside the range: | Data points are considered anomalies if they fall outside the range: | ||
| + | < | ||
| [mean - (3 * standard deviation), mean + (3 * standard deviation)] | [mean - (3 * standard deviation), mean + (3 * standard deviation)] | ||
| + | </ | ||
| ==== 2. Logging Information ==== | ==== 2. Logging Information ==== | ||
| Line 34: | Line 39: | ||
| **Example Log Messages**: | **Example Log Messages**: | ||
| + | < | ||
| INFO: Detecting anomalies in the data... INFO: Anomalies detected: [120, -45] | INFO: Detecting anomalies in the data... INFO: Anomalies detected: [120, -45] | ||
| + | </ | ||
| ====== Function Details ====== | ====== Function Details ====== | ||
| Line 44: | Line 49: | ||
| **Signature**: | **Signature**: | ||
| - | python | + | < |
| + | python | ||
| def detect_anomalies(data: | def detect_anomalies(data: | ||
| """ | """ | ||
| Line 51: | Line 57: | ||
| :return: List of anomalies detected | :return: List of anomalies detected | ||
| """ | """ | ||
| + | </ | ||
| ===== Examples ===== | ===== Examples ===== | ||
| Line 127: | Line 133: | ||
| **Framework for Live Data Streams**: | **Framework for Live Data Streams**: | ||
| - | python | + | < |
| + | python | ||
| import random | import random | ||
| import time | import time | ||
| Line 147: | Line 154: | ||
| stream_anomaly_detection() | stream_anomaly_detection() | ||
| + | </ | ||
| ===== Advanced Usage ===== | ===== Advanced Usage ===== | ||
| Line 153: | Line 160: | ||
| By default, the function uses **3 standard deviations** as the threshold for anomaly detection. To customize this, modify the following part of the function: | By default, the function uses **3 standard deviations** as the threshold for anomaly detection. To customize this, modify the following part of the function: | ||
| - | python | + | < |
| + | python | ||
| anomalies = [x for x in data if abs(x - mean) > THRESHOLD * std_dev] | anomalies = [x for x in data if abs(x - mean) > THRESHOLD * std_dev] | ||
| - | + | </ | |
| **Example Custom Threshold**: | **Example Custom Threshold**: | ||
| - | python | + | < |
| + | python | ||
| THRESHOLD = 2 # Using 2 standard deviations instead of 3 | THRESHOLD = 2 # Using 2 standard deviations instead of 3 | ||
| data = [12, 15, 18, 10, 140] | data = [12, 15, 18, 10, 140] | ||
| anomalies = detect_anomalies(data) | anomalies = detect_anomalies(data) | ||
| print(f" | print(f" | ||
| - | + | </ | |
| ==== 2. Batch Detection for Multiple Data Sets ==== | ==== 2. Batch Detection for Multiple Data Sets ==== | ||
| Line 169: | Line 177: | ||
| **Example**: | **Example**: | ||
| - | python | + | < |
| + | python | ||
| datasets = [ | datasets = [ | ||
| [10, 12, 14, 18, 200], | [10, 12, 14, 18, 200], | ||
| Line 179: | Line 188: | ||
| anomalies = detect_anomalies(data) | anomalies = detect_anomalies(data) | ||
| print(f" | print(f" | ||
| - | + | </ | |
| **Output**: | **Output**: | ||
| - | + | < | |
| Dataset 1: [200] Dataset 2: [700] Dataset 3: [500] | Dataset 1: [200] Dataset 2: [700] Dataset 3: [500] | ||
| + | </ | ||
| ==== 3. Combining with Visualization ==== | ==== 3. Combining with Visualization ==== | ||
| Line 189: | Line 198: | ||
| **Example with Matplotlib**: | **Example with Matplotlib**: | ||
| - | python | + | < |
| + | python | ||
| import matplotlib.pyplot as plt | import matplotlib.pyplot as plt | ||
| Line 208: | Line 218: | ||
| plt.legend() | plt.legend() | ||
| plt.show() | plt.show() | ||
| + | </ | ||
| ===== Applications ===== | ===== Applications ===== | ||
| Line 218: | Line 229: | ||
| **3. Preprocessing for AI Pipelines**: | **3. Preprocessing for AI Pipelines**: | ||
| Flag and handle anomalous data points before model training to improve model robustness and accuracy. | Flag and handle anomalous data points before model training to improve model robustness and accuracy. | ||
| - | |||
| - | --- | ||
| ===== Best Practices ===== | ===== Best Practices ===== | ||
| Line 231: | Line 240: | ||
| 3. **Visualization**: | 3. **Visualization**: | ||
| Combine detection results with visualizations for better interpretability. | Combine detection results with visualizations for better interpretability. | ||
| - | |||
| - | --- | ||
| - | |||
| ===== Conclusion ===== | ===== Conclusion ===== | ||
| The **AI Anomaly Detection** framework provides a robust, flexible, and extensible mechanism for outlier detection in numerical datasets. With applications ranging from real-time monitoring to preprocessing for AI pipelines, the system is a valuable tool for automated anomaly analysis. By leveraging advanced usage patterns like visualization and threshold adjustments, | The **AI Anomaly Detection** framework provides a robust, flexible, and extensible mechanism for outlier detection in numerical datasets. With applications ranging from real-time monitoring to preprocessing for AI pipelines, the system is a valuable tool for automated anomaly analysis. By leveraging advanced usage patterns like visualization and threshold adjustments, | ||
ai_anomaly_detection.1748097265.txt.gz · Last modified: 2025/05/24 14:34 by eagleeyenebula
