dalheimdall 1.0.707__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dalheimdall-1.0.707/.gitignore +223 -0
- dalheimdall-1.0.707/LICENSE +21 -0
- dalheimdall-1.0.707/PKG-INFO +153 -0
- dalheimdall-1.0.707/README.md +118 -0
- dalheimdall-1.0.707/pyproject.toml +62 -0
- dalheimdall-1.0.707/src/dalheimdall/__init__.py +275 -0
- dalheimdall-1.0.707/src/dalheimdall/adaptive/__init__.py +84 -0
- dalheimdall-1.0.707/src/dalheimdall/adaptive/concept.py +316 -0
- dalheimdall-1.0.707/src/dalheimdall/adaptive/policy.py +142 -0
- dalheimdall-1.0.707/src/dalheimdall/adaptive/recurrent.py +610 -0
- dalheimdall-1.0.707/src/dalheimdall/adaptive/retrain.py +335 -0
- dalheimdall-1.0.707/src/dalheimdall/adaptive/selectors.py +796 -0
- dalheimdall-1.0.707/src/dalheimdall/base.py +375 -0
- dalheimdall-1.0.707/src/dalheimdall/benchmark.py +829 -0
- dalheimdall-1.0.707/src/dalheimdall/datasets.py +126 -0
- dalheimdall-1.0.707/src/dalheimdall/detectors/__init__.py +116 -0
- dalheimdall-1.0.707/src/dalheimdall/detectors/ensemble.py +750 -0
- dalheimdall-1.0.707/src/dalheimdall/detectors/error.py +686 -0
- dalheimdall-1.0.707/src/dalheimdall/detectors/multivariate.py +565 -0
- dalheimdall-1.0.707/src/dalheimdall/detectors/neural.py +1594 -0
- dalheimdall-1.0.707/src/dalheimdall/detectors/sketch.py +1133 -0
- dalheimdall-1.0.707/src/dalheimdall/detectors/statistical.py +1612 -0
- dalheimdall-1.0.707/src/dalheimdall/detectors/structural.py +1374 -0
- dalheimdall-1.0.707/src/dalheimdall/detectors/univariate.py +810 -0
- dalheimdall-1.0.707/src/dalheimdall/memory.py +107 -0
- dalheimdall-1.0.707/src/dalheimdall/metrics.py +231 -0
- dalheimdall-1.0.707/src/dalheimdall/norm.py +109 -0
- dalheimdall-1.0.707/src/dalheimdall/transforms.py +72 -0
- dalheimdall-1.0.707/src/dalheimdall/utils.py +565 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
*.lcov
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
# Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# uv
|
|
99
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
100
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
101
|
+
# commonly ignored for libraries.
|
|
102
|
+
# uv.lock
|
|
103
|
+
|
|
104
|
+
# poetry
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
106
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
107
|
+
# commonly ignored for libraries.
|
|
108
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
109
|
+
# poetry.lock
|
|
110
|
+
# poetry.toml
|
|
111
|
+
|
|
112
|
+
# pdm
|
|
113
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
114
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
115
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
116
|
+
# pdm.lock
|
|
117
|
+
# pdm.toml
|
|
118
|
+
.pdm-python
|
|
119
|
+
.pdm-build/
|
|
120
|
+
|
|
121
|
+
# pixi
|
|
122
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
123
|
+
# pixi.lock
|
|
124
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
125
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
126
|
+
.pixi/*
|
|
127
|
+
!.pixi/config.toml
|
|
128
|
+
|
|
129
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
130
|
+
__pypackages__/
|
|
131
|
+
|
|
132
|
+
# Celery stuff
|
|
133
|
+
celerybeat-schedule*
|
|
134
|
+
celerybeat.pid
|
|
135
|
+
|
|
136
|
+
# Redis
|
|
137
|
+
*.rdb
|
|
138
|
+
*.aof
|
|
139
|
+
*.pid
|
|
140
|
+
|
|
141
|
+
# RabbitMQ
|
|
142
|
+
mnesia/
|
|
143
|
+
rabbitmq/
|
|
144
|
+
rabbitmq-data/
|
|
145
|
+
|
|
146
|
+
# ActiveMQ
|
|
147
|
+
activemq-data/
|
|
148
|
+
|
|
149
|
+
# SageMath parsed files
|
|
150
|
+
*.sage.py
|
|
151
|
+
|
|
152
|
+
# Environments
|
|
153
|
+
.env
|
|
154
|
+
.envrc
|
|
155
|
+
.venv
|
|
156
|
+
env/
|
|
157
|
+
venv/
|
|
158
|
+
ENV/
|
|
159
|
+
env.bak/
|
|
160
|
+
venv.bak/
|
|
161
|
+
|
|
162
|
+
# Conda environments
|
|
163
|
+
conda-meta/
|
|
164
|
+
|
|
165
|
+
# Spyder project settings
|
|
166
|
+
.spyderproject
|
|
167
|
+
.spyproject
|
|
168
|
+
|
|
169
|
+
# Rope project settings
|
|
170
|
+
.ropeproject
|
|
171
|
+
|
|
172
|
+
# mkdocs/Zensical documentation
|
|
173
|
+
/site
|
|
174
|
+
|
|
175
|
+
# mypy
|
|
176
|
+
.mypy_cache/
|
|
177
|
+
.dmypy.json
|
|
178
|
+
dmypy.json
|
|
179
|
+
|
|
180
|
+
# Pyre type checker
|
|
181
|
+
.pyre/
|
|
182
|
+
|
|
183
|
+
# pytype static type analyzer
|
|
184
|
+
.pytype/
|
|
185
|
+
|
|
186
|
+
# Cython debug symbols
|
|
187
|
+
cython_debug/
|
|
188
|
+
|
|
189
|
+
# PyCharm
|
|
190
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
191
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
192
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
193
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
194
|
+
# .idea/
|
|
195
|
+
|
|
196
|
+
# Abstra
|
|
197
|
+
# Abstra is an AI-powered process automation framework.
|
|
198
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
199
|
+
# Learn more at https://abstra.io/docs
|
|
200
|
+
.abstra/
|
|
201
|
+
|
|
202
|
+
# Visual Studio Code
|
|
203
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
|
|
204
|
+
# can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
205
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer, you
|
|
206
|
+
# could uncomment the following to ignore the entire vscode folder
|
|
207
|
+
# .vscode/
|
|
208
|
+
# Temporary file for partial code execution
|
|
209
|
+
tempCodeRunnerFile.py
|
|
210
|
+
|
|
211
|
+
# Ruff stuff:
|
|
212
|
+
.ruff_cache/
|
|
213
|
+
|
|
214
|
+
# PyPI configuration file
|
|
215
|
+
.pypirc
|
|
216
|
+
|
|
217
|
+
# Marimo
|
|
218
|
+
marimo/_static/
|
|
219
|
+
marimo/_lsp/
|
|
220
|
+
__marimo__/
|
|
221
|
+
|
|
222
|
+
# Streamlit
|
|
223
|
+
.streamlit/secrets.toml
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Data Analytics Lab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dalheimdall
|
|
3
|
+
Version: 1.0.707
|
|
4
|
+
Summary: Drift Adaptable Models (Python port of the R heimdall package)
|
|
5
|
+
Project-URL: Homepage, https://github.com/cefet-rj-dal/pyheimdall
|
|
6
|
+
Project-URL: Repository, https://github.com/cefet-rj-dal/pyheimdall
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/cefet-rj-dal/pyheimdall/issues
|
|
8
|
+
Author: Lucas Tavares, Leonardo Carvalho, Rodrigo Machado, Diego Carvalho, Esther Pacitti, Fabio Porto, Eduardo Ogasawara
|
|
9
|
+
Maintainer-email: Eduardo Ogasawara <eogasawara@ieee.org>
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: adaptive models,concept drift,data streams,drift detection,machine learning
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
|
+
Requires-Python: >=3.9
|
|
19
|
+
Requires-Dist: numpy>=1.23
|
|
20
|
+
Requires-Dist: pandas>=1.5
|
|
21
|
+
Requires-Dist: pydaltoolbox>=0.25.0
|
|
22
|
+
Requires-Dist: scikit-learn>=1.2
|
|
23
|
+
Requires-Dist: scipy>=1.10
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: build; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
27
|
+
Requires-Dist: ruff>=0.1; extra == 'dev'
|
|
28
|
+
Requires-Dist: twine; extra == 'dev'
|
|
29
|
+
Provides-Extra: docs
|
|
30
|
+
Requires-Dist: ipykernel>=6; extra == 'docs'
|
|
31
|
+
Requires-Dist: jupytext>=1.16; extra == 'docs'
|
|
32
|
+
Requires-Dist: nbclient>=0.9; extra == 'docs'
|
|
33
|
+
Requires-Dist: nbconvert>=7; extra == 'docs'
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# dalheimdall
|
|
37
|
+
|
|
38
|
+
[](https://www.python.org/)
|
|
39
|
+
[](https://github.com/cefet-rj-dal/pyheimdall/blob/main/LICENSE)
|
|
40
|
+
|
|
41
|
+
Python port of the R [heimdall](https://github.com/cefet-rj-dal/heimdall) package —
|
|
42
|
+
*Drift Adaptable Models*.
|
|
43
|
+
|
|
44
|
+
`dalheimdall` extends the DAL **Experiment Line** (`pydaltoolbox`) to streaming data and
|
|
45
|
+
non-stationary environments, providing a unified API for **concept drift detection**,
|
|
46
|
+
**reactive retraining**, **recurrent concept pools**, and **controlled drift benchmarking**.
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install dalheimdall
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
For local development:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install -e ".[dev]"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Quickstart
|
|
61
|
+
|
|
62
|
+
### 1. Concept Drift Detection
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
import dalheimdall as ph
|
|
66
|
+
|
|
67
|
+
data = ph.datasets.st_drift_examples()
|
|
68
|
+
stream = data["multivariate"]
|
|
69
|
+
|
|
70
|
+
detector = ph.DfrAdwin(target_feat="x1", delta=0.002)
|
|
71
|
+
detector.fit(stream)
|
|
72
|
+
|
|
73
|
+
print("Drift detected:", detector.drifted)
|
|
74
|
+
print(detector.drifter_output.tail())
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 2. Reactive Retraining (`AdpRetrain`)
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
import numpy as np
|
|
81
|
+
import pandas as pd
|
|
82
|
+
import pydaltoolbox as dal
|
|
83
|
+
import dalheimdall as ph
|
|
84
|
+
|
|
85
|
+
rng = np.random.default_rng(42)
|
|
86
|
+
x = rng.normal(0, 1, size=(200, 2))
|
|
87
|
+
y = (x[:, 0] > 0).astype(int)
|
|
88
|
+
y[100:] = (x[100:, 0] <= 0).astype(int) # abrupt concept flip
|
|
89
|
+
df = pd.DataFrame({"x1": x[:, 0], "x2": x[:, 1], "y": y.astype(str)})
|
|
90
|
+
|
|
91
|
+
workflow = ph.AdpRetrain(
|
|
92
|
+
model=dal.ClaDtree("y", slevels=["0", "1"], random_state=42),
|
|
93
|
+
drift_method=ph.DfrDdm(min_instances=20),
|
|
94
|
+
warmup_size=40,
|
|
95
|
+
)
|
|
96
|
+
for start in range(0, len(df), 40):
|
|
97
|
+
batch = df.iloc[start : start + 40]
|
|
98
|
+
workflow.fit(batch[["x1", "x2"]], batch[["y"]])
|
|
99
|
+
|
|
100
|
+
print("Drift detected on last batch:", workflow.drifted)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 3. Recurrent Concept Pools (`AdpRecurrent`)
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
import pydaltoolbox as dal
|
|
107
|
+
import dalheimdall as ph
|
|
108
|
+
|
|
109
|
+
workflow = ph.recurrent_ensemble(
|
|
110
|
+
method=dal.ClaDtree("y", slevels=["0", "1"], random_state=42),
|
|
111
|
+
train_size=40,
|
|
112
|
+
numerical_cols=["x1", "x2"],
|
|
113
|
+
detector=ph.DfrAdwin(target_feat="x1"),
|
|
114
|
+
memory=ph.MemoryBasic(),
|
|
115
|
+
)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## What's Included
|
|
119
|
+
|
|
120
|
+
Every detector inherits from `Drifter` (`ErrorBased`, `DistBased`, or `MvDistBased`),
|
|
121
|
+
supporting streaming `update_state(value) -> bool`, batch `fit(data) -> self`
|
|
122
|
+
(populating `drifter_output`), and `reset_state()`.
|
|
123
|
+
|
|
124
|
+
| Group | Classes & Functions |
|
|
125
|
+
|---|---|
|
|
126
|
+
| **Core & Infrastructure** | `Drifter`, `Dummy`, `DfrInactive`, `DfrPassive`, `ErrorBased`, `DistBased`, `MvDistBased`, `DfrMultiCriteria`, `DriftWorkflow`, `drift_step`, `OneHot`, `TransPipeline`, `NrmBase`, `NrmMemory`, `MemoryManager`, `MemoryBasic`, `MemoryOversampling`, `MemoryUndersampling` |
|
|
127
|
+
| **Metrics** | `Metric`, `MtAccuracy`, `MtPrecision`, `MtRecall`, `MtFscore`, `MtRocauc`, `cm_metrics`, `f1_aggregate` |
|
|
128
|
+
| **Error-Based Detectors** | `DfrDdm`, `DfrEddm`, `DfrHddm`, `DfrEcdd`, `DfrCusum` |
|
|
129
|
+
| **Univariate Distribution Detectors** | `DfrAdwin`, `DfrPageHinkley`, `DfrKswin`, `DfrLbdd`, `DfrMcdd`, `DfrPsi`, `DfrOnlinebcp`, `DfrFastlr`, `DfrGreedyks`, `DfrIks`, `DfrQts`, `psi`, `online_bcp`, `fastlr_split`, `ks_sf`, `GreedyKS`, `iks_ca`, `IKS` |
|
|
130
|
+
| **Multivariate & Structural Detectors** | `DfrKldist`, `DfrAedd`, `DfrCosine`, `DfrEikmeans`, `DfrMmqt`, `DfrDde`, `DfrLlr2`, `cosine_score`, `eikmeans`, `eikmeans_test`, `mmqt`, `mmqt_test`, `dde_curve`, `dde_score`, `dde_feature_drift`, `spbn`, `spbn_loglik` |
|
|
131
|
+
| **Ensemble, OOD & Student-Teacher** | `DfrStudd`, `DfrProton`, `DfrEnsemble`, `ensemble_vote` |
|
|
132
|
+
| **Neural & Deep CPD Detectors** | `DfrPadd`, `DfrMcd`, `DfrIndid`, `DfrWwAggr`, `indid`, `indid_predict`, `tscp2`, `ts2vec`, `cpd_scores`, `cpd_calibrate`, `cpd_ensemble`, `cpd_ensemble_fit`, `wwaggr` |
|
|
133
|
+
| **Adaptive Workflows** | `AdpRetrain`, `AdpRecurrent`, `adapt_static`, `adapt_retrain`, `adapt_incremental`, `adapt_reset`, `recurrent_ensemble`, `recurrent_incremental`, `Concept`, `ConceptPool`, `ConceptPoolInactive`, `TrainStatic`, `TrainRetrain`, `TrainIncremental`, `SlctInactive`, `SlctPsi`, `SlctErrorMetrics`, `SlctPsiThenBest`, `SlctPsiThenError`, `SlctAe`, `EvtLeastUsed`, `EvtRedundant`, `RankRatio`, `RankPsi`, `RareKeep`, `RareDrop`, `RecAlways`, `RecStable`, `LearnedLimit` |
|
|
134
|
+
| **Benchmarks & Datasets** | `datasets.st_drift_examples()`, `dsg_source`, `dsg_take`, `dsg_drift`, `dsg_stream`, `dsg_mmd_test`, `dsg_source_data`, `dsg_source_regions`, `dsg_sea`, `dsg_sine`, `dsg_mixed`, `dsg_agrawal` |
|
|
135
|
+
|
|
136
|
+
## Examples
|
|
137
|
+
|
|
138
|
+
Rendered examples live in [examples/README.md](examples/README.md) and are generated from
|
|
139
|
+
executable Markdown notebooks under `notebooks/` via:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
python notebooks/conversor.py
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Related DAL Projects
|
|
146
|
+
|
|
147
|
+
- [pydaltoolbox](https://github.com/cefet-rj-dal/pydaltoolbox) — Experiment Line foundations (Python)
|
|
148
|
+
- [heimdall](https://github.com/cefet-rj-dal/heimdall) — R original
|
|
149
|
+
- [Data Analytics Lab](https://eic.cefet-rj.br/~dal/)
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
MIT
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# dalheimdall
|
|
2
|
+
|
|
3
|
+
[](https://www.python.org/)
|
|
4
|
+
[](https://github.com/cefet-rj-dal/pyheimdall/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
Python port of the R [heimdall](https://github.com/cefet-rj-dal/heimdall) package —
|
|
7
|
+
*Drift Adaptable Models*.
|
|
8
|
+
|
|
9
|
+
`dalheimdall` extends the DAL **Experiment Line** (`pydaltoolbox`) to streaming data and
|
|
10
|
+
non-stationary environments, providing a unified API for **concept drift detection**,
|
|
11
|
+
**reactive retraining**, **recurrent concept pools**, and **controlled drift benchmarking**.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install dalheimdall
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
For local development:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install -e ".[dev]"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quickstart
|
|
26
|
+
|
|
27
|
+
### 1. Concept Drift Detection
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
import dalheimdall as ph
|
|
31
|
+
|
|
32
|
+
data = ph.datasets.st_drift_examples()
|
|
33
|
+
stream = data["multivariate"]
|
|
34
|
+
|
|
35
|
+
detector = ph.DfrAdwin(target_feat="x1", delta=0.002)
|
|
36
|
+
detector.fit(stream)
|
|
37
|
+
|
|
38
|
+
print("Drift detected:", detector.drifted)
|
|
39
|
+
print(detector.drifter_output.tail())
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 2. Reactive Retraining (`AdpRetrain`)
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
import numpy as np
|
|
46
|
+
import pandas as pd
|
|
47
|
+
import pydaltoolbox as dal
|
|
48
|
+
import dalheimdall as ph
|
|
49
|
+
|
|
50
|
+
rng = np.random.default_rng(42)
|
|
51
|
+
x = rng.normal(0, 1, size=(200, 2))
|
|
52
|
+
y = (x[:, 0] > 0).astype(int)
|
|
53
|
+
y[100:] = (x[100:, 0] <= 0).astype(int) # abrupt concept flip
|
|
54
|
+
df = pd.DataFrame({"x1": x[:, 0], "x2": x[:, 1], "y": y.astype(str)})
|
|
55
|
+
|
|
56
|
+
workflow = ph.AdpRetrain(
|
|
57
|
+
model=dal.ClaDtree("y", slevels=["0", "1"], random_state=42),
|
|
58
|
+
drift_method=ph.DfrDdm(min_instances=20),
|
|
59
|
+
warmup_size=40,
|
|
60
|
+
)
|
|
61
|
+
for start in range(0, len(df), 40):
|
|
62
|
+
batch = df.iloc[start : start + 40]
|
|
63
|
+
workflow.fit(batch[["x1", "x2"]], batch[["y"]])
|
|
64
|
+
|
|
65
|
+
print("Drift detected on last batch:", workflow.drifted)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 3. Recurrent Concept Pools (`AdpRecurrent`)
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
import pydaltoolbox as dal
|
|
72
|
+
import dalheimdall as ph
|
|
73
|
+
|
|
74
|
+
workflow = ph.recurrent_ensemble(
|
|
75
|
+
method=dal.ClaDtree("y", slevels=["0", "1"], random_state=42),
|
|
76
|
+
train_size=40,
|
|
77
|
+
numerical_cols=["x1", "x2"],
|
|
78
|
+
detector=ph.DfrAdwin(target_feat="x1"),
|
|
79
|
+
memory=ph.MemoryBasic(),
|
|
80
|
+
)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## What's Included
|
|
84
|
+
|
|
85
|
+
Every detector inherits from `Drifter` (`ErrorBased`, `DistBased`, or `MvDistBased`),
|
|
86
|
+
supporting streaming `update_state(value) -> bool`, batch `fit(data) -> self`
|
|
87
|
+
(populating `drifter_output`), and `reset_state()`.
|
|
88
|
+
|
|
89
|
+
| Group | Classes & Functions |
|
|
90
|
+
|---|---|
|
|
91
|
+
| **Core & Infrastructure** | `Drifter`, `Dummy`, `DfrInactive`, `DfrPassive`, `ErrorBased`, `DistBased`, `MvDistBased`, `DfrMultiCriteria`, `DriftWorkflow`, `drift_step`, `OneHot`, `TransPipeline`, `NrmBase`, `NrmMemory`, `MemoryManager`, `MemoryBasic`, `MemoryOversampling`, `MemoryUndersampling` |
|
|
92
|
+
| **Metrics** | `Metric`, `MtAccuracy`, `MtPrecision`, `MtRecall`, `MtFscore`, `MtRocauc`, `cm_metrics`, `f1_aggregate` |
|
|
93
|
+
| **Error-Based Detectors** | `DfrDdm`, `DfrEddm`, `DfrHddm`, `DfrEcdd`, `DfrCusum` |
|
|
94
|
+
| **Univariate Distribution Detectors** | `DfrAdwin`, `DfrPageHinkley`, `DfrKswin`, `DfrLbdd`, `DfrMcdd`, `DfrPsi`, `DfrOnlinebcp`, `DfrFastlr`, `DfrGreedyks`, `DfrIks`, `DfrQts`, `psi`, `online_bcp`, `fastlr_split`, `ks_sf`, `GreedyKS`, `iks_ca`, `IKS` |
|
|
95
|
+
| **Multivariate & Structural Detectors** | `DfrKldist`, `DfrAedd`, `DfrCosine`, `DfrEikmeans`, `DfrMmqt`, `DfrDde`, `DfrLlr2`, `cosine_score`, `eikmeans`, `eikmeans_test`, `mmqt`, `mmqt_test`, `dde_curve`, `dde_score`, `dde_feature_drift`, `spbn`, `spbn_loglik` |
|
|
96
|
+
| **Ensemble, OOD & Student-Teacher** | `DfrStudd`, `DfrProton`, `DfrEnsemble`, `ensemble_vote` |
|
|
97
|
+
| **Neural & Deep CPD Detectors** | `DfrPadd`, `DfrMcd`, `DfrIndid`, `DfrWwAggr`, `indid`, `indid_predict`, `tscp2`, `ts2vec`, `cpd_scores`, `cpd_calibrate`, `cpd_ensemble`, `cpd_ensemble_fit`, `wwaggr` |
|
|
98
|
+
| **Adaptive Workflows** | `AdpRetrain`, `AdpRecurrent`, `adapt_static`, `adapt_retrain`, `adapt_incremental`, `adapt_reset`, `recurrent_ensemble`, `recurrent_incremental`, `Concept`, `ConceptPool`, `ConceptPoolInactive`, `TrainStatic`, `TrainRetrain`, `TrainIncremental`, `SlctInactive`, `SlctPsi`, `SlctErrorMetrics`, `SlctPsiThenBest`, `SlctPsiThenError`, `SlctAe`, `EvtLeastUsed`, `EvtRedundant`, `RankRatio`, `RankPsi`, `RareKeep`, `RareDrop`, `RecAlways`, `RecStable`, `LearnedLimit` |
|
|
99
|
+
| **Benchmarks & Datasets** | `datasets.st_drift_examples()`, `dsg_source`, `dsg_take`, `dsg_drift`, `dsg_stream`, `dsg_mmd_test`, `dsg_source_data`, `dsg_source_regions`, `dsg_sea`, `dsg_sine`, `dsg_mixed`, `dsg_agrawal` |
|
|
100
|
+
|
|
101
|
+
## Examples
|
|
102
|
+
|
|
103
|
+
Rendered examples live in [examples/README.md](examples/README.md) and are generated from
|
|
104
|
+
executable Markdown notebooks under `notebooks/` via:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
python notebooks/conversor.py
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Related DAL Projects
|
|
111
|
+
|
|
112
|
+
- [pydaltoolbox](https://github.com/cefet-rj-dal/pydaltoolbox) — Experiment Line foundations (Python)
|
|
113
|
+
- [heimdall](https://github.com/cefet-rj-dal/heimdall) — R original
|
|
114
|
+
- [Data Analytics Lab](https://eic.cefet-rj.br/~dal/)
|
|
115
|
+
|
|
116
|
+
## License
|
|
117
|
+
|
|
118
|
+
MIT
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dalheimdall"
|
|
7
|
+
version = "1.0.707"
|
|
8
|
+
description = "Drift Adaptable Models (Python port of the R heimdall package)"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Lucas Tavares" },
|
|
14
|
+
{ name = "Leonardo Carvalho" },
|
|
15
|
+
{ name = "Rodrigo Machado" },
|
|
16
|
+
{ name = "Diego Carvalho" },
|
|
17
|
+
{ name = "Esther Pacitti" },
|
|
18
|
+
{ name = "Fabio Porto" },
|
|
19
|
+
{ name = "Eduardo Ogasawara" },
|
|
20
|
+
]
|
|
21
|
+
maintainers = [
|
|
22
|
+
{ name = "Eduardo Ogasawara", email = "eogasawara@ieee.org" },
|
|
23
|
+
]
|
|
24
|
+
keywords = ["concept drift", "drift detection", "adaptive models", "data streams", "machine learning"]
|
|
25
|
+
classifiers = [
|
|
26
|
+
"Development Status :: 5 - Production/Stable",
|
|
27
|
+
"Intended Audience :: Science/Research",
|
|
28
|
+
"License :: OSI Approved :: MIT License",
|
|
29
|
+
"Programming Language :: Python :: 3",
|
|
30
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
31
|
+
]
|
|
32
|
+
dependencies = [
|
|
33
|
+
"numpy>=1.23",
|
|
34
|
+
"pandas>=1.5",
|
|
35
|
+
"scipy>=1.10",
|
|
36
|
+
"scikit-learn>=1.2",
|
|
37
|
+
"pydaltoolbox>=0.25.0",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[project.optional-dependencies]
|
|
41
|
+
dev = ["pytest>=7", "ruff>=0.1", "build", "twine"]
|
|
42
|
+
docs = ["jupytext>=1.16", "nbconvert>=7", "nbclient>=0.9", "ipykernel>=6"]
|
|
43
|
+
|
|
44
|
+
[project.urls]
|
|
45
|
+
Homepage = "https://github.com/cefet-rj-dal/pyheimdall"
|
|
46
|
+
Repository = "https://github.com/cefet-rj-dal/pyheimdall"
|
|
47
|
+
"Bug Tracker" = "https://github.com/cefet-rj-dal/pyheimdall/issues"
|
|
48
|
+
|
|
49
|
+
[tool.hatch.build.targets.wheel]
|
|
50
|
+
packages = ["src/dalheimdall"]
|
|
51
|
+
|
|
52
|
+
[tool.hatch.build.targets.sdist]
|
|
53
|
+
include = ["src/dalheimdall", "README.md", "LICENSE"]
|
|
54
|
+
exclude = ["develop", "notebooks", "examples", "tests"]
|
|
55
|
+
|
|
56
|
+
[tool.pytest.ini_options]
|
|
57
|
+
testpaths = ["tests"]
|
|
58
|
+
addopts = "-q"
|
|
59
|
+
|
|
60
|
+
[tool.ruff]
|
|
61
|
+
line-length = 100
|
|
62
|
+
target-version = "py39"
|