# The anomaly detector trained on an incident

The anomaly detector classifies an incident-like latency as normal. Investigate
the training window and correct the baseline selection, rather than suppressing
alerts or changing the observations.

## Before you begin

Use Bash and Python 3.11 or later in a disposable local environment. Create a
virtual environment and install the pinned model library:

```sh
LAB_VENV="$(mktemp -d)"
python3 -m venv "$LAB_VENV"
. "$LAB_VENV/bin/activate"
python -m pip install -r requirements.txt
```

Installing packages needs internet access. This exercise trains a real
scikit-learn Isolation Forest on synthetic one-dimensional latency values. It
does not contact an external AI service or consume real operational data.

## Investigate

```sh
./setup.sh
cat baseline.csv
cat training-policy.json
python detector.py 225
```

Rows labeled `incident` belong to a known incident window; rows labeled
`healthy` belong to the approved baseline. The labels are supplied incident
records, not predictions made by the model. Change the training selection in
`training-policy.json` while retaining the original dataset and detector.
Each invocation trains a fresh deterministic model, so rerun the command
after changing the policy.

```sh
./verify.sh
./teardown.sh
```

Verification checks the original dataset and policy and exercises healthy and
incident-like observations that were not in the training data. The fixed
synthetic scenario demonstrates contamination, not a production-ready alert:
real baselines need representative data, validated labels, drift monitoring
and evaluation before deployment. Teardown has no service or cloud resources to
remove; deactivate and remove the temporary virtual environment separately
when done.
