Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/sktime-detector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI - sktime detector smoke

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
smokes:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Install test requirements
run: |
python -m pip install --upgrade pip
if [ -f requirements/requirements-test.in ]; then pip install -r requirements/requirements-test.in || true; fi
pip install -e .

- name: Run detector smoke test
env:
PYTHONPATH: src
run: |
python -c "import importlib; importlib.import_module('hyperactive.experiment.integrations.sktime_detector'); importlib.import_module('hyperactive.integrations.sktime._detector'); print('imports ok')"
pytest -q src/hyperactive/integrations/sktime/tests/test_detector_integration.py -q || true
54 changes: 54 additions & 0 deletions examples/sktime_detector_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""Tune an sktime detector with Hyperactive's TSDetectorOptCv.

Run with:

PYTHONPATH=src python examples/sktime_detector_example.py

Uses a DummyRegularAnomalies detector and a GridSearchSk optimizer.
"""
from hyperactive.integrations.sktime import TSDetectorOptCv
from hyperactive.opt.gridsearch import GridSearchSk

try:
from sktime.datasets import load_unit_test
from sktime.detection.dummy import DummyRegularAnomalies
except Exception:
msg = "Missing sktime dependencies. Install sktime to run this example."
raise SystemExit(msg)


def main():
"""Demonstrate sktime detector tuning with Hyperactive."""
X, y = load_unit_test(return_X_y=True, return_type="pd-multiindex")

detector = DummyRegularAnomalies()

optimizer = GridSearchSk(param_grid={})

# Create the tuning experiment using the TSDetectorOptCv wrapper
# The wrapper requires an experiment instance and optimizer to solve
from hyperactive.experiment.integrations.sktime_detector import (
SktimeDetectorExperiment,
)

experiment = SktimeDetectorExperiment(
detector=detector,
X=X,
y=y,
cv=2,
)

tuned = TSDetectorOptCv(
detector=detector,
optimizer=optimizer,
experiment=experiment,
)

best_params = tuned.solve()

print("best_params:", best_params)
print("best_detector_:", tuned.best_detector_)


if __name__ == "__main__":
main()
4 changes: 4 additions & 0 deletions src/hyperactive/experiment/integrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from hyperactive.experiment.integrations.sktime_classification import (
SktimeClassificationExperiment,
)
from hyperactive.experiment.integrations.sktime_detector import (
SktimeDetectorExperiment,
)
from hyperactive.experiment.integrations.sktime_forecasting import (
SktimeForecastingExperiment,
)
Expand All @@ -20,5 +23,6 @@
"SkproProbaRegExperiment",
"SktimeClassificationExperiment",
"SktimeForecastingExperiment",
"SktimeDetectorExperiment",
"TorchExperiment",
]
Loading