deep-river 0.2.6__tar.gz → 0.2.8__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.
- {deep_river-0.2.6 → deep_river-0.2.8}/PKG-INFO +29 -109
- {deep_river-0.2.6 → deep_river-0.2.8}/README.md +9 -5
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/__version__.py +1 -1
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/anomaly/__init__.py +1 -5
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/anomaly/ae.py +55 -29
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/anomaly/probability_weighted_ae.py +18 -19
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/anomaly/rolling_ae.py +18 -29
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/anomaly/scaler.py +2 -6
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/base.py +102 -15
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/classification/__init__.py +1 -4
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/classification/classifier.py +95 -149
- deep_river-0.2.8/deep_river/classification/rolling_classifier.py +282 -0
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/classification/zoo.py +38 -28
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/regression/multioutput.py +10 -13
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/regression/regressor.py +32 -31
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/regression/rolling_regressor.py +39 -39
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/regression/zoo.py +25 -20
- deep_river-0.2.8/deep_river/utils/layer_adaptation.py +239 -0
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/utils/params.py +11 -16
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/utils/tensor_conversion.py +59 -24
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/utils/test_estimators.py +2 -6
- deep_river-0.2.8/deep_river/utils/test_layer_adaptation.py +179 -0
- deep_river-0.2.8/deep_river/utils/test_tensor_conversion.py +150 -0
- deep_river-0.2.8/pyproject.toml +83 -0
- deep_river-0.2.6/deep_river/classification/rolling_classifier.py +0 -605
- deep_river-0.2.6/deep_river/utils/test_tensor_conversion.py +0 -117
- deep_river-0.2.6/deep_river.egg-info/PKG-INFO +0 -289
- deep_river-0.2.6/deep_river.egg-info/SOURCES.txt +0 -34
- deep_river-0.2.6/deep_river.egg-info/dependency_links.txt +0 -1
- deep_river-0.2.6/deep_river.egg-info/requires.txt +0 -101
- deep_river-0.2.6/deep_river.egg-info/top_level.txt +0 -1
- deep_river-0.2.6/pyproject.toml +0 -63
- deep_river-0.2.6/setup.cfg +0 -9
- deep_river-0.2.6/setup.py +0 -111
- {deep_river-0.2.6 → deep_river-0.2.8}/LICENSE +0 -0
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/__init__.py +0 -0
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/regression/__init__.py +0 -0
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/utils/__init__.py +0 -0
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/utils/estimator_checks.py +0 -0
- {deep_river-0.2.6 → deep_river-0.2.8}/deep_river/utils/hooks.py +0 -0
|
@@ -1,119 +1,34 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: deep_river
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.8
|
|
4
4
|
Summary: Online Deep Learning for river
|
|
5
|
-
Home-page: https://online-ml
|
|
5
|
+
Home-page: https://github.com/online-ml/deep-river
|
|
6
|
+
License: BSD-3-Clause
|
|
7
|
+
Keywords: online-learning,deep-learning,data-streams
|
|
6
8
|
Author: Cedric Kulbach
|
|
7
9
|
Author-email: cedric.kulbach@googlemail.com
|
|
8
|
-
|
|
10
|
+
Requires-Python: >=3.10,<3.13
|
|
9
11
|
Classifier: License :: OSI Approved :: BSD License
|
|
10
12
|
Classifier: Programming Language :: Python
|
|
11
13
|
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
17
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
16
18
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
17
|
-
Requires-
|
|
19
|
+
Requires-Dist: mkdocstrings[python] (>=0.19.0)
|
|
20
|
+
Requires-Dist: numpy (>=1.26.4,<1.27.0)
|
|
21
|
+
Requires-Dist: ordered-set (>=4.1.0,<4.2.0)
|
|
22
|
+
Requires-Dist: pandas (>=2.2.2,<2.3.0)
|
|
23
|
+
Requires-Dist: pytkdocs[numpy-style] (>=0.5.0)
|
|
24
|
+
Requires-Dist: river
|
|
25
|
+
Requires-Dist: scikit-learn (>=1.5.0,<1.6.0)
|
|
26
|
+
Requires-Dist: torch (>=2.2.2,<2.3.0)
|
|
27
|
+
Requires-Dist: torchviz (>=0.0.2,<0.1.0)
|
|
28
|
+
Requires-Dist: tqdm (>=4.66.5,<4.67.0)
|
|
29
|
+
Project-URL: Documentation, https://github.com/online-ml/deep-river
|
|
30
|
+
Project-URL: Repository, https://github.com/online-ml/deep-river
|
|
18
31
|
Description-Content-Type: text/markdown
|
|
19
|
-
License-File: LICENSE
|
|
20
|
-
Requires-Dist: scikit-learn~=1.4.2
|
|
21
|
-
Requires-Dist: torch~=2.2.2
|
|
22
|
-
Requires-Dist: pandas~=2.2.2
|
|
23
|
-
Requires-Dist: numpy~=1.26.4
|
|
24
|
-
Requires-Dist: river~=0.21.1
|
|
25
|
-
Requires-Dist: tqdm~=4.66.4
|
|
26
|
-
Requires-Dist: ordered-set~=4.1.0
|
|
27
|
-
Requires-Dist: torchviz~=0.0.2
|
|
28
|
-
Provides-Extra: dev
|
|
29
|
-
Requires-Dist: scikit-learn~=1.4.2; extra == "dev"
|
|
30
|
-
Requires-Dist: torch~=2.2.2; extra == "dev"
|
|
31
|
-
Requires-Dist: pandas~=2.2.2; extra == "dev"
|
|
32
|
-
Requires-Dist: numpy~=1.26.4; extra == "dev"
|
|
33
|
-
Requires-Dist: river~=0.21.1; extra == "dev"
|
|
34
|
-
Requires-Dist: tqdm~=4.66.4; extra == "dev"
|
|
35
|
-
Requires-Dist: ordered-set~=4.1.0; extra == "dev"
|
|
36
|
-
Requires-Dist: torchviz~=0.0.2; extra == "dev"
|
|
37
|
-
Requires-Dist: graphviz>=0.10.1; extra == "dev"
|
|
38
|
-
Requires-Dist: matplotlib>=3.0.2; extra == "dev"
|
|
39
|
-
Requires-Dist: mypy>=0.990; extra == "dev"
|
|
40
|
-
Requires-Dist: pre-commit>=2.20.0; extra == "dev"
|
|
41
|
-
Requires-Dist: pytest>=7.2.0; extra == "dev"
|
|
42
|
-
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
43
|
-
Requires-Dist: scikit-learn>=0.22.1; extra == "dev"
|
|
44
|
-
Requires-Dist: black>=22.10.0; extra == "dev"
|
|
45
|
-
Requires-Dist: flake8>=5.0.4; extra == "dev"
|
|
46
|
-
Requires-Dist: isort>=5.10.1; extra == "dev"
|
|
47
|
-
Requires-Dist: jupyter>=1.0.0; extra == "dev"
|
|
48
|
-
Requires-Dist: pyupgrade==3.2.0; extra == "dev"
|
|
49
|
-
Provides-Extra: docs
|
|
50
|
-
Requires-Dist: scikit-learn~=1.4.2; extra == "docs"
|
|
51
|
-
Requires-Dist: torch~=2.2.2; extra == "docs"
|
|
52
|
-
Requires-Dist: pandas~=2.2.2; extra == "docs"
|
|
53
|
-
Requires-Dist: numpy~=1.26.4; extra == "docs"
|
|
54
|
-
Requires-Dist: river~=0.21.1; extra == "docs"
|
|
55
|
-
Requires-Dist: tqdm~=4.66.4; extra == "docs"
|
|
56
|
-
Requires-Dist: ordered-set~=4.1.0; extra == "docs"
|
|
57
|
-
Requires-Dist: torchviz~=0.0.2; extra == "docs"
|
|
58
|
-
Requires-Dist: flask>=2.0.2; extra == "docs"
|
|
59
|
-
Requires-Dist: ipykernel>=6.9.0; extra == "docs"
|
|
60
|
-
Requires-Dist: mike>=0.5.3; extra == "docs"
|
|
61
|
-
Requires-Dist: mkdocs>=1.2.3; extra == "docs"
|
|
62
|
-
Requires-Dist: mkdocs-awesome-pages-plugin>=2.7.0; extra == "docs"
|
|
63
|
-
Requires-Dist: mkdocs-gen-files>=0.3.5; extra == "docs"
|
|
64
|
-
Requires-Dist: mkdocs-charts-plugin>=0.0.8; extra == "docs"
|
|
65
|
-
Requires-Dist: mkdocs-literate-nav>=0.4.1; extra == "docs"
|
|
66
|
-
Requires-Dist: mkdocs-material>=8.1.11; extra == "docs"
|
|
67
|
-
Requires-Dist: mkdocstrings[python]>=0.19.0; extra == "docs"
|
|
68
|
-
Requires-Dist: pytkdocs[numpy-style]>=0.5.0; extra == "docs"
|
|
69
|
-
Requires-Dist: ipython_genutils>=0.1.0; extra == "docs"
|
|
70
|
-
Requires-Dist: mkdocs-jupyter>=0.20.0; extra == "docs"
|
|
71
|
-
Requires-Dist: nbconvert>=6.4.2; extra == "docs"
|
|
72
|
-
Requires-Dist: numpydoc>=1.2; extra == "docs"
|
|
73
|
-
Requires-Dist: spacy>=3.2.2; extra == "docs"
|
|
74
|
-
Requires-Dist: jinja2>=3.0.3; extra == "docs"
|
|
75
|
-
Requires-Dist: dominate; extra == "docs"
|
|
76
|
-
Requires-Dist: jupyter-client; extra == "docs"
|
|
77
|
-
Requires-Dist: mkdocs-charts-plugin; extra == "docs"
|
|
78
|
-
Requires-Dist: python-slugify; extra == "docs"
|
|
79
|
-
Requires-Dist: watermark==2.3.1; extra == "docs"
|
|
80
|
-
Provides-Extra: all
|
|
81
|
-
Requires-Dist: graphviz>=0.10.1; extra == "all"
|
|
82
|
-
Requires-Dist: matplotlib>=3.0.2; extra == "all"
|
|
83
|
-
Requires-Dist: mypy>=0.990; extra == "all"
|
|
84
|
-
Requires-Dist: pre-commit>=2.20.0; extra == "all"
|
|
85
|
-
Requires-Dist: pytest>=7.2.0; extra == "all"
|
|
86
|
-
Requires-Dist: pytest-cov>=4.0.0; extra == "all"
|
|
87
|
-
Requires-Dist: scikit-learn>=0.22.1; extra == "all"
|
|
88
|
-
Requires-Dist: black>=22.10.0; extra == "all"
|
|
89
|
-
Requires-Dist: flake8>=5.0.4; extra == "all"
|
|
90
|
-
Requires-Dist: isort>=5.10.1; extra == "all"
|
|
91
|
-
Requires-Dist: jupyter>=1.0.0; extra == "all"
|
|
92
|
-
Requires-Dist: pyupgrade==3.2.0; extra == "all"
|
|
93
|
-
Requires-Dist: flask>=2.0.2; extra == "all"
|
|
94
|
-
Requires-Dist: ipykernel>=6.9.0; extra == "all"
|
|
95
|
-
Requires-Dist: mike>=0.5.3; extra == "all"
|
|
96
|
-
Requires-Dist: mkdocs>=1.2.3; extra == "all"
|
|
97
|
-
Requires-Dist: mkdocs-awesome-pages-plugin>=2.7.0; extra == "all"
|
|
98
|
-
Requires-Dist: mkdocs-gen-files>=0.3.5; extra == "all"
|
|
99
|
-
Requires-Dist: mkdocs-charts-plugin>=0.0.8; extra == "all"
|
|
100
|
-
Requires-Dist: mkdocs-literate-nav>=0.4.1; extra == "all"
|
|
101
|
-
Requires-Dist: mkdocs-material>=8.1.11; extra == "all"
|
|
102
|
-
Requires-Dist: mkdocstrings[python]>=0.19.0; extra == "all"
|
|
103
|
-
Requires-Dist: pytkdocs[numpy-style]>=0.5.0; extra == "all"
|
|
104
|
-
Requires-Dist: ipython_genutils>=0.1.0; extra == "all"
|
|
105
|
-
Requires-Dist: mkdocs-jupyter>=0.20.0; extra == "all"
|
|
106
|
-
Requires-Dist: nbconvert>=6.4.2; extra == "all"
|
|
107
|
-
Requires-Dist: numpydoc>=1.2; extra == "all"
|
|
108
|
-
Requires-Dist: spacy>=3.2.2; extra == "all"
|
|
109
|
-
Requires-Dist: jinja2>=3.0.3; extra == "all"
|
|
110
|
-
Requires-Dist: dominate; extra == "all"
|
|
111
|
-
Requires-Dist: jupyter-client; extra == "all"
|
|
112
|
-
Requires-Dist: mkdocs-charts-plugin; extra == "all"
|
|
113
|
-
Requires-Dist: python-slugify; extra == "all"
|
|
114
|
-
Requires-Dist: watermark==2.3.1; extra == "all"
|
|
115
|
-
Requires-Dist: dataclasses; python_version == "3.6"
|
|
116
|
-
|
|
117
32
|
|
|
118
33
|
<p align="center">
|
|
119
34
|
<img height="150px" src="https://raw.githubusercontent.com/online-ml/deep-river/master/docs/img/logo.png" alt="incremental dl logo">
|
|
@@ -123,8 +38,10 @@ Requires-Dist: dataclasses; python_version == "3.6"
|
|
|
123
38
|
<a href="https://codecov.io/gh/online-ml/deep-river" >
|
|
124
39
|
<img src="https://codecov.io/gh/online-ml/deep-river/branch/master/graph/badge.svg?token=ZKUIISZAYA"/>
|
|
125
40
|
</a>
|
|
41
|
+
<img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/deep-river">
|
|
126
42
|
<img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dm/deep-river">
|
|
127
43
|
<img alt="GitHub" src="https://img.shields.io/github/license/online-ml/deep-river">
|
|
44
|
+
<a href="https://joss.theoj.org/papers/6a76784f55e8b041d71a7fa776eb386a"><img src="https://joss.theoj.org/papers/6a76784f55e8b041d71a7fa776eb386a/status.svg"></a>
|
|
128
45
|
</p>
|
|
129
46
|
<p align="center">
|
|
130
47
|
deep-river is a Python library for online deep learning.
|
|
@@ -133,7 +50,9 @@ Requires-Dist: dataclasses; python_version == "3.6"
|
|
|
133
50
|
</p>
|
|
134
51
|
|
|
135
52
|
## 📚 [Documentation](https://online-ml.github.io/deep-river/)
|
|
136
|
-
The [documentation](https://online-ml.github.io/deep-river/) contains an overview of all features of this repository as well as the repository's full features list.
|
|
53
|
+
The [documentation](https://online-ml.github.io/deep-river/) contains an overview of all features of this repository as well as the repository's full features list.
|
|
54
|
+
In each of these, the git repo reference is listed in a section that shows [examples](https://github.com/online-ml/deep-river/blob/master/docs/examples) of the features and functionality.
|
|
55
|
+
As we are always looking for further use cases and examples, feel free to contribute to the documentation or the repository itself via a pull request
|
|
137
56
|
|
|
138
57
|
## 💈 Installation
|
|
139
58
|
|
|
@@ -194,7 +113,7 @@ For further examples check out the <a href="https://online-ml.github.io/deep-riv
|
|
|
194
113
|
... metric.update(y, y_pred) # update the metric
|
|
195
114
|
... model_pipeline.learn_one(x, y) # make the model learn
|
|
196
115
|
>>> print(f"Accuracy: {metric.get():.4f}")
|
|
197
|
-
Accuracy: 0.
|
|
116
|
+
Accuracy: 0.7264
|
|
198
117
|
|
|
199
118
|
```
|
|
200
119
|
### Multi Target Regression
|
|
@@ -248,7 +167,7 @@ MicroAverage(MAE): 34.31
|
|
|
248
167
|
>>> from river.preprocessing import MinMaxScaler
|
|
249
168
|
|
|
250
169
|
>>> dataset = CreditCard().take(5000)
|
|
251
|
-
>>> metric = metrics.
|
|
170
|
+
>>> metric = metrics.RollingROCAUC(window_size=5000)
|
|
252
171
|
|
|
253
172
|
>>> class MyAutoEncoder(nn.Module):
|
|
254
173
|
... def __init__(self, n_features, latent_dim=3):
|
|
@@ -273,8 +192,8 @@ MicroAverage(MAE): 34.31
|
|
|
273
192
|
... model.learn_one(x=x)
|
|
274
193
|
... metric.update(y, score)
|
|
275
194
|
...
|
|
276
|
-
>>> print(f"ROCAUC: {metric.get():.4f}")
|
|
277
|
-
ROCAUC: 0.
|
|
195
|
+
>>> print(f"Rolling ROCAUC: {metric.get():.4f}")
|
|
196
|
+
Rolling ROCAUC: 0.8901
|
|
278
197
|
|
|
279
198
|
```
|
|
280
199
|
|
|
@@ -287,3 +206,4 @@ ROCAUC: 0.9017
|
|
|
287
206
|
<p align="center">
|
|
288
207
|
<img src="https://lieferbotnet.de/wp-content/uploads/2022/09/LieferBotNet-Logo.png?raw=true" alt="Lieferbot net" height="200"/>
|
|
289
208
|
</p>
|
|
209
|
+
|
|
@@ -6,8 +6,10 @@
|
|
|
6
6
|
<a href="https://codecov.io/gh/online-ml/deep-river" >
|
|
7
7
|
<img src="https://codecov.io/gh/online-ml/deep-river/branch/master/graph/badge.svg?token=ZKUIISZAYA"/>
|
|
8
8
|
</a>
|
|
9
|
+
<img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/deep-river">
|
|
9
10
|
<img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dm/deep-river">
|
|
10
11
|
<img alt="GitHub" src="https://img.shields.io/github/license/online-ml/deep-river">
|
|
12
|
+
<a href="https://joss.theoj.org/papers/6a76784f55e8b041d71a7fa776eb386a"><img src="https://joss.theoj.org/papers/6a76784f55e8b041d71a7fa776eb386a/status.svg"></a>
|
|
11
13
|
</p>
|
|
12
14
|
<p align="center">
|
|
13
15
|
deep-river is a Python library for online deep learning.
|
|
@@ -16,7 +18,9 @@
|
|
|
16
18
|
</p>
|
|
17
19
|
|
|
18
20
|
## 📚 [Documentation](https://online-ml.github.io/deep-river/)
|
|
19
|
-
The [documentation](https://online-ml.github.io/deep-river/) contains an overview of all features of this repository as well as the repository's full features list.
|
|
21
|
+
The [documentation](https://online-ml.github.io/deep-river/) contains an overview of all features of this repository as well as the repository's full features list.
|
|
22
|
+
In each of these, the git repo reference is listed in a section that shows [examples](https://github.com/online-ml/deep-river/blob/master/docs/examples) of the features and functionality.
|
|
23
|
+
As we are always looking for further use cases and examples, feel free to contribute to the documentation or the repository itself via a pull request
|
|
20
24
|
|
|
21
25
|
## 💈 Installation
|
|
22
26
|
|
|
@@ -77,7 +81,7 @@ For further examples check out the <a href="https://online-ml.github.io/deep-riv
|
|
|
77
81
|
... metric.update(y, y_pred) # update the metric
|
|
78
82
|
... model_pipeline.learn_one(x, y) # make the model learn
|
|
79
83
|
>>> print(f"Accuracy: {metric.get():.4f}")
|
|
80
|
-
Accuracy: 0.
|
|
84
|
+
Accuracy: 0.7264
|
|
81
85
|
|
|
82
86
|
```
|
|
83
87
|
### Multi Target Regression
|
|
@@ -131,7 +135,7 @@ MicroAverage(MAE): 34.31
|
|
|
131
135
|
>>> from river.preprocessing import MinMaxScaler
|
|
132
136
|
|
|
133
137
|
>>> dataset = CreditCard().take(5000)
|
|
134
|
-
>>> metric = metrics.
|
|
138
|
+
>>> metric = metrics.RollingROCAUC(window_size=5000)
|
|
135
139
|
|
|
136
140
|
>>> class MyAutoEncoder(nn.Module):
|
|
137
141
|
... def __init__(self, n_features, latent_dim=3):
|
|
@@ -156,8 +160,8 @@ MicroAverage(MAE): 34.31
|
|
|
156
160
|
... model.learn_one(x=x)
|
|
157
161
|
... metric.update(y, score)
|
|
158
162
|
...
|
|
159
|
-
>>> print(f"ROCAUC: {metric.get():.4f}")
|
|
160
|
-
ROCAUC: 0.
|
|
163
|
+
>>> print(f"Rolling ROCAUC: {metric.get():.4f}")
|
|
164
|
+
Rolling ROCAUC: 0.8901
|
|
161
165
|
|
|
162
166
|
```
|
|
163
167
|
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
from .ae import Autoencoder
|
|
2
2
|
from .probability_weighted_ae import ProbabilityWeightedAutoencoder
|
|
3
3
|
from .rolling_ae import RollingAutoencoder
|
|
4
|
-
from .scaler import
|
|
5
|
-
AnomalyMeanScaler,
|
|
6
|
-
AnomalyMinMaxScaler,
|
|
7
|
-
AnomalyStandardScaler,
|
|
8
|
-
)
|
|
4
|
+
from .scaler import AnomalyMeanScaler, AnomalyMinMaxScaler, AnomalyStandardScaler
|
|
9
5
|
|
|
10
6
|
"""
|
|
11
7
|
This module contains the anomaly detection algorithms for the
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Any, Callable, Type, Union
|
|
1
|
+
from typing import Any, Callable, Dict, Type, Union
|
|
2
2
|
|
|
3
3
|
import numpy as np
|
|
4
4
|
import pandas as pd
|
|
@@ -8,6 +8,7 @@ from torch import nn
|
|
|
8
8
|
|
|
9
9
|
from deep_river.base import DeepEstimator
|
|
10
10
|
from deep_river.utils import dict2tensor
|
|
11
|
+
from deep_river.utils.layer_adaptation import expand_layer
|
|
11
12
|
from deep_river.utils.tensor_conversion import df2tensor
|
|
12
13
|
|
|
13
14
|
|
|
@@ -67,7 +68,7 @@ class Autoencoder(DeepEstimator, AnomalyDetector):
|
|
|
67
68
|
>>> from river.preprocessing import MinMaxScaler
|
|
68
69
|
|
|
69
70
|
>>> dataset = CreditCard().take(5000)
|
|
70
|
-
>>> metric = metrics.
|
|
71
|
+
>>> metric = metrics.RollingROCAUC(window_size=5000)
|
|
71
72
|
|
|
72
73
|
>>> class MyAutoEncoder(torch.nn.Module):
|
|
73
74
|
... def __init__(self, n_features, latent_dim=3):
|
|
@@ -92,8 +93,8 @@ class Autoencoder(DeepEstimator, AnomalyDetector):
|
|
|
92
93
|
... model.learn_one(x=x)
|
|
93
94
|
... metric.update(y, score)
|
|
94
95
|
...
|
|
95
|
-
>>> print(f"ROCAUC: {metric.get():.4f}")
|
|
96
|
-
ROCAUC: 0.
|
|
96
|
+
>>> print(f"Rolling ROCAUC: {metric.get():.4f}")
|
|
97
|
+
Rolling ROCAUC: 0.8901
|
|
97
98
|
"""
|
|
98
99
|
|
|
99
100
|
def __init__(
|
|
@@ -102,6 +103,7 @@ class Autoencoder(DeepEstimator, AnomalyDetector):
|
|
|
102
103
|
loss_fn: Union[str, Callable] = "mse",
|
|
103
104
|
optimizer_fn: Union[str, Callable] = "sgd",
|
|
104
105
|
lr: float = 1e-3,
|
|
106
|
+
is_feature_incremental: bool = False,
|
|
105
107
|
device: str = "cpu",
|
|
106
108
|
seed: int = 42,
|
|
107
109
|
**kwargs,
|
|
@@ -111,10 +113,12 @@ class Autoencoder(DeepEstimator, AnomalyDetector):
|
|
|
111
113
|
loss_fn=loss_fn,
|
|
112
114
|
optimizer_fn=optimizer_fn,
|
|
113
115
|
lr=lr,
|
|
116
|
+
is_feature_incremental=is_feature_incremental,
|
|
114
117
|
device=device,
|
|
115
118
|
seed=seed,
|
|
116
119
|
**kwargs,
|
|
117
120
|
)
|
|
121
|
+
self.is_class_incremental = is_feature_incremental
|
|
118
122
|
|
|
119
123
|
@classmethod
|
|
120
124
|
def _unit_test_params(cls):
|
|
@@ -133,6 +137,7 @@ class Autoencoder(DeepEstimator, AnomalyDetector):
|
|
|
133
137
|
"module": _TestAutoencoder,
|
|
134
138
|
"loss_fn": "mse",
|
|
135
139
|
"optimizer_fn": "sgd",
|
|
140
|
+
"is_feature_incremental": True,
|
|
136
141
|
}
|
|
137
142
|
|
|
138
143
|
@classmethod
|
|
@@ -148,13 +153,7 @@ class Autoencoder(DeepEstimator, AnomalyDetector):
|
|
|
148
153
|
set
|
|
149
154
|
Set of checks to skip during unit testing.
|
|
150
155
|
"""
|
|
151
|
-
return
|
|
152
|
-
"check_shuffle_features_no_impact",
|
|
153
|
-
"check_emerging_features",
|
|
154
|
-
"check_disappearing_features",
|
|
155
|
-
"check_predict_proba_one",
|
|
156
|
-
"check_predict_proba_one_binary",
|
|
157
|
-
}
|
|
156
|
+
return set()
|
|
158
157
|
|
|
159
158
|
def learn_one(self, x: dict, y: Any = None, **kwargs) -> "Autoencoder":
|
|
160
159
|
"""
|
|
@@ -173,14 +172,17 @@ class Autoencoder(DeepEstimator, AnomalyDetector):
|
|
|
173
172
|
The model itself.
|
|
174
173
|
"""
|
|
175
174
|
if not self.module_initialized:
|
|
176
|
-
self.
|
|
177
|
-
self.initialize_module(**self.kwargs)
|
|
178
|
-
|
|
175
|
+
self._update_observed_features(x)
|
|
176
|
+
self.initialize_module(x=x, **self.kwargs)
|
|
177
|
+
self._adapt_input_dim(x)
|
|
178
|
+
return self._learn(
|
|
179
|
+
dict2tensor(x, features=self.observed_features, device=self.device)
|
|
180
|
+
)
|
|
179
181
|
|
|
180
182
|
def _learn(self, x: torch.Tensor) -> "Autoencoder":
|
|
181
183
|
self.module.train()
|
|
182
184
|
x_pred = self.module(x)
|
|
183
|
-
loss = self.
|
|
185
|
+
loss = self.loss_func(x_pred, x)
|
|
184
186
|
loss.backward()
|
|
185
187
|
self.optimizer.step()
|
|
186
188
|
self.optimizer.zero_grad()
|
|
@@ -205,14 +207,16 @@ class Autoencoder(DeepEstimator, AnomalyDetector):
|
|
|
205
207
|
"""
|
|
206
208
|
|
|
207
209
|
if not self.module_initialized:
|
|
208
|
-
self.
|
|
209
|
-
self.initialize_module(**self.kwargs)
|
|
210
|
+
self._update_observed_features(x)
|
|
211
|
+
self.initialize_module(x=x, **self.kwargs)
|
|
210
212
|
|
|
211
|
-
|
|
213
|
+
self._adapt_input_dim(x)
|
|
214
|
+
|
|
215
|
+
x_t = dict2tensor(x, features=self.observed_features, device=self.device)
|
|
212
216
|
self.module.eval()
|
|
213
217
|
with torch.inference_mode():
|
|
214
218
|
x_pred = self.module(x_t)
|
|
215
|
-
loss = self.
|
|
219
|
+
loss = self.loss_func(x_pred, x_t).item()
|
|
216
220
|
return loss
|
|
217
221
|
|
|
218
222
|
def learn_many(self, X: pd.DataFrame) -> "Autoencoder":
|
|
@@ -231,10 +235,13 @@ class Autoencoder(DeepEstimator, AnomalyDetector):
|
|
|
231
235
|
|
|
232
236
|
"""
|
|
233
237
|
if not self.module_initialized:
|
|
234
|
-
|
|
235
|
-
self.
|
|
236
|
-
|
|
237
|
-
|
|
238
|
+
|
|
239
|
+
self._update_observed_features(X)
|
|
240
|
+
self.initialize_module(x=X, **self.kwargs)
|
|
241
|
+
|
|
242
|
+
self._adapt_input_dim(X)
|
|
243
|
+
X_t = df2tensor(X, features=self.observed_features, device=self.device)
|
|
244
|
+
return self._learn(X_t)
|
|
238
245
|
|
|
239
246
|
def score_many(self, X: pd.DataFrame) -> np.ndarray:
|
|
240
247
|
"""
|
|
@@ -253,16 +260,35 @@ class Autoencoder(DeepEstimator, AnomalyDetector):
|
|
|
253
260
|
indicate more anomalous examples.
|
|
254
261
|
"""
|
|
255
262
|
if not self.module_initialized:
|
|
256
|
-
self.
|
|
257
|
-
self.initialize_module(**self.kwargs)
|
|
258
|
-
|
|
263
|
+
self._update_observed_features(X)
|
|
264
|
+
self.initialize_module(x=X, **self.kwargs)
|
|
265
|
+
|
|
266
|
+
self._adapt_input_dim(X)
|
|
267
|
+
X_t = df2tensor(X, features=self.observed_features, device=self.device)
|
|
259
268
|
|
|
260
269
|
self.module.eval()
|
|
261
270
|
with torch.inference_mode():
|
|
262
|
-
X_pred = self.module(
|
|
271
|
+
X_pred = self.module(X_t)
|
|
263
272
|
loss = torch.mean(
|
|
264
|
-
self.
|
|
265
|
-
dim=list(range(1,
|
|
273
|
+
self.loss_func(X_pred, X_t, reduction="none"),
|
|
274
|
+
dim=list(range(1, X_t.dim())),
|
|
266
275
|
)
|
|
267
276
|
score = loss.cpu().detach().numpy()
|
|
268
277
|
return score
|
|
278
|
+
|
|
279
|
+
def _adapt_input_dim(self, x: Dict | pd.DataFrame):
|
|
280
|
+
has_new_feature = self._update_observed_features(x)
|
|
281
|
+
|
|
282
|
+
if has_new_feature and self.is_feature_incremental:
|
|
283
|
+
expand_layer(
|
|
284
|
+
self.input_layer,
|
|
285
|
+
self.input_expansion_instructions,
|
|
286
|
+
len(self.observed_features),
|
|
287
|
+
output=False,
|
|
288
|
+
)
|
|
289
|
+
expand_layer(
|
|
290
|
+
self.output_layer,
|
|
291
|
+
self.output_expansion_instructions,
|
|
292
|
+
len(self.observed_features),
|
|
293
|
+
output=True,
|
|
294
|
+
)
|
|
@@ -8,6 +8,7 @@ from scipy.special import ndtr
|
|
|
8
8
|
|
|
9
9
|
from deep_river.anomaly import ae
|
|
10
10
|
from deep_river.utils import dict2tensor
|
|
11
|
+
from deep_river.utils.tensor_conversion import df2tensor
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
class ProbabilityWeightedAutoencoder(ae.Autoencoder):
|
|
@@ -61,7 +62,7 @@ class ProbabilityWeightedAutoencoder(ae.Autoencoder):
|
|
|
61
62
|
|
|
62
63
|
>>> _ = manual_seed(42)
|
|
63
64
|
>>> dataset = CreditCard().take(5000)
|
|
64
|
-
>>> metric = metrics.
|
|
65
|
+
>>> metric = metrics.RollingROCAUC(window_size=5000)
|
|
65
66
|
|
|
66
67
|
>>> class MyAutoEncoder(torch.nn.Module):
|
|
67
68
|
... def __init__(self, n_features, latent_dim=3):
|
|
@@ -86,8 +87,8 @@ class ProbabilityWeightedAutoencoder(ae.Autoencoder):
|
|
|
86
87
|
... model.learn_one(x=x)
|
|
87
88
|
... metric.update(y, score)
|
|
88
89
|
...
|
|
89
|
-
>>> print(f"ROCAUC: {metric.get():.4f}")
|
|
90
|
-
ROCAUC: 0.
|
|
90
|
+
>>> print(f"Rolling ROCAUC: {metric.get():.4f}")
|
|
91
|
+
Rolling ROCAUC: 0.8530
|
|
91
92
|
"""
|
|
92
93
|
|
|
93
94
|
def __init__(
|
|
@@ -113,9 +114,7 @@ class ProbabilityWeightedAutoencoder(ae.Autoencoder):
|
|
|
113
114
|
)
|
|
114
115
|
self.window_size = window_size
|
|
115
116
|
self.skip_threshold = skip_threshold
|
|
116
|
-
self.rolling_mean = utils.Rolling(
|
|
117
|
-
stats.Mean(), window_size=window_size
|
|
118
|
-
)
|
|
117
|
+
self.rolling_mean = utils.Rolling(stats.Mean(), window_size=window_size)
|
|
119
118
|
self.rolling_var = utils.Rolling(stats.Var(), window_size=window_size)
|
|
120
119
|
|
|
121
120
|
def learn_one(
|
|
@@ -138,13 +137,15 @@ class ProbabilityWeightedAutoencoder(ae.Autoencoder):
|
|
|
138
137
|
The autoencoder itself.
|
|
139
138
|
"""
|
|
140
139
|
if not self.module_initialized:
|
|
141
|
-
self.
|
|
142
|
-
self.initialize_module(**self.kwargs)
|
|
143
|
-
|
|
140
|
+
self._update_observed_features(x)
|
|
141
|
+
self.initialize_module(x=x, **self.kwargs)
|
|
142
|
+
|
|
143
|
+
self._adapt_input_dim(x)
|
|
144
|
+
x_t = dict2tensor(x, self.observed_features, device=self.device)
|
|
144
145
|
|
|
145
146
|
self.module.train()
|
|
146
147
|
x_pred = self.module(x_t)
|
|
147
|
-
loss = self.
|
|
148
|
+
loss = self.loss_func(x_pred, x_t)
|
|
148
149
|
self._apply_loss(loss)
|
|
149
150
|
return self
|
|
150
151
|
|
|
@@ -162,10 +163,7 @@ class ProbabilityWeightedAutoencoder(ae.Autoencoder):
|
|
|
162
163
|
|
|
163
164
|
loss_scaled = (losses_numpy - mean) / math.sqrt(var)
|
|
164
165
|
prob = ndtr(loss_scaled)
|
|
165
|
-
loss = (
|
|
166
|
-
torch.tensor((self.skip_threshold - prob) / self.skip_threshold)
|
|
167
|
-
* loss
|
|
168
|
-
)
|
|
166
|
+
loss = torch.tensor((self.skip_threshold - prob) / self.skip_threshold) * loss
|
|
169
167
|
|
|
170
168
|
self.optimizer.zero_grad()
|
|
171
169
|
loss.backward()
|
|
@@ -173,15 +171,16 @@ class ProbabilityWeightedAutoencoder(ae.Autoencoder):
|
|
|
173
171
|
|
|
174
172
|
def learn_many(self, X: pd.DataFrame) -> "ProbabilityWeightedAutoencoder":
|
|
175
173
|
if not self.module_initialized:
|
|
176
|
-
self.
|
|
177
|
-
self.initialize_module(**self.kwargs)
|
|
178
|
-
|
|
174
|
+
self._update_observed_features(X)
|
|
175
|
+
self.initialize_module(x=X, **self.kwargs)
|
|
176
|
+
self._adapt_input_dim(X)
|
|
177
|
+
X_t = df2tensor(X, features=self.observed_features, device=self.device)
|
|
179
178
|
|
|
180
179
|
self.module.train()
|
|
181
180
|
x_pred = self.module(X)
|
|
182
181
|
loss = torch.mean(
|
|
183
|
-
self.
|
|
184
|
-
dim=list(range(1,
|
|
182
|
+
self.loss_func(x_pred, X_t, reduction="none"),
|
|
183
|
+
dim=list(range(1, X_t.dim())),
|
|
185
184
|
)
|
|
186
185
|
self._apply_loss(loss)
|
|
187
186
|
return self
|
|
@@ -11,9 +11,7 @@ from deep_river.utils.tensor_conversion import deque2rolling_tensor
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class _TestLSTMAutoencoder(nn.Module):
|
|
14
|
-
def __init__(
|
|
15
|
-
self, n_features, hidden_size=30, n_layers=1, batch_first=False
|
|
16
|
-
):
|
|
14
|
+
def __init__(self, n_features, hidden_size=30, n_layers=1, batch_first=False):
|
|
17
15
|
super().__init__()
|
|
18
16
|
self.n_features = n_features
|
|
19
17
|
self.hidden_size = hidden_size
|
|
@@ -26,20 +24,10 @@ class _TestLSTMAutoencoder(nn.Module):
|
|
|
26
24
|
num_layers=n_layers,
|
|
27
25
|
batch_first=batch_first,
|
|
28
26
|
)
|
|
29
|
-
self.decoder = nn.LSTM(
|
|
30
|
-
input_size=hidden_size,
|
|
31
|
-
hidden_size=n_features,
|
|
32
|
-
num_layers=n_layers,
|
|
33
|
-
batch_first=batch_first,
|
|
34
|
-
)
|
|
35
27
|
|
|
36
28
|
def forward(self, x):
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
x_flipped = torch.flip(x[1:], dims=[self.time_axis])
|
|
40
|
-
input = torch.cat((h, x_flipped), dim=self.time_axis)
|
|
41
|
-
x_hat, _ = self.decoder(input)
|
|
42
|
-
return torch.flip(x_hat, dims=[self.time_axis])
|
|
29
|
+
output, (h, c) = self.encoder(x)
|
|
30
|
+
return output
|
|
43
31
|
|
|
44
32
|
|
|
45
33
|
class RollingAutoencoder(RollingDeepEstimator, anomaly.base.AnomalyDetector):
|
|
@@ -146,15 +134,13 @@ class RollingAutoencoder(RollingDeepEstimator, anomaly.base.AnomalyDetector):
|
|
|
146
134
|
def _learn(self, x: torch.Tensor):
|
|
147
135
|
self.module.train()
|
|
148
136
|
x_pred = self.module(x)
|
|
149
|
-
loss = self.
|
|
137
|
+
loss = self.loss_func(x_pred, x)
|
|
150
138
|
|
|
151
139
|
self.optimizer.zero_grad()
|
|
152
140
|
loss.backward()
|
|
153
141
|
self.optimizer.step()
|
|
154
142
|
|
|
155
|
-
def learn_one(
|
|
156
|
-
self, x: dict, y: Any = None, **kwargs
|
|
157
|
-
) -> "RollingAutoencoder":
|
|
143
|
+
def learn_one(self, x: dict, y: Any = None, **kwargs) -> "RollingAutoencoder":
|
|
158
144
|
"""
|
|
159
145
|
Performs one step of training with a single example.
|
|
160
146
|
|
|
@@ -169,8 +155,8 @@ class RollingAutoencoder(RollingDeepEstimator, anomaly.base.AnomalyDetector):
|
|
|
169
155
|
The estimator itself.
|
|
170
156
|
"""
|
|
171
157
|
if not self.module_initialized:
|
|
172
|
-
self.
|
|
173
|
-
self.initialize_module(**self.kwargs)
|
|
158
|
+
self._update_observed_features(x)
|
|
159
|
+
self.initialize_module(x=x, **self.kwargs)
|
|
174
160
|
|
|
175
161
|
self._x_window.append(list(x.values()))
|
|
176
162
|
|
|
@@ -197,8 +183,8 @@ class RollingAutoencoder(RollingDeepEstimator, anomaly.base.AnomalyDetector):
|
|
|
197
183
|
The estimator itself.
|
|
198
184
|
"""
|
|
199
185
|
if not self.module_initialized:
|
|
200
|
-
self.
|
|
201
|
-
self.initialize_module(**self.kwargs)
|
|
186
|
+
self._update_observed_features(X)
|
|
187
|
+
self.initialize_module(x=X, **self.kwargs)
|
|
202
188
|
|
|
203
189
|
self._x_window.append(X.values.tolist())
|
|
204
190
|
if len(self._x_window) == self.window_size:
|
|
@@ -209,8 +195,10 @@ class RollingAutoencoder(RollingDeepEstimator, anomaly.base.AnomalyDetector):
|
|
|
209
195
|
def score_one(self, x: dict) -> float:
|
|
210
196
|
res = 0.0
|
|
211
197
|
if not self.module_initialized:
|
|
212
|
-
|
|
213
|
-
self.
|
|
198
|
+
|
|
199
|
+
self._update_observed_features(x)
|
|
200
|
+
|
|
201
|
+
self.initialize_module(x=x, **self.kwargs)
|
|
214
202
|
|
|
215
203
|
if len(self._x_window) == self.window_size:
|
|
216
204
|
x_win = self._x_window.copy()
|
|
@@ -219,7 +207,7 @@ class RollingAutoencoder(RollingDeepEstimator, anomaly.base.AnomalyDetector):
|
|
|
219
207
|
self.module.eval()
|
|
220
208
|
with torch.inference_mode():
|
|
221
209
|
x_pred = self.module(x_t)
|
|
222
|
-
loss = self.
|
|
210
|
+
loss = self.loss_func(x_pred, x_t)
|
|
223
211
|
res = loss.item()
|
|
224
212
|
|
|
225
213
|
if self.append_predict:
|
|
@@ -228,8 +216,9 @@ class RollingAutoencoder(RollingDeepEstimator, anomaly.base.AnomalyDetector):
|
|
|
228
216
|
|
|
229
217
|
def score_many(self, X: pd.DataFrame) -> List[Any]:
|
|
230
218
|
if not self.module_initialized:
|
|
231
|
-
|
|
232
|
-
self.
|
|
219
|
+
|
|
220
|
+
self._update_observed_features(X)
|
|
221
|
+
self.initialize_module(x=X, **self.kwargs)
|
|
233
222
|
|
|
234
223
|
x_win = self._x_window.copy()
|
|
235
224
|
x_win.append(X.values.tolist())
|
|
@@ -242,7 +231,7 @@ class RollingAutoencoder(RollingDeepEstimator, anomaly.base.AnomalyDetector):
|
|
|
242
231
|
with torch.inference_mode():
|
|
243
232
|
x_pred = self.module(X_t)
|
|
244
233
|
loss = torch.mean(
|
|
245
|
-
self.
|
|
234
|
+
self.loss_func(x_pred, x_pred, reduction="none"),
|
|
246
235
|
dim=list(range(1, x_pred.dim())),
|
|
247
236
|
)
|
|
248
237
|
losses = loss.detach().numpy()
|
|
@@ -145,9 +145,7 @@ class AnomalyStandardScaler(AnomalyScaler):
|
|
|
145
145
|
super().__init__(anomaly_detector)
|
|
146
146
|
self.rolling = rolling
|
|
147
147
|
self.window_size = window_size
|
|
148
|
-
self.mean = (
|
|
149
|
-
utils.Rolling(Mean(), self.window_size) if self.rolling else Mean()
|
|
150
|
-
)
|
|
148
|
+
self.mean = utils.Rolling(Mean(), self.window_size) if self.rolling else Mean()
|
|
151
149
|
self.sq_mean = (
|
|
152
150
|
utils.Rolling(Mean(), self.window_size) if self.rolling else Mean()
|
|
153
151
|
)
|
|
@@ -208,9 +206,7 @@ class AnomalyMeanScaler(AnomalyScaler):
|
|
|
208
206
|
super().__init__(anomaly_detector=anomaly_detector)
|
|
209
207
|
self.rolling = rolling
|
|
210
208
|
self.window_size = window_size
|
|
211
|
-
self.mean = (
|
|
212
|
-
utils.Rolling(Mean(), self.window_size) if self.rolling else Mean()
|
|
213
|
-
)
|
|
209
|
+
self.mean = utils.Rolling(Mean(), self.window_size) if self.rolling else Mean()
|
|
214
210
|
|
|
215
211
|
def score_one(self, *args):
|
|
216
212
|
"""
|