{"id":"f40c63c3-e959-41c4-82a1-0f67dd45d549","slug":"sample-predictive-maintenance-skill","kind":"skill","name":"sample-predictive-maintenance-skill","summary":"Skill for end-to-end predictive maintenance: explores raw IoT telemetry in S3, engineers features, trains AutoML models (RUL regression, failure classification, multi-label classification, or survival","owner":"aws-samples","repoUrl":"https://github.com/aws-samples/sample-predictive-maintenance-skill","license":"MIT-0","licenseTier":"permissive","trust":"official","stars":8,"match":null,"fewStars":false,"format":"skill","createdAt":"2026-06-30T16:35:24.000Z","addedAt":"2026-10-21T23:23:07.353Z","logoUrl":"https://avatars.githubusercontent.com/u/8931462?v=4","linkOnly":false,"collection":null,"skillPath":null,"categories":["writing"],"tags":[],"runtime":"binary","local":true,"cloudCapable":false,"cloudCapability":"unknown","cloudReadyOnPlatform":false,"needsApiKey":false,"reviewed":false,"syncedAt":"2026-10-25T11:56:08.084Z","sample":false,"url":"https://conduits.dev/tools/sample-predictive-maintenance-skill","language":"Python","transports":["stdio"],"install":{},"requirements":{"env":[],"upstreamMayCharge":false},"tools":null,"readme":"# Predictive Maintenance Skill\n\nAn AI agent skill that generates complete predictive maintenance (PdM) models end-to-end: from raw IoT sensor data in S3 to a deployed SageMaker inference endpoint, daily batch job, or edge device via AWS IoT Greengrass.\n\n> 📝 **Blog post:** [Building Predictive Maintenance Models from raw IoT data with Kiro and Amazon SageMaker](https://builder.aws.com/content/3DkXbcQxyPux7nYBREEBUW3W08F/building-predictive-maintenance-models-from-raw-iot-data-with-kiro-and-amazon-sagemaker) — a walkthrough of this project.\n\n## What It Does\n\nGive your AI Coding Assistant access to your S3 data and ask it to build a failure prediction model. The skill guides the agent through a nine-phase workflow:\n\n1. **Setup** — project scaffolding, dependencies\n2. **Data Exploration** — discover schemas, joins, formulation strategy\n3. **Raw Aggregation** — load, join, label, temporal split\n4. **Baselines** — first working model per formulation\n5. **Experimentation** — hypothesis-driven feature engineering loop\n6. **Save & Plan** — artifacts to S3, post-training decisions\n7. **Example Inference** — score one day of data for validation\n8. **Deploy** — real-time endpoint, daily batch, and/or edge device (Greengrass)\n9. **Documentation** — auto-generated project README\n\n## Supported Formulations\n\n| Formulation | Use When |\n|---|---|\n| **RUL Regression** | You have run-to-failure data and need precise remaining-life estimates |\n| **Failure Classification** | You have failure labels and need binary/multi-label alerts |\n| **Survival Analysis** | Devices are maintained before failure (censored data) |\n| **Anomaly Detection** | You want unsupervised deviation detection without failure labels |\n\n## Deployment Options\n\n| Mode | Infrastructure | Use When |\n|------|---------------|----------|\n| **Real-time endpoint** (8A) | SageMaker endpoint | Low-latency API calls, fleet-wide scoring |\n| **Batch inference** (8B) | EventBridge + Lambda + SageMaker Processing | Daily scheduled scoring, cost-efficient |\n| **Edge deployment** (8C) | IoT Greengrass + EC2/physical device | On-device inference, offline-capable, bandwidth-constrained |\n\n### Edge Deployment (Phase 8C)\n\nDeploy the trained model to edge devices using AWS IoT Greengrass. The model runs inference locally on sensor data and publishes only predictions (not raw data) to AWS IoT Core via MQTT. The edge component uses a pluggable sensor source interface — ships with CSV replay for demos; implement custom sources for OPC-UA, MQTT, Modbus, or any industrial protocol.\n\n```bash\n# Deploy infrastructure (EC2 + IoT Core + Greengrass)\ncd infrastructure/edge && cdk deploy\n\n# Build, publish, and deploy the Greengrass component\nbash scripts/deploy_edge.sh --model-dir ./fault_prediction/baseline/model\n\n# Teardown when done\nbash scripts/deploy_edge.sh --destroy\n```\n\nSee `edge_component/README.md` for the sensor source interface and `infrastructure/edge/README.md` for CloudWatch metric configuration per formulation.\n\n## Architecture\n\nThe three deployment modes at a glance — daily batch inference (EventBridge → Lambda → SageMaker Processing Job), a real-time SageMaker endpoint, and edge inference on AWS IoT Greengrass publishing to IoT Core:\n\n![Predictive maintenance deployment architectures: batch, real-time endpoint, and edge/Greengrass](docs/architecture-overview.png)\n\n## Benchmark Results\n\nResults from running the full skill workflow (Phases 1–5: setup → data prep → baseline → experimentation) on four canonical PdM benchmarks.\n\n**Best results** (after Phase 5 experimentation loop with feature engineering):\n\n| Benchmark | Metric | Best Result | Published SOTA | Notes |\n|-----------|--------|-------------|----------------|-------|\n| C-MAPSS FD001 (RUL) | RMSE ↓ | **11.40** | 9.21 (AutoRUL) | +24% gap; feature selection + XGBoost HPO |\n| AI4I 2020 (Classification) | F1 ↑ | **0.889** | ~0.99 (FL+SMOTE) | -10% gap; closes with SMOTE |\n| Backblaze hdfail (Survival) | C-index ↑ | **0.88** | 0.958 (Cox, 21 feats) | 52K drives, 94% censoring |\n| NASA SMAP (Anomaly Detection) | PA-F1 ↑ | **0.64** | ~0.90 (THOC/TranAD) | Spectral Residual; ROC AUC 0.61; a random detector scores PA-F1 0.63 (see note) |\n\n**Baselines** (Phase 4 only — no experimentation, default model, no feature engineering):\n\n| Benchmark | Metric | Baseline | Notes |\n|-----------|--------|----------|-------|\n| C-MAPSS FD001 (RUL) | RMSE ↓ | 16.48 | `RULPredictor(window_size=15, stride=5, presets=medium_quality)` |\n| AI4I 2020 (Classification) | F1 ↑ | 0.82 | `FailureClassifier()` with default features |\n| Backblaze hdfail (Survival) | C-index ↑ | 0.88 | `SurvivalPredictor()` — 52K drives, 94% censoring |\n| NASA SMAP (Anomaly Detection) | ROC AUC ↑ | 0.61 | `SpectralResidualDetector(sr_window=5, aggregation_percentile=95, contamination=0.10, sr_block_size=256)` |\n\nThe baselines in `pdm/benchmarks/baselines.json` are regression gates — they ensure code changes don't degrade the out-of-the-box model quality. The \"Best Result\" column reflects what the skill achieves when the full experimentation loop (Phase 5) runs with domain-informed feature engineering.\n\n**About the SMAP numbers.** The earlier SMAP F1 of 0.97 came from a decision threshold optimized on held-out test labels, so it was an oracle diagnostic, not deployable performance. The 0.44 that replaced it was a scoring artifact: the old global-FFT saliency changed scale with input length and exploded near exactly-zero spectral bins, so only 28 of 427k test points could ever be flagged. The detector now computes saliency over fixed-length blocks (orthonormal IFFT, relative spectral floor). The canonical run (threshold from normal training scores only, `contamination=0.10`) gives ROC AUC=0.6053, Average Precision=0.1613 (prevalence 0.128), and point-adjust F1=0.6378 (precision 0.47, recall 0.99). A random detector at the same 17% alert rate also reaches PA-F1≈0.63, so the ranking metrics are the honest SMAP numbers, and the regression gate uses ROC AUC.\n\n## Installation\n\n### Quick Install (git clone)\n\n```bash\ngit clone git@github.com:aws-samples/sample-predictive-maintenance-skill.git ~/.kiro/skills/predictive-maintenance\n```\n\n### Manual\n\nCopy this folder into your Kiro skills directory:\n- **Global** (all projects): `~/.kiro/skills/predictive-maintenance/`\n- **Workspace** (one project): `.kiro/skills/predictive-maintenance/`\n\n## Optional: Knowledge Acquisition Skill\n\nThe predictive-maintenance skill can leverage the **knowledge-acquisition** skill to build a domain-specific research wiki before running experiments. This is used in **Phase 5 (Experimentation)** — specifically Step 0: \"Build Domain Knowledge Base\" — where the agent researches state-of-the-art techniques from academic literature (arXiv, Semantic Scholar, Papers With Code, etc.) to ground experiments in proven methods rather than ad-hoc intuition.\n\nThe wiki produces actionable hypotheses for feature engineering and model selection, tailored to the specific PdM formulation (RUL, classification, survival, anomaly detection). Experiments that draw from literature-backed techniques consistently outperform those based on intuition alone.\n\n### Install\n\n```bash\ngit clone https://github.com/aws-samples/sample-knowledge-acquisition-skill.git ~/.kiro/skills/knowledge-acquisition\n```\n\nOr for workspace-scoped installation:\n\n```bash\ngit clone https://github.com/aws-samples/sample-knowledge-acquisition-skill.git .kiro/skills/knowledge-acquisition\n```\n\n### What It Does During Experimentation\n\nWhen the experimentation phase begins, the agent uses the knowledge-acquisition skill to:\n\n1. **Gather sources** — searches arXiv, Semantic Scholar, OpenAlex, and Papers With Code for papers relevant to the formulation (e.g., \"remaining useful life prediction\", \"unsupervised anomaly detection IoT\")\n2. **Distill findings** — extracts key techniques, feature engineering strategies, and model architectures\n3. **Write wiki pages** under `./wiki/concepts/`:\n   - `feature-engineering-pdm.md` — state-of-the-art feature engineering for the formulation\n   - `<formulation>-techniques.md` — best models, loss functions, evaluation metrics\n   - `domain-features.md` — domain-specific features for the equipment type\n4. **Generate experiment hypotheses** — each wiki page ends with an \"Implications for Experiments\" section listing concrete, actionable ideas\n\nWithout this skill installed, the experimentation phase still works — the agent will propose experiments based on feature importance analysis and CAAFE-style semantic reasoning. The knowledge-acquisition skill adds literature grounding that improves experiment quality.\n\n## Requirements\n\n- **Python 3.11+** with `uv` (or pip)\n- **AWS credentials** with S3 read access + SageMaker (for deployment)\n- **Kiro CLI**, or **Kiro IDE**, or **Claude Code**\n\nKey Python dependencies (installed automatically by `scripts/setup.sh`):\n- `autogluon.tabular` — AutoML training\n- `boto3` / `pyarrow` — S3 + Parquet I/O\n- `pandas` / `numpy` / `scikit-learn` — data processing\n- `lifelines` — survival analysis\n- `flask` — inference container\n\n## Usage\n\nStart your AI Coding Assistant and say:\n\n```\nBuild a predictive maintenance model from my S3 data in s3://my-bucket/\n```\n\nOr for benchmark datasets:\n\n```\nTrain a RUL model on the C-MAPSS dataset\n```\n\nThe skill activates automatically based on keywords like \"predictive maintenance\", \"failure prediction\", \"remaining useful life\", \"RUL\", or \"survival analysis\".\n\n## Project Structure\n\n```\npredictive-maintenance/\n├── SKILL.md                    # Agent instructions (9-phase workflow)\n├── README.md                   # This file\n├── docs/                       # Diagrams & static assets for docs\n│   └── architecture-overview.png\n├── references/                 # Detailed phase guides (loaded on demand)\n│   ├── data-exploration.md\n│   ├── benchmark-datasets.md\n│   ├── raw-aggregation.md\n│   ├── baselines.md\n│   ├── experimentation.md\n│   ├── artifacts.md\n│   ├── deployment.md\n│   └── readme-template.md\n├── scripts/                    # Setup & utilities\n│   ├── setup.sh                # One-command project bootstrap\n│   ├── save_model.sh           # Upload artifacts to S3\n│   └── pyproject.toml          # Dependencies\n├── pdm/                        # Standalone PdM library (usable without the skill)\n│   ├── README.md               # Library documentation\n│   ├── data/                   # S3 exploration, EAV aggregation, feature utils\n│   ├── anomaly_detection/      # Spectral Residual + Temporal PCA + Isolation Forest\n│   ├── fault_prediction/       # AutoGluon classification + RUL\n│   ├── rul/                    # Sliding-window RUL regression\n│   ├── survival/               # Cox PH, Weibull AFT, Random Survival Forest\n│   ├── deployment/             # Batch inference + SageMaker handlers\n│   └── remote/                 # SageMaker Training Job submission\n├── edge_component/             # Greengrass edge inference component\n│   ├── README.md               # Usage + custom sensor source guide\n│   ├── main.py                 # Inference loop (pluggable sensor sources)\n│   ├── sensor_sources/         # SensorSource ABC + CsvReplaySource\n│   ├── recipe.yaml             # Greengrass component recipe\n│   └── gdk-config.json         # GDK build configuration\n├── sagemaker_container/        # Custom Docker container for endpoints\n│   ├── README.md\n│   ├── Dockerfile\n│   ├── serve.py\n│   └── inference.py\n└── infrastructure/             # CDK stacks (independent apps per deployment mode)\n    ├── batch/                  # Phase 8B: EventBridge + Lambda + SageMaker\n    └── edge/                   # Phase 8C: IoT Core + Greengrass + EC2\n```\n\n## The `pdm/` Library\n\nThe `pdm/` directory is a standalone Python library usable independently of the AI Coding Assistant skill. It provides:\n\n- **5 model classes**: `AnomalyDetector`, `TemporalAnomalyDetector`, `SpectralResidualDetector`, `FailureClassifier`, `RULPredictor`, `SurvivalPredictor`\n- **CLI tools** for training, evaluation, and inference\n- **S3 utilities** for exploring and loading partitioned parquet data\n- **Batch inference** utilities for production scheduling\n\nSee [`pdm/README.md`](pdm/README.md) for full API documentation and usage.\n\n## How It Works\n\nYour AI Coding Assistant loads skills through **progressive disclosure**:\n\n1. At startup, only the `name` and `description` from `SKILL.md` frontmatter are loaded (minimal context cost)\n2. When your request matches the skill description, the full `SKILL.md` instructions load\n3. The agent reads `references/` files only when needed for the current phase\n\nThis means the skill has near-zero overhead when not activated.\n\n## Compatibility\n\nThis skill follows the open [Agent Skills](https://agentskills.io) standard and works with:\n\n- **Kiro CLI**, **Kiro IDE**, or **Claude Code**\n- Any agent that supports the Agent Skills `SKILL.md` format\n\n## Security\n\nSee [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.\n\n## License\n\nThis library is licensed under the MIT-0 License. See the LICENSE file.\n"}