predict_anomalies
Detect anomalies in a loaded signal using a trained model. Returns aggregate anomaly statistics and worst segments for machinery health assessment.
Instructions
Predict anomalies in a stored signal using a trained model.
Requires the signal loaded via load_signal() first and a model
trained via train_anomaly_model (its result echoes the model_name
to pass here). Pipeline: segment -> features -> scaler -> PCA ->
predict -> aggregate.
Output is BOUNDED: counts, anomaly ratio, score percentiles, and
up to 10 worst segments — never per-segment arrays, regardless of
signal length.
Args:
signal_id: ID of the stored signal to analyze (from load_signal)
model_name: Name of trained model (default: 'anomaly_model')
ctx: MCP context for progress/logging
Returns:
AnomalyPredictionResult with aggregate statistics and health
assessment.
Raises:
FileNotFoundError: If the model does not exist (the message
lists the models actually on disk).
ValueError: If the signal_id is not loaded, or no sampling rate
is available for segmentation.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| signal_id | Yes | ||
| model_name | No | anomaly_model |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| model_name | Yes | Name of the trained model used | |
| num_segments | Yes | Number of segments analyzed | |
| anomaly_count | Yes | Number of anomalies detected | |
| anomaly_ratio | Yes | Ratio of anomalies (0-1) | |
| overall_health | Yes | Overall health status: 'Healthy', 'Suspicious', 'Faulty' (thresholded on anomaly_ratio: <0.1, <0.3, >=0.3) | |
| worst_segments | No | Up to 10 most anomalous segments, each with segment_index, start_time_s, and score (when available) — enough to locate the worst regions without dumping per-segment arrays. | |
| score_percentiles | No | Percentiles (p5/p25/p50/p75/p95) of the model decision scores; negative = anomalous side. None when the model exposes no decision_function. | |
| segment_duration_s | Yes | Segment length in seconds (from the model's training metadata) |