spacekit 1.1.3__tar.gz → 1.1.5__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.
- {spacekit-1.1.3 → spacekit-1.1.5}/LICENSE +1 -1
- {spacekit-1.1.3/spacekit.egg-info → spacekit-1.1.5}/PKG-INFO +9 -8
- {spacekit-1.1.3 → spacekit-1.1.5}/README.md +5 -5
- {spacekit-1.1.3 → spacekit-1.1.5}/pyproject.toml +1 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/setup.cfg +4 -3
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/analyzer/compute.py +106 -63
- spacekit-1.1.5/spacekit/analyzer/explore.py +1555 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/analyzer/scan.py +54 -74
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/analyzer/track.py +18 -12
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/analyzer/validate.py +26 -24
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/builder/architect.py +83 -119
- spacekit-1.1.5/spacekit/builder/blueprints.py +211 -0
- spacekit-1.1.5/spacekit/builder/trained_networks/jwst_cal.zip +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/dashboard/cal/__init__.py +1 -3
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/dashboard/cal/config.py +3 -11
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/dashboard/cal/eda.py +4 -10
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/dashboard/cal/eval.py +6 -17
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/dashboard/cal/index.py +16 -26
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/dashboard/cal/nodegraph.py +18 -29
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/dashboard/cal/pred.py +9 -16
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/dashboard/svm/config.py +3 -3
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/dashboard/svm/eda.py +8 -11
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/dashboard/svm/eval.py +5 -14
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/dashboard/svm/index.py +17 -21
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/dashboard/svm/pred.py +3 -8
- spacekit-1.1.5/spacekit/datasets/__init__.py +14 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/datasets/_base.py +6 -9
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/datasets/beam.py +12 -16
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/datasets/meta.py +8 -8
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/extractor/load.py +44 -55
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/extractor/radio.py +87 -101
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/extractor/scrape.py +112 -152
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/generator/augment.py +3 -6
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/generator/draw.py +35 -45
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/logger/log.py +26 -75
- spacekit-1.1.5/spacekit/preprocessor/__init__.py +4 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/preprocessor/encode.py +114 -102
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/preprocessor/ingest.py +173 -232
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/preprocessor/prep.py +69 -53
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/preprocessor/scrub.py +162 -179
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/preprocessor/transform.py +105 -123
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/skopes/hst/cal/predict.py +34 -41
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/skopes/hst/cal/train.py +60 -90
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/skopes/hst/cal/validate.py +11 -7
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/skopes/hst/svm/corrupt.py +17 -22
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/skopes/hst/svm/predict.py +17 -18
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/skopes/hst/svm/prep.py +4 -4
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/skopes/hst/svm/train.py +45 -48
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/skopes/jwst/cal/config.py +41 -41
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/skopes/jwst/cal/predict.py +56 -69
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/skopes/jwst/cal/train.py +83 -91
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/skopes/kepler/light_curves.py +14 -14
- {spacekit-1.1.3 → spacekit-1.1.5/spacekit.egg-info}/PKG-INFO +9 -8
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit.egg-info/requires.txt +1 -1
- spacekit-1.1.3/spacekit/analyzer/explore.py +0 -1199
- spacekit-1.1.3/spacekit/builder/blueprints.py +0 -211
- spacekit-1.1.3/spacekit/builder/trained_networks/jwst_cal.zip +0 -0
- spacekit-1.1.3/spacekit/datasets/__init__.py +0 -21
- spacekit-1.1.3/spacekit/preprocessor/__init__.py +0 -4
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/__init__.py +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/analyzer/__init__.py +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/builder/__init__.py +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/builder/trained_networks/__init__.py +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/builder/trained_networks/hst_cal.zip +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/builder/trained_networks/svm_align.zip +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/dashboard/__init__.py +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/dashboard/cal/app.py +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/dashboard/svm/__init__.py +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/dashboard/svm/app.py +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/extractor/__init__.py +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/generator/__init__.py +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/logger/__init__.py +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/skopes/__init__.py +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/skopes/hst/__init__.py +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/skopes/hst/cal/__init__.py +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/skopes/hst/cal/config.py +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/skopes/hst/svm/__init__.py +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/skopes/jwst/__init__.py +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/skopes/jwst/cal/__init__.py +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit/skopes/kepler/__init__.py +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit.egg-info/SOURCES.txt +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit.egg-info/dependency_links.txt +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit.egg-info/not-zip-safe +0 -0
- {spacekit-1.1.3 → spacekit-1.1.5}/spacekit.egg-info/top_level.txt +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: spacekit
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.5
|
|
4
4
|
Summary: Astronomical Data Science and Machine Learning Toolkit
|
|
5
5
|
Home-page: https://github.com/spacetelescope/spacekit
|
|
6
6
|
Author: Ru Keïn
|
|
7
7
|
Author-email: rkein@stsci.edu
|
|
8
8
|
License: MIT
|
|
9
9
|
Project-URL: Source, https://github.com/spacetelescope/spacekit
|
|
10
|
-
Project-URL: Documentation, https://spacekit.
|
|
10
|
+
Project-URL: Documentation, https://www.spacekit.org
|
|
11
11
|
Project-URL: Tracker, https://github.com/spacetelescope/spacekit/issues
|
|
12
12
|
Classifier: Intended Audience :: Science/Research
|
|
13
13
|
Classifier: Topic :: Scientific/Engineering :: Astronomy
|
|
@@ -17,13 +17,14 @@ Classifier: Operating System :: OS Independent
|
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.10
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.11
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
21
|
Requires-Python: >=3.10
|
|
21
22
|
Description-Content-Type: text/markdown
|
|
22
23
|
License-File: LICENSE
|
|
23
24
|
Requires-Dist: tensorflow>=2.16.1
|
|
24
25
|
Requires-Dist: astropy
|
|
25
26
|
Requires-Dist: boto3
|
|
26
|
-
Requires-Dist: numpy>=1.
|
|
27
|
+
Requires-Dist: numpy>=1.25
|
|
27
28
|
Requires-Dist: pandas
|
|
28
29
|
Requires-Dist: scikit-learn>=1.3.2
|
|
29
30
|
Provides-Extra: test
|
|
@@ -109,7 +110,7 @@ $ pytest --env jwstcal -m jwst
|
|
|
109
110
|
|
|
110
111
|
**JWST Calibration Pipeline Resource Prediction (JWST)**
|
|
111
112
|
|
|
112
|
-
[JWST CAL Docs](https://spacekit.
|
|
113
|
+
[JWST CAL Docs](https://www.spacekit.org/en/latest/skopes/jwst/cal/index.html)
|
|
113
114
|
|
|
114
115
|
* Inference ``spacekit.skopes.jwst.cal.predict``
|
|
115
116
|
|
|
@@ -143,7 +144,7 @@ $ python -m spacekit.skopes.jwst.cal.predict /path/to/inputs --pid 1076
|
|
|
143
144
|
|
|
144
145
|
**Single Visit Mosaic Alignment (HST)**
|
|
145
146
|
|
|
146
|
-
[SVM Docs](https://spacekit.
|
|
147
|
+
[SVM Docs](https://www.spacekit.org/en/latest/skopes/hst/svm/index.html)
|
|
147
148
|
|
|
148
149
|
* Preprocessing: ``spacekit.skopes.hst.svm.prep``
|
|
149
150
|
* Predict Image Alignments: ``spacekit.skopes.hst.svm.predict``
|
|
@@ -154,7 +155,7 @@ $ python -m spacekit.skopes.jwst.cal.predict /path/to/inputs --pid 1076
|
|
|
154
155
|
|
|
155
156
|
**HST Calibration Pipeline Resource Prediction (HST)**
|
|
156
157
|
|
|
157
|
-
[HST CAL Docs](https://spacekit.
|
|
158
|
+
[HST CAL Docs](https://www.spacekit.org/en/latest/skopes/hst/cal/index.html)
|
|
158
159
|
|
|
159
160
|
* Training ``spacekit.skopes.hst.cal.train``
|
|
160
161
|
* Inference ``spacekit.skopes.hst.cal.predict``
|
|
@@ -162,7 +163,7 @@ $ python -m spacekit.skopes.jwst.cal.predict /path/to/inputs --pid 1076
|
|
|
162
163
|
|
|
163
164
|
**Exoplanet Detection with time-series photometry (K2, TESS)**
|
|
164
165
|
|
|
165
|
-
[K2 Docs](https://spacekit.
|
|
166
|
+
[K2 Docs](https://www.spacekit.org/en/latest/skopes/kepler/light_curves.html)
|
|
166
167
|
|
|
167
168
|
* ``spacekit.skopes.kepler.light_curves``
|
|
168
169
|
|
|
@@ -184,7 +185,7 @@ ens.batch_fit()
|
|
|
184
185
|
|
|
185
186
|
# Save Training Metrics
|
|
186
187
|
outputs = f"data/{date_timestamp}"
|
|
187
|
-
com = ComputeBinary(builder=ens, res_path=f"{outputs}/results/test")
|
|
188
|
+
com = ComputeBinary(builder=ens, res_path=f"{outputs}/results/test", classes=["aligned", "misaligned"])
|
|
188
189
|
com.calculate_results()
|
|
189
190
|
```
|
|
190
191
|
# Load and plot metrics to evaluate and compare model performance
|
|
@@ -52,7 +52,7 @@ $ pytest --env jwstcal -m jwst
|
|
|
52
52
|
|
|
53
53
|
**JWST Calibration Pipeline Resource Prediction (JWST)**
|
|
54
54
|
|
|
55
|
-
[JWST CAL Docs](https://spacekit.
|
|
55
|
+
[JWST CAL Docs](https://www.spacekit.org/en/latest/skopes/jwst/cal/index.html)
|
|
56
56
|
|
|
57
57
|
* Inference ``spacekit.skopes.jwst.cal.predict``
|
|
58
58
|
|
|
@@ -86,7 +86,7 @@ $ python -m spacekit.skopes.jwst.cal.predict /path/to/inputs --pid 1076
|
|
|
86
86
|
|
|
87
87
|
**Single Visit Mosaic Alignment (HST)**
|
|
88
88
|
|
|
89
|
-
[SVM Docs](https://spacekit.
|
|
89
|
+
[SVM Docs](https://www.spacekit.org/en/latest/skopes/hst/svm/index.html)
|
|
90
90
|
|
|
91
91
|
* Preprocessing: ``spacekit.skopes.hst.svm.prep``
|
|
92
92
|
* Predict Image Alignments: ``spacekit.skopes.hst.svm.predict``
|
|
@@ -97,7 +97,7 @@ $ python -m spacekit.skopes.jwst.cal.predict /path/to/inputs --pid 1076
|
|
|
97
97
|
|
|
98
98
|
**HST Calibration Pipeline Resource Prediction (HST)**
|
|
99
99
|
|
|
100
|
-
[HST CAL Docs](https://spacekit.
|
|
100
|
+
[HST CAL Docs](https://www.spacekit.org/en/latest/skopes/hst/cal/index.html)
|
|
101
101
|
|
|
102
102
|
* Training ``spacekit.skopes.hst.cal.train``
|
|
103
103
|
* Inference ``spacekit.skopes.hst.cal.predict``
|
|
@@ -105,7 +105,7 @@ $ python -m spacekit.skopes.jwst.cal.predict /path/to/inputs --pid 1076
|
|
|
105
105
|
|
|
106
106
|
**Exoplanet Detection with time-series photometry (K2, TESS)**
|
|
107
107
|
|
|
108
|
-
[K2 Docs](https://spacekit.
|
|
108
|
+
[K2 Docs](https://www.spacekit.org/en/latest/skopes/kepler/light_curves.html)
|
|
109
109
|
|
|
110
110
|
* ``spacekit.skopes.kepler.light_curves``
|
|
111
111
|
|
|
@@ -127,7 +127,7 @@ ens.batch_fit()
|
|
|
127
127
|
|
|
128
128
|
# Save Training Metrics
|
|
129
129
|
outputs = f"data/{date_timestamp}"
|
|
130
|
-
com = ComputeBinary(builder=ens, res_path=f"{outputs}/results/test")
|
|
130
|
+
com = ComputeBinary(builder=ens, res_path=f"{outputs}/results/test", classes=["aligned", "misaligned"])
|
|
131
131
|
com.calculate_results()
|
|
132
132
|
```
|
|
133
133
|
# Load and plot metrics to evaluate and compare model performance
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[metadata]
|
|
2
2
|
name = spacekit
|
|
3
|
-
version = 1.1.
|
|
3
|
+
version = 1.1.5
|
|
4
4
|
author = Ru Keïn
|
|
5
5
|
author_email = rkein@stsci.edu
|
|
6
6
|
license = MIT
|
|
@@ -13,7 +13,7 @@ edit_on_github = False
|
|
|
13
13
|
github_project = spacetelescope/spacekit
|
|
14
14
|
project_urls =
|
|
15
15
|
Source = https://github.com/spacetelescope/spacekit
|
|
16
|
-
Documentation = https://spacekit.
|
|
16
|
+
Documentation = https://www.spacekit.org
|
|
17
17
|
Tracker = https://github.com/spacetelescope/spacekit/issues
|
|
18
18
|
classifiers =
|
|
19
19
|
Intended Audience :: Science/Research
|
|
@@ -24,6 +24,7 @@ classifiers =
|
|
|
24
24
|
Programming Language :: Python :: 3.10
|
|
25
25
|
Programming Language :: Python :: 3.11
|
|
26
26
|
Programming Language :: Python :: 3.12
|
|
27
|
+
Programming Language :: Python :: 3.13
|
|
27
28
|
|
|
28
29
|
[options]
|
|
29
30
|
zip_safe = False
|
|
@@ -36,7 +37,7 @@ install_requires =
|
|
|
36
37
|
tensorflow>=2.16.1
|
|
37
38
|
astropy
|
|
38
39
|
boto3
|
|
39
|
-
numpy>=1.
|
|
40
|
+
numpy>=1.25
|
|
40
41
|
pandas
|
|
41
42
|
scikit-learn>=1.3.2
|
|
42
43
|
|
|
@@ -1,26 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
import datetime as dt
|
|
2
2
|
import glob
|
|
3
3
|
import itertools
|
|
4
|
+
import os
|
|
5
|
+
|
|
4
6
|
import numpy as np
|
|
5
7
|
import pandas as pd
|
|
6
|
-
import datetime as dt
|
|
7
8
|
from sklearn.metrics import (
|
|
8
9
|
auc,
|
|
9
|
-
roc_curve,
|
|
10
|
-
roc_auc_score,
|
|
11
|
-
precision_recall_curve,
|
|
12
10
|
average_precision_score,
|
|
13
11
|
classification_report,
|
|
14
12
|
confusion_matrix,
|
|
13
|
+
precision_recall_curve,
|
|
14
|
+
roc_auc_score,
|
|
15
|
+
roc_curve,
|
|
15
16
|
)
|
|
16
17
|
from tensorflow.python.ops.numpy_ops import np_config
|
|
18
|
+
|
|
19
|
+
from spacekit.extractor.load import load_multitype_data, save_multitype_data
|
|
17
20
|
from spacekit.logger.log import Logger
|
|
18
|
-
from spacekit.extractor.load import save_multitype_data, load_multitype_data
|
|
19
21
|
|
|
20
22
|
try:
|
|
21
|
-
import plotly.graph_objects as go
|
|
22
23
|
import matplotlib as mpl
|
|
23
24
|
import matplotlib.pyplot as plt
|
|
25
|
+
import plotly.graph_objects as go
|
|
26
|
+
|
|
24
27
|
font_dict = {"family": "monospace", "size": 16} # Titillium Web
|
|
25
28
|
mpl.rc("font", **font_dict)
|
|
26
29
|
styles = ["seaborn-bright", "seaborn-v0_8-bright"]
|
|
@@ -40,7 +43,7 @@ def check_viz_imports():
|
|
|
40
43
|
return go is not None
|
|
41
44
|
|
|
42
45
|
|
|
43
|
-
class Computer
|
|
46
|
+
class Computer:
|
|
44
47
|
def __init__(
|
|
45
48
|
self,
|
|
46
49
|
algorithm,
|
|
@@ -149,7 +152,7 @@ class Computer(object):
|
|
|
149
152
|
self.y_test = builder.y_val
|
|
150
153
|
self.X_train = builder.X_test
|
|
151
154
|
self.y_train = builder.y_test
|
|
152
|
-
except
|
|
155
|
+
except AttributeError as e:
|
|
153
156
|
print(e)
|
|
154
157
|
print("Validation attributes not set.")
|
|
155
158
|
else:
|
|
@@ -174,8 +177,8 @@ class Computer(object):
|
|
|
174
177
|
Outputs created by their respective subclasses using the ``make_outputs`` method.
|
|
175
178
|
"""
|
|
176
179
|
if self.res_path is None:
|
|
177
|
-
timestamp = int(dt.datetime.now().timestamp())
|
|
178
|
-
datestamp = dt.
|
|
180
|
+
timestamp = int(dt.datetime.now(tz=dt.timezone.utc).timestamp())
|
|
181
|
+
datestamp = dt.datetime.fromtimestamp(timestamp, tz=dt.timezone.utc).date().isoformat()
|
|
179
182
|
prefix = str(datestamp) + "-" + str(timestamp)
|
|
180
183
|
self.res_path = os.path.join(os.getcwd(), prefix, "results", self.algorithm)
|
|
181
184
|
save_multitype_data(
|
|
@@ -201,7 +204,7 @@ class Computer(object):
|
|
|
201
204
|
if self.res_path is None:
|
|
202
205
|
try:
|
|
203
206
|
self.res_path = glob.glob(f"data/*/results/{self.algorithm}")[0]
|
|
204
|
-
except
|
|
207
|
+
except IndexError as e:
|
|
205
208
|
self.log.error(f"No results found @ {self.res_path} \n", e)
|
|
206
209
|
return outputs
|
|
207
210
|
if os.path.exists(self.res_path):
|
|
@@ -238,9 +241,7 @@ class Computer(object):
|
|
|
238
241
|
"""
|
|
239
242
|
self.y_scores = self.model.predict(self.X_test)
|
|
240
243
|
if self.y_scores.shape[1] < 2:
|
|
241
|
-
self.y_scores = np.concatenate(
|
|
242
|
-
[np.round(1 - self.y_scores), np.round(self.y_scores)], axis=1
|
|
243
|
-
)
|
|
244
|
+
self.y_scores = np.concatenate([np.round(1 - self.y_scores), np.round(self.y_scores)], axis=1)
|
|
244
245
|
return self.y_scores
|
|
245
246
|
|
|
246
247
|
def acc_loss_scores(self):
|
|
@@ -281,7 +282,6 @@ class Computer(object):
|
|
|
281
282
|
self.roc_fig = self.make_roc_curve()
|
|
282
283
|
self.pr_fig = self.make_pr_curve()
|
|
283
284
|
self.cm_fig, self.cmx_norm = self.fusion_matrix(self.cmx, self.classes)
|
|
284
|
-
return self
|
|
285
285
|
|
|
286
286
|
# Matplotlib "static" alternative to interactive plotly version
|
|
287
287
|
def roc_plots(self):
|
|
@@ -312,17 +312,11 @@ class Computer(object):
|
|
|
312
312
|
ax = axes[0]
|
|
313
313
|
ax.plot(thresholds, 1.0 - fpr)
|
|
314
314
|
ax.plot(thresholds, tpr)
|
|
315
|
-
ax.set_title(
|
|
316
|
-
"Crossover at {0:.2f}, Specificity {1:.2f}".format(
|
|
317
|
-
crossover_cutoff, crossover_specificity
|
|
318
|
-
)
|
|
319
|
-
)
|
|
315
|
+
ax.set_title(f"Crossover at {crossover_cutoff:.2f}, Specificity {crossover_specificity:.2f}")
|
|
320
316
|
|
|
321
317
|
ax = axes[1]
|
|
322
318
|
ax.plot(fpr, tpr)
|
|
323
|
-
ax.set_title(
|
|
324
|
-
"ROC area under curve: {0:.2f}".format(roc_auc_score(y_true, y_hat))
|
|
325
|
-
)
|
|
319
|
+
ax.set_title(f"ROC area under curve: {roc_auc_score(y_true, y_hat):.2f}")
|
|
326
320
|
if self.show:
|
|
327
321
|
fig.show()
|
|
328
322
|
|
|
@@ -337,7 +331,7 @@ class Computer(object):
|
|
|
337
331
|
ROC-AUC interactive figure plot
|
|
338
332
|
"""
|
|
339
333
|
fig = go.Figure()
|
|
340
|
-
fig.add_shape(type="line", line=
|
|
334
|
+
fig.add_shape(type="line", line={"dash":"dash"}, x0=0, x1=1, y0=0, y1=1)
|
|
341
335
|
|
|
342
336
|
if regression is True:
|
|
343
337
|
if self.y_pred_dummies is None:
|
|
@@ -361,8 +355,8 @@ class Computer(object):
|
|
|
361
355
|
title_text=title,
|
|
362
356
|
xaxis_title="False Positive Rate",
|
|
363
357
|
yaxis_title="True Positive Rate",
|
|
364
|
-
yaxis=
|
|
365
|
-
xaxis=
|
|
358
|
+
yaxis={"scaleanchor":"x", "scaleratio":1},
|
|
359
|
+
xaxis={"constrain":"domain"},
|
|
366
360
|
width=800,
|
|
367
361
|
height=500,
|
|
368
362
|
paper_bgcolor="#242a44",
|
|
@@ -374,8 +368,27 @@ class Computer(object):
|
|
|
374
368
|
return fig
|
|
375
369
|
|
|
376
370
|
@staticmethod
|
|
377
|
-
def get_bin_estimate(y_val, n_classes=4, thresholds=
|
|
371
|
+
def get_bin_estimate(y_val, n_classes=4, thresholds=None):
|
|
372
|
+
"""_summary_
|
|
373
|
+
|
|
374
|
+
Parameters
|
|
375
|
+
----------
|
|
376
|
+
y_val : int
|
|
377
|
+
predicted value
|
|
378
|
+
n_classes : int, optional
|
|
379
|
+
number of target classes, by default 4
|
|
380
|
+
thresholds : list, optional
|
|
381
|
+
target class threshold values (length of list much match n_classes), by default None
|
|
382
|
+
|
|
383
|
+
Returns
|
|
384
|
+
-------
|
|
385
|
+
int
|
|
386
|
+
target class bin estimate
|
|
387
|
+
"""
|
|
388
|
+
thresholds = [0, 12, 225, 950] if thresholds is None else thresholds
|
|
378
389
|
thresholds = sorted(thresholds, reverse=True)
|
|
390
|
+
if len(thresholds) != n_classes:
|
|
391
|
+
raise IndexError(f"n_classes = {n_classes} does not match length of thresholds list: {len(thresholds)}")
|
|
379
392
|
for i in list(range(len(thresholds))):
|
|
380
393
|
if y_val >= thresholds[i]:
|
|
381
394
|
return n_classes - i - 1
|
|
@@ -383,7 +396,7 @@ class Computer(object):
|
|
|
383
396
|
continue
|
|
384
397
|
|
|
385
398
|
def make_regression_dummies(self, **kwargs):
|
|
386
|
-
y_true = [self.get_bin_estimate(t, **kwargs) for t in self.predictions[:,1]]
|
|
399
|
+
y_true = [self.get_bin_estimate(t, **kwargs) for t in self.predictions[:, 1]]
|
|
387
400
|
y_scores = [self.get_bin_estimate(p, **kwargs) for p in self.predictions[:, 0]]
|
|
388
401
|
y_onehot = pd.get_dummies(y_true, drop_first=False, dtype=int, prefix="bin")
|
|
389
402
|
self.y_pred_dummies = pd.get_dummies(y_scores, drop_first=False, dtype=int, prefix="bin")
|
|
@@ -395,7 +408,7 @@ class Computer(object):
|
|
|
395
408
|
self.classes = y_onehot.columns
|
|
396
409
|
|
|
397
410
|
def regression_roc(self, fig):
|
|
398
|
-
fpr, tpr, self.roc_auc =
|
|
411
|
+
fpr, tpr, self.roc_auc = {}, {}, {}
|
|
399
412
|
for i in list(range(len(self.classes))):
|
|
400
413
|
y_true = self.y_test_dummies[:, i]
|
|
401
414
|
y_hat = self.y_pred_dummies.iloc[:, i]
|
|
@@ -406,7 +419,7 @@ class Computer(object):
|
|
|
406
419
|
return fig
|
|
407
420
|
|
|
408
421
|
def regression_recall(self, fig):
|
|
409
|
-
precision, recall, self.pr =
|
|
422
|
+
precision, recall, self.pr = {}, {}, {}
|
|
410
423
|
for i in list(range(len(self.classes))):
|
|
411
424
|
y_true = self.y_test_dummies[:, i]
|
|
412
425
|
y_hat = self.y_pred_dummies.iloc[:, i]
|
|
@@ -426,7 +439,7 @@ class Computer(object):
|
|
|
426
439
|
"""
|
|
427
440
|
|
|
428
441
|
fig = go.Figure()
|
|
429
|
-
fig.add_shape(type="line", line=
|
|
442
|
+
fig.add_shape(type="line", line={"dash":"dash"}, x0=0, x1=1, y0=1, y1=0)
|
|
430
443
|
|
|
431
444
|
if regression is True:
|
|
432
445
|
if self.y_pred_dummies is None:
|
|
@@ -450,8 +463,8 @@ class Computer(object):
|
|
|
450
463
|
title_text=title,
|
|
451
464
|
xaxis_title="Recall",
|
|
452
465
|
yaxis_title="Precision",
|
|
453
|
-
yaxis=
|
|
454
|
-
xaxis=
|
|
466
|
+
yaxis={"scaleanchor":"x", "scaleratio":1},
|
|
467
|
+
xaxis={"constrain":"domain"},
|
|
455
468
|
width=800,
|
|
456
469
|
height=500,
|
|
457
470
|
paper_bgcolor="#242a44",
|
|
@@ -479,13 +492,13 @@ class Computer(object):
|
|
|
479
492
|
x=n_epochs,
|
|
480
493
|
y=acc_train,
|
|
481
494
|
name=f"Training {keys[1].title()}",
|
|
482
|
-
marker=
|
|
495
|
+
marker={"color":"#119dff"},
|
|
483
496
|
),
|
|
484
497
|
go.Scatter(
|
|
485
498
|
x=n_epochs,
|
|
486
499
|
y=acc_test,
|
|
487
500
|
name=f"Test {keys[3].title()}",
|
|
488
|
-
marker=
|
|
501
|
+
marker={"color":"#66c2a5"},
|
|
489
502
|
),
|
|
490
503
|
]
|
|
491
504
|
layout = go.Layout(
|
|
@@ -530,13 +543,13 @@ class Computer(object):
|
|
|
530
543
|
x=n_epochs,
|
|
531
544
|
y=loss_train,
|
|
532
545
|
name=f"Training {keys[0].title()}",
|
|
533
|
-
marker=
|
|
546
|
+
marker={"color":"#119dff"},
|
|
534
547
|
),
|
|
535
548
|
go.Scatter(
|
|
536
549
|
x=n_epochs,
|
|
537
550
|
y=loss_test,
|
|
538
551
|
name=f"Test {keys[2].title()}",
|
|
539
|
-
marker=
|
|
552
|
+
marker={"color":"#66c2a5"},
|
|
540
553
|
),
|
|
541
554
|
]
|
|
542
555
|
layout = go.Layout(
|
|
@@ -560,7 +573,7 @@ class Computer(object):
|
|
|
560
573
|
Parameters
|
|
561
574
|
----------
|
|
562
575
|
desc: str, optional
|
|
563
|
-
Append custom text to title
|
|
576
|
+
Append custom text to title
|
|
564
577
|
|
|
565
578
|
Returns
|
|
566
579
|
-------
|
|
@@ -574,13 +587,11 @@ class Computer(object):
|
|
|
574
587
|
np_config.enable_numpy_behavior()
|
|
575
588
|
y = self.y_test.reshape(1, -1)
|
|
576
589
|
p = self.y_pred
|
|
577
|
-
|
|
590
|
+
|
|
578
591
|
title = "Residual Error"
|
|
579
592
|
if desc:
|
|
580
593
|
title += f" - {desc}"
|
|
581
|
-
data = go.Scatter(
|
|
582
|
-
x=y, y=p, name="y-y_hat", mode="markers", marker=dict(color="red")
|
|
583
|
-
)
|
|
594
|
+
data = go.Scatter(x=y, y=p, name="y-y_hat", mode="markers", marker={"color":"red"})
|
|
584
595
|
layout = go.Layout(
|
|
585
596
|
title=title,
|
|
586
597
|
xaxis={"title": "y (ground truth)"},
|
|
@@ -594,7 +605,7 @@ class Computer(object):
|
|
|
594
605
|
fig = go.Figure(data=data, layout=layout)
|
|
595
606
|
fig.add_shape(
|
|
596
607
|
type="line",
|
|
597
|
-
line=
|
|
608
|
+
line={"dash":"dash"},
|
|
598
609
|
x0=y.min(),
|
|
599
610
|
y0=y.min(),
|
|
600
611
|
x1=y.max(),
|
|
@@ -692,14 +703,24 @@ class ComputeClassifier(Computer):
|
|
|
692
703
|
|
|
693
704
|
Parameters
|
|
694
705
|
----------
|
|
695
|
-
|
|
696
|
-
|
|
706
|
+
algorithm : str, optional
|
|
707
|
+
Algorithm used for classification such as 'clf', 'binary' or 'linreg', by default "clf"
|
|
708
|
+
classes : list or tuple, optional
|
|
709
|
+
String labels for the target classes, by default None
|
|
710
|
+
res_path : str, optional
|
|
711
|
+
Path to the directory where results will be saved, by default "results/mem_bin"
|
|
712
|
+
show : bool, optional
|
|
713
|
+
Whether to display plots, by default False
|
|
714
|
+
validation : bool, optional
|
|
715
|
+
Whether the compute object is for a validation set, by default False
|
|
716
|
+
name : str, optional
|
|
717
|
+
Name of the compute object, by default "ComputeClassifier"
|
|
697
718
|
"""
|
|
698
719
|
|
|
699
720
|
def __init__(
|
|
700
721
|
self,
|
|
701
722
|
algorithm="clf",
|
|
702
|
-
classes=
|
|
723
|
+
classes=None,
|
|
703
724
|
res_path="results/mem_bin",
|
|
704
725
|
show=False,
|
|
705
726
|
validation=False,
|
|
@@ -714,7 +735,7 @@ class ComputeClassifier(Computer):
|
|
|
714
735
|
name=name,
|
|
715
736
|
**log_kws,
|
|
716
737
|
)
|
|
717
|
-
self.classes = classes
|
|
738
|
+
self.classes = ["2g", "8g", "16g", "64g"] if classes is None else list(classes)
|
|
718
739
|
|
|
719
740
|
def make_outputs(self, dl=True):
|
|
720
741
|
"""Store computed results into a dictionary, and optionally save to disk.
|
|
@@ -794,9 +815,7 @@ class ComputeClassifier(Computer):
|
|
|
794
815
|
try:
|
|
795
816
|
conf_idx = np.where(self.y_pred != self.test_idx.values)
|
|
796
817
|
except AttributeError as e:
|
|
797
|
-
print(
|
|
798
|
-
f"Test/Val Index should be a pandas series, not {type(self.test_idx)}"
|
|
799
|
-
)
|
|
818
|
+
print(f"Test/Val Index should be a pandas series, not {type(self.test_idx)}")
|
|
800
819
|
print(e)
|
|
801
820
|
return
|
|
802
821
|
pred_proba = np.asarray(self.model.predict(self.X_test).flatten(), "float32")
|
|
@@ -830,20 +849,38 @@ class ComputeBinary(ComputeClassifier):
|
|
|
830
849
|
|
|
831
850
|
Parameters
|
|
832
851
|
----------
|
|
833
|
-
|
|
834
|
-
|
|
852
|
+
builder : ComputeClassifier object, optional
|
|
853
|
+
Existing ComputeClassifier object with instantiated attributes, by default None
|
|
854
|
+
algorithm : str, optional
|
|
855
|
+
Algorithm kind, by default "binary"
|
|
856
|
+
classes : list or tuple, optional
|
|
857
|
+
String labels for the target classes, by default None, by default None
|
|
858
|
+
res_path : str, optional
|
|
859
|
+
Path to store results, by default "results/svm"
|
|
860
|
+
show : bool, optional
|
|
861
|
+
Whether to display plots, by default False
|
|
862
|
+
validation : bool, optional
|
|
863
|
+
Whether to perform validation, by default False
|
|
864
|
+
|
|
865
|
+
Raises
|
|
866
|
+
------
|
|
867
|
+
AttributeError
|
|
868
|
+
Raised when the `classes` parameter is not a list or tuple of exactly two strings.
|
|
835
869
|
"""
|
|
836
870
|
|
|
837
871
|
def __init__(
|
|
838
872
|
self,
|
|
839
873
|
builder=None,
|
|
840
874
|
algorithm="binary",
|
|
841
|
-
classes=
|
|
875
|
+
classes=None,
|
|
842
876
|
res_path="results/svm",
|
|
843
877
|
show=False,
|
|
844
878
|
validation=False,
|
|
845
879
|
**log_kws,
|
|
846
880
|
):
|
|
881
|
+
classes = ["aligned", "misaligned"] if classes is None else classes
|
|
882
|
+
if not isinstance(classes, (list, tuple)) or len(classes) != 2:
|
|
883
|
+
raise AttributeError("Binary classifier requires `classes` to be a list/tuple of exactly two strings to be used as target class names.")
|
|
847
884
|
super().__init__(
|
|
848
885
|
algorithm=algorithm,
|
|
849
886
|
classes=classes,
|
|
@@ -892,15 +929,25 @@ class ComputeMulti(ComputeClassifier):
|
|
|
892
929
|
|
|
893
930
|
Parameters
|
|
894
931
|
----------
|
|
895
|
-
|
|
896
|
-
|
|
932
|
+
builder : ComputeClassifier object, optional
|
|
933
|
+
Existing ComputeClassifier object with instantiated attributes, by default None
|
|
934
|
+
algorithm : str, optional
|
|
935
|
+
Algorithm kind, by default "multiclass"
|
|
936
|
+
classes : list or tuple, optional
|
|
937
|
+
String labels for the target classes, by default None
|
|
938
|
+
res_path : str, optional
|
|
939
|
+
Path to store results, by default "results/svm"
|
|
940
|
+
show : bool, optional
|
|
941
|
+
Whether to display plots, by default False
|
|
942
|
+
validation : bool, optional
|
|
943
|
+
Whether to perform validation, by default False
|
|
897
944
|
"""
|
|
898
945
|
|
|
899
946
|
def __init__(
|
|
900
947
|
self,
|
|
901
948
|
builder=None,
|
|
902
949
|
algorithm="multiclass",
|
|
903
|
-
classes=
|
|
950
|
+
classes=None,
|
|
904
951
|
res_path="results/mem_bin",
|
|
905
952
|
show=False,
|
|
906
953
|
validation=False,
|
|
@@ -951,9 +998,7 @@ class ComputeMulti(ComputeClassifier):
|
|
|
951
998
|
)
|
|
952
999
|
self.roc_auc = self.roc_auc_multi()
|
|
953
1000
|
self.acc_loss = self.acc_loss_scores()
|
|
954
|
-
self.cmx = confusion_matrix(
|
|
955
|
-
np.argmax(self.y_test, axis=-1), np.argmax(self.y_pred, axis=-1)
|
|
956
|
-
)
|
|
1001
|
+
self.cmx = confusion_matrix(np.argmax(self.y_test, axis=-1), np.argmax(self.y_pred, axis=-1))
|
|
957
1002
|
self.cmx_norm = self.fusion_matrix(self.cmx, self.classes)[1]
|
|
958
1003
|
self.fnfp = self.fnfp_multi()
|
|
959
1004
|
if show_summary:
|
|
@@ -1009,9 +1054,7 @@ class ComputeMulti(ComputeClassifier):
|
|
|
1009
1054
|
try:
|
|
1010
1055
|
conf_idx = np.where(preds != actual)[0]
|
|
1011
1056
|
except AttributeError as e: # can probably remove this
|
|
1012
|
-
print(
|
|
1013
|
-
f"Test/Val Index should be a pandas series, not {type(self.test_idx)}"
|
|
1014
|
-
)
|
|
1057
|
+
print(f"Test/Val Index should be a pandas series, not {type(self.test_idx)}")
|
|
1015
1058
|
print(e)
|
|
1016
1059
|
return
|
|
1017
1060
|
pred_proba = np.amax(self.y_scores, axis=-1)
|