dragon-ml-toolbox 20.10.0__py3-none-any.whl → 20.12.0__py3-none-any.whl
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.
- {dragon_ml_toolbox-20.10.0.dist-info → dragon_ml_toolbox-20.12.0.dist-info}/METADATA +1 -1
- {dragon_ml_toolbox-20.10.0.dist-info → dragon_ml_toolbox-20.12.0.dist-info}/RECORD +11 -11
- {dragon_ml_toolbox-20.10.0.dist-info → dragon_ml_toolbox-20.12.0.dist-info}/WHEEL +1 -1
- ml_tools/ML_callbacks/_checkpoint.py +1 -1
- ml_tools/ML_evaluation_captum/_ML_evaluation_captum.py +28 -7
- ml_tools/ML_trainer/_base_trainer.py +11 -1
- ml_tools/ML_trainer/_dragon_trainer.py +5 -4
- ml_tools/keys/_keys.py +1 -1
- {dragon_ml_toolbox-20.10.0.dist-info → dragon_ml_toolbox-20.12.0.dist-info}/licenses/LICENSE +0 -0
- {dragon_ml_toolbox-20.10.0.dist-info → dragon_ml_toolbox-20.12.0.dist-info}/licenses/LICENSE-THIRD-PARTY.md +0 -0
- {dragon_ml_toolbox-20.10.0.dist-info → dragon_ml_toolbox-20.12.0.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dragon-ml-toolbox
|
|
3
|
-
Version: 20.
|
|
3
|
+
Version: 20.12.0
|
|
4
4
|
Summary: Complete pipelines and helper tools for data science and machine learning projects.
|
|
5
5
|
Author-email: Karl Luigi Loza Vidaurre <luigiloza@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
dragon_ml_toolbox-20.
|
|
2
|
-
dragon_ml_toolbox-20.
|
|
1
|
+
dragon_ml_toolbox-20.12.0.dist-info/licenses/LICENSE,sha256=L35WDmmLZNTlJvxF6Vy7Uy4SYNi6rCfWUqlTHpoRMoU,1081
|
|
2
|
+
dragon_ml_toolbox-20.12.0.dist-info/licenses/LICENSE-THIRD-PARTY.md,sha256=0-HBRMMgKuwtGy6nMJZvIn1fLxhx_ksyyVB2U_iyYZU,2818
|
|
3
3
|
ml_tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
4
|
ml_tools/constants.py,sha256=3br5Rk9cL2IUo638eJuMOGdbGQaWssaUecYEvSeRBLM,3322
|
|
5
5
|
ml_tools/ETL_cleaning/__init__.py,sha256=gLRHF-qzwpqKTvbbn9chIQELeUDh_XGpBRX28j-5IqI,545
|
|
@@ -20,7 +20,7 @@ ml_tools/MICE/__init__.py,sha256=-IZv9V06U7BbB3ubu1vgbxtwFy0dV6E-9EDSg6-woio,385
|
|
|
20
20
|
ml_tools/MICE/_dragon_mice.py,sha256=k82I3-f4aMuSW7LzTRnuBniEig7A9_vH-Oj7yWum6ss,17817
|
|
21
21
|
ml_tools/ML_callbacks/__init__.py,sha256=xck_IdLFYCq6Lo2lQqbQd_nOeCDI8nfVyxBaBnQ-wcY,490
|
|
22
22
|
ml_tools/ML_callbacks/_base.py,sha256=xLVAFOhBHjqnf8a_wKgW1F-tn2u6EqV3IHXsXKTn2NE,3269
|
|
23
|
-
ml_tools/ML_callbacks/_checkpoint.py,sha256=
|
|
23
|
+
ml_tools/ML_callbacks/_checkpoint.py,sha256=hzFRCXJexS91lN428ztT85_db9DwaAwczODvdDMn9B4,9721
|
|
24
24
|
ml_tools/ML_callbacks/_early_stop.py,sha256=qzTzxfDCDim0qj7QQ7ykJNIOBWbXtviDptMCczXXy_k,8073
|
|
25
25
|
ml_tools/ML_callbacks/_scheduler.py,sha256=mn97_VH8Lp37KH3zSgmPemGQV8g-K8GfhRNHTftaNcg,7390
|
|
26
26
|
ml_tools/ML_chain/__init__.py,sha256=aqSGAJnFYE_ZWbueNneg2z5welBsmGJ0XKi8Ebgw6Eg,554
|
|
@@ -46,7 +46,7 @@ ml_tools/ML_evaluation/_loss.py,sha256=1a4O25i3Ya_3naNZNL7ELLUL46BY86g1scA7d7q2U
|
|
|
46
46
|
ml_tools/ML_evaluation/_regression.py,sha256=UZA7_fg85ZKJQWszioWDtmkplSiXeHJk2fBYR5bRXHY,11225
|
|
47
47
|
ml_tools/ML_evaluation/_sequence.py,sha256=gUk9Uvmy7MrXkfrriMnfypkgJU5XERHdqekTa2gBaOM,8004
|
|
48
48
|
ml_tools/ML_evaluation/_vision.py,sha256=abBHQ6Z2GunHNusL3wcLgfI1FVNA6hBUBTq1eOA8FSA,11489
|
|
49
|
-
ml_tools/ML_evaluation_captum/_ML_evaluation_captum.py,sha256=
|
|
49
|
+
ml_tools/ML_evaluation_captum/_ML_evaluation_captum.py,sha256=eWxd6HRQSaqFYNek6x1hZBKi8qeHqk4oOkqrjQgKjZk,19611
|
|
50
50
|
ml_tools/ML_evaluation_captum/__init__.py,sha256=DZDoZXexCI49JNl_tTmFfYW4hTUYK5QQLex01wMfhnk,333
|
|
51
51
|
ml_tools/ML_finalize_handler/_ML_finalize_handler.py,sha256=g-vkHJDTGXZsKOUA-Yfg7EuA1SmaHjzesCPiAyRMg2k,7054
|
|
52
52
|
ml_tools/ML_finalize_handler/__init__.py,sha256=VQyLbCQUcliAAFiOAsnPhyJ7UVYgbSqAbAnpqeOnRSg,198
|
|
@@ -83,10 +83,10 @@ ml_tools/ML_optimization/_single_manual.py,sha256=h-_k9JmRqPkjTra1nu7AyYbSyWkYZ1
|
|
|
83
83
|
ml_tools/ML_scaler/_ML_scaler.py,sha256=P75X0Sx8N-VxC2Qy8aG7mWaZlkTfjspiZDi1YiMQD1I,8872
|
|
84
84
|
ml_tools/ML_scaler/__init__.py,sha256=SHDNyLsoOLl2OtkIb3pGg-JRs3E2bYJBgnHwH3vw_Tk,172
|
|
85
85
|
ml_tools/ML_trainer/__init__.py,sha256=42kueHa7Z0b_yLbywNCgIxlW6WmgLBqkTFwKH7vFLXw,379
|
|
86
|
-
ml_tools/ML_trainer/_base_trainer.py,sha256=
|
|
86
|
+
ml_tools/ML_trainer/_base_trainer.py,sha256=0ATm672NRsjJ6nv_NEl6-OEd9Bst1-s5OPxfG4qe8Lg,18075
|
|
87
87
|
ml_tools/ML_trainer/_dragon_detection_trainer.py,sha256=B5F93PPnp2fYQmj1SYFRnAPVA39JwZUtJRMCdpSQF7k,16235
|
|
88
88
|
ml_tools/ML_trainer/_dragon_sequence_trainer.py,sha256=Tj4YGgMrCkLnnNUlT_8wcdJFFcFhsdux308QPiqj-tw,23509
|
|
89
|
-
ml_tools/ML_trainer/_dragon_trainer.py,sha256=
|
|
89
|
+
ml_tools/ML_trainer/_dragon_trainer.py,sha256=KLDLoUcCLIteoGtrLQDTbnD9Cf73V7TUiGT7CGSdeks,58574
|
|
90
90
|
ml_tools/ML_utilities/__init__.py,sha256=71T3RDKDgHVvFrEr0G7tjuwbDVk_4JZGzwZtejC3PuE,739
|
|
91
91
|
ml_tools/ML_utilities/_artifact_finder.py,sha256=X4xz_rmi0jVan8Sun_6431TcQiNM-GDHm-DHLA1zYms,15816
|
|
92
92
|
ml_tools/ML_utilities/_inspection.py,sha256=mXTnjGmdDpBfY99xfekyrGbSvrWHBcVndivMbqPD4PI,13186
|
|
@@ -119,7 +119,7 @@ ml_tools/ensemble_learning/_ensemble_learning.py,sha256=MHDZBR20_nStlSSeThFI3bSu
|
|
|
119
119
|
ml_tools/excel_handler/__init__.py,sha256=AaWM3n_dqBhJLTs3OEA57ex5YykKXNOwVCyHlVsdnqI,530
|
|
120
120
|
ml_tools/excel_handler/_excel_handler.py,sha256=TODudmeQgDSdxUKzLfAzizs--VL-g8WxDOfQ4sgxxLs,13965
|
|
121
121
|
ml_tools/keys/__init__.py,sha256=-0c2pmrhyfROc-oQpEjJGLBMhSagA3CyFijQaaqZRqU,399
|
|
122
|
-
ml_tools/keys/_keys.py,sha256=
|
|
122
|
+
ml_tools/keys/_keys.py,sha256=Kr73o9SaH5Y3DT0z0H-1eLwlBplJmjisjoO_EoUNkAg,9388
|
|
123
123
|
ml_tools/math_utilities/__init__.py,sha256=K7Obkkc4rPKj4EbRZf1BsXHfiCg7FXYv_aN9Yc2Z_Vg,400
|
|
124
124
|
ml_tools/math_utilities/_math_utilities.py,sha256=BYHIVcM9tuKIhVrkgLLiM5QalJ39zx7dXYy_M9aGgiM,9012
|
|
125
125
|
ml_tools/optimization_tools/__init__.py,sha256=KD8JXpfGuPndO4AHnjJGu6uV1GRwhOfboD0KZV45kzw,658
|
|
@@ -143,7 +143,7 @@ ml_tools/utilities/__init__.py,sha256=h4lE3SQstg-opcQj6QSKhu-HkqSbmHExsWoM9vC5D9
|
|
|
143
143
|
ml_tools/utilities/_translate.py,sha256=U8hRPa3PmTpIf9n9yR3gBGmp_hkcsjQLwjAHSHc0WHs,10325
|
|
144
144
|
ml_tools/utilities/_utility_save_load.py,sha256=EFvFaTaHahDQWdJWZr-j7cHqRbG_Xrpc96228JhV-bs,16773
|
|
145
145
|
ml_tools/utilities/_utility_tools.py,sha256=bN0J9d1S0W5wNzNntBWqDsJcEAK7-1OgQg3X2fwXns0,6918
|
|
146
|
-
dragon_ml_toolbox-20.
|
|
147
|
-
dragon_ml_toolbox-20.
|
|
148
|
-
dragon_ml_toolbox-20.
|
|
149
|
-
dragon_ml_toolbox-20.
|
|
146
|
+
dragon_ml_toolbox-20.12.0.dist-info/METADATA,sha256=VH-wt974dX5kNOfVShO_N5HJJCIhqP2V_7uihSwlYzE,7889
|
|
147
|
+
dragon_ml_toolbox-20.12.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
148
|
+
dragon_ml_toolbox-20.12.0.dist-info/top_level.txt,sha256=wm-oxax3ciyez6VoO4zsFd-gSok2VipYXnbg3TH9PtU,9
|
|
149
|
+
dragon_ml_toolbox-20.12.0.dist-info/RECORD,,
|
|
@@ -79,7 +79,7 @@ class DragonModelCheckpoint(_Callback):
|
|
|
79
79
|
|
|
80
80
|
def on_train_begin(self, logs=None):
|
|
81
81
|
"""Reset file tracking state when training starts.
|
|
82
|
-
NOTE: Do
|
|
82
|
+
NOTE: Do not reset self.best here if it differs from the default. This allows the Trainer to restore 'best' from a checkpoint before calling train()."""
|
|
83
83
|
self.best_checkpoints = []
|
|
84
84
|
self.recent_checkpoints = []
|
|
85
85
|
|
|
@@ -30,7 +30,8 @@ def captum_feature_importance(model: nn.Module,
|
|
|
30
30
|
save_dir: Union[str, Path],
|
|
31
31
|
target_names: Optional[list[str]] = None,
|
|
32
32
|
n_steps: int = 50,
|
|
33
|
-
device: Union[str, torch.device] = 'cpu'
|
|
33
|
+
device: Union[str, torch.device] = 'cpu',
|
|
34
|
+
verbose: int = 0):
|
|
34
35
|
"""
|
|
35
36
|
Calculates feature importance using Captum's Integrated Gradients.
|
|
36
37
|
|
|
@@ -49,7 +50,7 @@ def captum_feature_importance(model: nn.Module,
|
|
|
49
50
|
- If `None`, generic names (e.g., "Output_0") will be generated based on model output shape.
|
|
50
51
|
n_steps (int): Number of steps for the integral approximation. Higher means more accurate but slower.
|
|
51
52
|
device (str | torch.device): Torch device.
|
|
52
|
-
|
|
53
|
+
verbose (int): Verbosity level.
|
|
53
54
|
<br>
|
|
54
55
|
|
|
55
56
|
### NOTE:
|
|
@@ -127,7 +128,8 @@ def captum_feature_importance(model: nn.Module,
|
|
|
127
128
|
save_dir=save_dir_path,
|
|
128
129
|
n_steps=n_steps,
|
|
129
130
|
file_suffix=f"_{clean_name}",
|
|
130
|
-
target_name=name # Pass original name for plotting
|
|
131
|
+
target_name=name, # Pass original name for plotting
|
|
132
|
+
verbose=verbose
|
|
131
133
|
)
|
|
132
134
|
|
|
133
135
|
|
|
@@ -139,7 +141,8 @@ def _process_single_target(ig: 'IntegratedGradients', # type: ignore
|
|
|
139
141
|
save_dir: Path,
|
|
140
142
|
n_steps: int,
|
|
141
143
|
file_suffix: str,
|
|
142
|
-
target_name: str = ""
|
|
144
|
+
target_name: str = "",
|
|
145
|
+
verbose: int = 0):
|
|
143
146
|
"""
|
|
144
147
|
Private helper to run the attribution, aggregation, and saving for a single context.
|
|
145
148
|
"""
|
|
@@ -153,8 +156,8 @@ def _process_single_target(ig: 'IntegratedGradients', # type: ignore
|
|
|
153
156
|
return_convergence_delta=True)
|
|
154
157
|
# Check convergence quality
|
|
155
158
|
mean_delta = torch.mean(torch.abs(delta)).item()
|
|
156
|
-
if mean_delta > 0.1:
|
|
157
|
-
_LOGGER.warning(f"Captum Convergence Delta is high ({mean_delta:.4f}).
|
|
159
|
+
if mean_delta > 0.1 and verbose > 0:
|
|
160
|
+
_LOGGER.warning(f"Captum Convergence Delta is high ({mean_delta:.4f}). Consider increasing 'n_steps'.")
|
|
158
161
|
|
|
159
162
|
except Exception as e:
|
|
160
163
|
_LOGGER.error(f"Captum attribution failed for target '{target_index}': {e}")
|
|
@@ -198,6 +201,23 @@ def _process_single_target(ig: 'IntegratedGradients', # type: ignore
|
|
|
198
201
|
min_len = min(len(mean_abs_attr), len(feature_names))
|
|
199
202
|
mean_abs_attr = mean_abs_attr[:min_len]
|
|
200
203
|
feature_names = feature_names[:min_len]
|
|
204
|
+
|
|
205
|
+
# Min-Max Scaling
|
|
206
|
+
target_min = 0.01
|
|
207
|
+
target_max = 1.0
|
|
208
|
+
|
|
209
|
+
_min = np.min(mean_abs_attr)
|
|
210
|
+
_max = np.max(mean_abs_attr)
|
|
211
|
+
|
|
212
|
+
if _max > _min:
|
|
213
|
+
# 1. Normalize to [0, 1]
|
|
214
|
+
mean_abs_attr = (mean_abs_attr - _min) / (_max - _min)
|
|
215
|
+
# 2. Scale to [target_min, target_max]
|
|
216
|
+
mean_abs_attr = mean_abs_attr * (target_max - target_min) + target_min
|
|
217
|
+
else:
|
|
218
|
+
# Fallback: if all values are identical (e.g. all 0.0), set to target_min
|
|
219
|
+
fill_val = target_min if _max == 0 else target_max
|
|
220
|
+
mean_abs_attr = np.full_like(mean_abs_attr, fill_val)
|
|
201
221
|
|
|
202
222
|
# --- Save Data to CSV ---
|
|
203
223
|
summary_df = pd.DataFrame({
|
|
@@ -211,8 +231,9 @@ def _process_single_target(ig: 'IntegratedGradients', # type: ignore
|
|
|
211
231
|
|
|
212
232
|
# --- Generate Plot ---
|
|
213
233
|
plot_df = summary_df.head(20).sort_values(CaptumKeys.IMPORTANCE_COLUMN, ascending=True)
|
|
214
|
-
plt.figure(figsize=(10, 8), dpi=
|
|
234
|
+
plt.figure(figsize=(10, 8), dpi=300)
|
|
215
235
|
plt.barh(plot_df[CaptumKeys.FEATURE_COLUMN], plot_df[CaptumKeys.IMPORTANCE_COLUMN], color='mediumpurple')
|
|
236
|
+
plt.xlim(0, 1.05) # standardized scale
|
|
216
237
|
plt.xlabel("Mean Absolute Attribution")
|
|
217
238
|
|
|
218
239
|
title = "Feature Importance"
|
|
@@ -276,6 +276,16 @@ class _BaseDragonTrainer(ABC):
|
|
|
276
276
|
except Exception as e:
|
|
277
277
|
_LOGGER.error(f"Failed to load checkpoint from '{p}': {e}")
|
|
278
278
|
raise
|
|
279
|
+
|
|
280
|
+
def load_checkpoint(self, path: Union[str, Path], verbose: int = 3):
|
|
281
|
+
"""
|
|
282
|
+
Loads a specific checkpoint state into the model, optimizer, and scheduler.
|
|
283
|
+
|
|
284
|
+
Args:
|
|
285
|
+
path (str | Path): Path to the .pth checkpoint file.
|
|
286
|
+
verbose (int): Verbosity level for logging.
|
|
287
|
+
"""
|
|
288
|
+
self._load_checkpoint(path=path, verbose=verbose)
|
|
279
289
|
|
|
280
290
|
def fit(self,
|
|
281
291
|
save_dir: Union[str,Path],
|
|
@@ -366,7 +376,7 @@ class _BaseDragonTrainer(ABC):
|
|
|
366
376
|
self.device = self._validate_device(device)
|
|
367
377
|
self.model.to(self.device)
|
|
368
378
|
_LOGGER.info(f"Trainer and model moved to {self.device}.")
|
|
369
|
-
|
|
379
|
+
|
|
370
380
|
def _load_model_state_wrapper(self, model_checkpoint: Union[Path, Literal['best', 'current']], verbose: int = 2):
|
|
371
381
|
"""
|
|
372
382
|
Private helper to load the correct model state_dict based on user's choice.
|
|
@@ -33,8 +33,7 @@ from ..ML_configuration import (FormatRegressionMetrics,
|
|
|
33
33
|
FinalizeMultiTargetRegression,
|
|
34
34
|
FinalizeRegression)
|
|
35
35
|
|
|
36
|
-
from ..
|
|
37
|
-
from ..keys._keys import PyTorchLogKeys, PyTorchCheckpointKeys, DatasetKeys, MLTaskKeys, MagicWords, DragonTrainerKeys, ScalerKeys
|
|
36
|
+
from ..keys._keys import PyTorchLogKeys, PyTorchCheckpointKeys, DatasetKeys, MLTaskKeys, DragonTrainerKeys, ScalerKeys
|
|
38
37
|
from .._core import get_logger
|
|
39
38
|
|
|
40
39
|
from ._base_trainer import _BaseDragonTrainer
|
|
@@ -824,7 +823,8 @@ class DragonTrainer(_BaseDragonTrainer):
|
|
|
824
823
|
n_samples: int = 100,
|
|
825
824
|
feature_names: Optional[list[str]] = None,
|
|
826
825
|
target_names: Optional[list[str]] = None,
|
|
827
|
-
n_steps: int = 50
|
|
826
|
+
n_steps: int = 50,
|
|
827
|
+
verbose: int = 0):
|
|
828
828
|
"""
|
|
829
829
|
Explains model predictions using Captum's Integrated Gradients.
|
|
830
830
|
|
|
@@ -927,7 +927,8 @@ class DragonTrainer(_BaseDragonTrainer):
|
|
|
927
927
|
save_dir=save_dir,
|
|
928
928
|
target_names=target_names,
|
|
929
929
|
n_steps=n_steps,
|
|
930
|
-
device=self.device
|
|
930
|
+
device=self.device,
|
|
931
|
+
verbose=verbose
|
|
931
932
|
)
|
|
932
933
|
|
|
933
934
|
def _attention_helper(self, dataloader: DataLoader):
|
ml_tools/keys/_keys.py
CHANGED
{dragon_ml_toolbox-20.10.0.dist-info → dragon_ml_toolbox-20.12.0.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|