dragon-ml-toolbox 19.13.0__py3-none-any.whl → 20.0.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-19.13.0.dist-info → dragon_ml_toolbox-20.0.0.dist-info}/METADATA +29 -46
- dragon_ml_toolbox-20.0.0.dist-info/RECORD +178 -0
- ml_tools/{ETL_cleaning.py → ETL_cleaning/__init__.py} +13 -5
- ml_tools/ETL_cleaning/_basic_clean.py +351 -0
- ml_tools/ETL_cleaning/_clean_tools.py +128 -0
- ml_tools/ETL_cleaning/_dragon_cleaner.py +245 -0
- ml_tools/ETL_cleaning/_imprimir.py +13 -0
- ml_tools/{ETL_engineering.py → ETL_engineering/__init__.py} +8 -4
- ml_tools/ETL_engineering/_dragon_engineering.py +261 -0
- ml_tools/ETL_engineering/_imprimir.py +24 -0
- ml_tools/{_core/_ETL_engineering.py → ETL_engineering/_transforms.py} +14 -267
- ml_tools/{_core → GUI_tools}/_GUI_tools.py +37 -40
- ml_tools/{GUI_tools.py → GUI_tools/__init__.py} +7 -5
- ml_tools/GUI_tools/_imprimir.py +12 -0
- ml_tools/IO_tools/_IO_loggers.py +235 -0
- ml_tools/IO_tools/_IO_save_load.py +151 -0
- ml_tools/IO_tools/_IO_utils.py +140 -0
- ml_tools/{IO_tools.py → IO_tools/__init__.py} +13 -5
- ml_tools/IO_tools/_imprimir.py +14 -0
- ml_tools/MICE/_MICE_imputation.py +132 -0
- ml_tools/{MICE_imputation.py → MICE/__init__.py} +6 -7
- ml_tools/{_core/_MICE_imputation.py → MICE/_dragon_mice.py} +243 -322
- ml_tools/MICE/_imprimir.py +11 -0
- ml_tools/{ML_callbacks.py → ML_callbacks/__init__.py} +12 -4
- ml_tools/ML_callbacks/_base.py +101 -0
- ml_tools/ML_callbacks/_checkpoint.py +232 -0
- ml_tools/ML_callbacks/_early_stop.py +208 -0
- ml_tools/ML_callbacks/_imprimir.py +12 -0
- ml_tools/ML_callbacks/_scheduler.py +197 -0
- ml_tools/{ML_chaining_utilities.py → ML_chain/__init__.py} +8 -3
- ml_tools/{_core/_ML_chaining_utilities.py → ML_chain/_chaining_tools.py} +5 -129
- ml_tools/ML_chain/_dragon_chain.py +140 -0
- ml_tools/ML_chain/_imprimir.py +11 -0
- ml_tools/ML_configuration/__init__.py +90 -0
- ml_tools/ML_configuration/_base_model_config.py +69 -0
- ml_tools/ML_configuration/_finalize.py +366 -0
- ml_tools/ML_configuration/_imprimir.py +47 -0
- ml_tools/ML_configuration/_metrics.py +593 -0
- ml_tools/ML_configuration/_models.py +206 -0
- ml_tools/ML_configuration/_training.py +124 -0
- ml_tools/ML_datasetmaster/__init__.py +28 -0
- ml_tools/ML_datasetmaster/_base_datasetmaster.py +337 -0
- ml_tools/{_core/_ML_datasetmaster.py → ML_datasetmaster/_datasetmaster.py} +9 -329
- ml_tools/ML_datasetmaster/_imprimir.py +15 -0
- ml_tools/{_core/_ML_sequence_datasetmaster.py → ML_datasetmaster/_sequence_datasetmaster.py} +13 -15
- ml_tools/{_core/_ML_vision_datasetmaster.py → ML_datasetmaster/_vision_datasetmaster.py} +63 -65
- ml_tools/ML_evaluation/__init__.py +53 -0
- ml_tools/ML_evaluation/_classification.py +629 -0
- ml_tools/ML_evaluation/_feature_importance.py +409 -0
- ml_tools/ML_evaluation/_imprimir.py +25 -0
- ml_tools/ML_evaluation/_loss.py +92 -0
- ml_tools/ML_evaluation/_regression.py +273 -0
- ml_tools/{_core/_ML_sequence_evaluation.py → ML_evaluation/_sequence.py} +8 -11
- ml_tools/{_core/_ML_vision_evaluation.py → ML_evaluation/_vision.py} +12 -17
- ml_tools/{_core → ML_evaluation_captum}/_ML_evaluation_captum.py +11 -38
- ml_tools/{ML_evaluation_captum.py → ML_evaluation_captum/__init__.py} +6 -4
- ml_tools/ML_evaluation_captum/_imprimir.py +10 -0
- ml_tools/{_core → ML_finalize_handler}/_ML_finalize_handler.py +3 -7
- ml_tools/ML_finalize_handler/__init__.py +10 -0
- ml_tools/ML_finalize_handler/_imprimir.py +8 -0
- ml_tools/ML_inference/__init__.py +22 -0
- ml_tools/ML_inference/_base_inference.py +166 -0
- ml_tools/{_core/_ML_chaining_inference.py → ML_inference/_chain_inference.py} +14 -17
- ml_tools/ML_inference/_dragon_inference.py +332 -0
- ml_tools/ML_inference/_imprimir.py +11 -0
- ml_tools/ML_inference/_multi_inference.py +180 -0
- ml_tools/ML_inference_sequence/__init__.py +10 -0
- ml_tools/ML_inference_sequence/_imprimir.py +8 -0
- ml_tools/{_core/_ML_sequence_inference.py → ML_inference_sequence/_sequence_inference.py} +11 -15
- ml_tools/ML_inference_vision/__init__.py +10 -0
- ml_tools/ML_inference_vision/_imprimir.py +8 -0
- ml_tools/{_core/_ML_vision_inference.py → ML_inference_vision/_vision_inference.py} +15 -19
- ml_tools/ML_models/__init__.py +32 -0
- ml_tools/{_core/_ML_models_advanced.py → ML_models/_advanced_models.py} +22 -18
- ml_tools/ML_models/_base_mlp_attention.py +198 -0
- ml_tools/{_core/_models_advanced_base.py → ML_models/_base_save_load.py} +73 -49
- ml_tools/ML_models/_dragon_tabular.py +248 -0
- ml_tools/ML_models/_imprimir.py +18 -0
- ml_tools/ML_models/_mlp_attention.py +134 -0
- ml_tools/{_core → ML_models}/_models_advanced_helpers.py +13 -13
- ml_tools/ML_models_sequence/__init__.py +10 -0
- ml_tools/ML_models_sequence/_imprimir.py +8 -0
- ml_tools/{_core/_ML_sequence_models.py → ML_models_sequence/_sequence_models.py} +5 -8
- ml_tools/ML_models_vision/__init__.py +29 -0
- ml_tools/ML_models_vision/_base_wrapper.py +254 -0
- ml_tools/ML_models_vision/_image_classification.py +182 -0
- ml_tools/ML_models_vision/_image_segmentation.py +108 -0
- ml_tools/ML_models_vision/_imprimir.py +16 -0
- ml_tools/ML_models_vision/_object_detection.py +135 -0
- ml_tools/ML_optimization/__init__.py +21 -0
- ml_tools/ML_optimization/_imprimir.py +13 -0
- ml_tools/{_core/_ML_optimization_pareto.py → ML_optimization/_multi_dragon.py} +18 -24
- ml_tools/ML_optimization/_single_dragon.py +203 -0
- ml_tools/{_core/_ML_optimization.py → ML_optimization/_single_manual.py} +75 -213
- ml_tools/{_core → ML_scaler}/_ML_scaler.py +8 -11
- ml_tools/ML_scaler/__init__.py +10 -0
- ml_tools/ML_scaler/_imprimir.py +8 -0
- ml_tools/ML_trainer/__init__.py +20 -0
- ml_tools/ML_trainer/_base_trainer.py +297 -0
- ml_tools/ML_trainer/_dragon_detection_trainer.py +402 -0
- ml_tools/ML_trainer/_dragon_sequence_trainer.py +540 -0
- ml_tools/ML_trainer/_dragon_trainer.py +1160 -0
- ml_tools/ML_trainer/_imprimir.py +10 -0
- ml_tools/{ML_utilities.py → ML_utilities/__init__.py} +14 -6
- ml_tools/ML_utilities/_artifact_finder.py +382 -0
- ml_tools/ML_utilities/_imprimir.py +16 -0
- ml_tools/ML_utilities/_inspection.py +325 -0
- ml_tools/ML_utilities/_train_tools.py +205 -0
- ml_tools/{ML_vision_transformers.py → ML_vision_transformers/__init__.py} +9 -6
- ml_tools/{_core/_ML_vision_transformers.py → ML_vision_transformers/_core_transforms.py} +11 -155
- ml_tools/ML_vision_transformers/_imprimir.py +14 -0
- ml_tools/ML_vision_transformers/_offline_augmentation.py +159 -0
- ml_tools/{_core/_PSO_optimization.py → PSO_optimization/_PSO.py} +58 -15
- ml_tools/{PSO_optimization.py → PSO_optimization/__init__.py} +5 -3
- ml_tools/PSO_optimization/_imprimir.py +10 -0
- ml_tools/SQL/__init__.py +7 -0
- ml_tools/{_core/_SQL.py → SQL/_dragon_SQL.py} +7 -11
- ml_tools/SQL/_imprimir.py +8 -0
- ml_tools/{_core → VIF}/_VIF_factor.py +5 -8
- ml_tools/{VIF_factor.py → VIF/__init__.py} +4 -2
- ml_tools/VIF/_imprimir.py +10 -0
- ml_tools/_core/__init__.py +7 -1
- ml_tools/_core/_logger.py +8 -18
- ml_tools/_core/_schema_load_ops.py +43 -0
- ml_tools/_core/_script_info.py +2 -2
- ml_tools/{data_exploration.py → data_exploration/__init__.py} +32 -16
- ml_tools/data_exploration/_analysis.py +214 -0
- ml_tools/data_exploration/_cleaning.py +566 -0
- ml_tools/data_exploration/_features.py +583 -0
- ml_tools/data_exploration/_imprimir.py +32 -0
- ml_tools/data_exploration/_plotting.py +487 -0
- ml_tools/data_exploration/_schema_ops.py +176 -0
- ml_tools/{ensemble_evaluation.py → ensemble_evaluation/__init__.py} +6 -4
- ml_tools/{_core → ensemble_evaluation}/_ensemble_evaluation.py +3 -7
- ml_tools/ensemble_evaluation/_imprimir.py +14 -0
- ml_tools/{ensemble_inference.py → ensemble_inference/__init__.py} +5 -3
- ml_tools/{_core → ensemble_inference}/_ensemble_inference.py +15 -18
- ml_tools/ensemble_inference/_imprimir.py +9 -0
- ml_tools/{ensemble_learning.py → ensemble_learning/__init__.py} +4 -6
- ml_tools/{_core → ensemble_learning}/_ensemble_learning.py +7 -10
- ml_tools/ensemble_learning/_imprimir.py +10 -0
- ml_tools/{excel_handler.py → excel_handler/__init__.py} +5 -3
- ml_tools/{_core → excel_handler}/_excel_handler.py +6 -10
- ml_tools/excel_handler/_imprimir.py +13 -0
- ml_tools/{keys.py → keys/__init__.py} +4 -1
- ml_tools/keys/_imprimir.py +11 -0
- ml_tools/{_core → keys}/_keys.py +2 -0
- ml_tools/{math_utilities.py → math_utilities/__init__.py} +5 -2
- ml_tools/math_utilities/_imprimir.py +11 -0
- ml_tools/{_core → math_utilities}/_math_utilities.py +1 -5
- ml_tools/{optimization_tools.py → optimization_tools/__init__.py} +9 -4
- ml_tools/optimization_tools/_imprimir.py +13 -0
- ml_tools/optimization_tools/_optimization_bounds.py +236 -0
- ml_tools/optimization_tools/_optimization_plots.py +218 -0
- ml_tools/{path_manager.py → path_manager/__init__.py} +6 -3
- ml_tools/{_core/_path_manager.py → path_manager/_dragonmanager.py} +11 -347
- ml_tools/path_manager/_imprimir.py +15 -0
- ml_tools/path_manager/_path_tools.py +346 -0
- ml_tools/plot_fonts/__init__.py +8 -0
- ml_tools/plot_fonts/_imprimir.py +8 -0
- ml_tools/{_core → plot_fonts}/_plot_fonts.py +2 -5
- ml_tools/schema/__init__.py +15 -0
- ml_tools/schema/_feature_schema.py +223 -0
- ml_tools/schema/_gui_schema.py +191 -0
- ml_tools/schema/_imprimir.py +10 -0
- ml_tools/{serde.py → serde/__init__.py} +4 -2
- ml_tools/serde/_imprimir.py +10 -0
- ml_tools/{_core → serde}/_serde.py +3 -8
- ml_tools/{utilities.py → utilities/__init__.py} +11 -6
- ml_tools/utilities/_imprimir.py +18 -0
- ml_tools/{_core/_utilities.py → utilities/_utility_save_load.py} +13 -190
- ml_tools/utilities/_utility_tools.py +192 -0
- dragon_ml_toolbox-19.13.0.dist-info/RECORD +0 -111
- ml_tools/ML_chaining_inference.py +0 -8
- ml_tools/ML_configuration.py +0 -86
- ml_tools/ML_configuration_pytab.py +0 -14
- ml_tools/ML_datasetmaster.py +0 -10
- ml_tools/ML_evaluation.py +0 -16
- ml_tools/ML_evaluation_multi.py +0 -12
- ml_tools/ML_finalize_handler.py +0 -8
- ml_tools/ML_inference.py +0 -12
- ml_tools/ML_models.py +0 -14
- ml_tools/ML_models_advanced.py +0 -14
- ml_tools/ML_models_pytab.py +0 -14
- ml_tools/ML_optimization.py +0 -14
- ml_tools/ML_optimization_pareto.py +0 -8
- ml_tools/ML_scaler.py +0 -8
- ml_tools/ML_sequence_datasetmaster.py +0 -8
- ml_tools/ML_sequence_evaluation.py +0 -10
- ml_tools/ML_sequence_inference.py +0 -8
- ml_tools/ML_sequence_models.py +0 -8
- ml_tools/ML_trainer.py +0 -12
- ml_tools/ML_vision_datasetmaster.py +0 -12
- ml_tools/ML_vision_evaluation.py +0 -10
- ml_tools/ML_vision_inference.py +0 -8
- ml_tools/ML_vision_models.py +0 -18
- ml_tools/SQL.py +0 -8
- ml_tools/_core/_ETL_cleaning.py +0 -694
- ml_tools/_core/_IO_tools.py +0 -498
- ml_tools/_core/_ML_callbacks.py +0 -702
- ml_tools/_core/_ML_configuration.py +0 -1332
- ml_tools/_core/_ML_configuration_pytab.py +0 -102
- ml_tools/_core/_ML_evaluation.py +0 -867
- ml_tools/_core/_ML_evaluation_multi.py +0 -544
- ml_tools/_core/_ML_inference.py +0 -646
- ml_tools/_core/_ML_models.py +0 -668
- ml_tools/_core/_ML_models_pytab.py +0 -693
- ml_tools/_core/_ML_trainer.py +0 -2323
- ml_tools/_core/_ML_utilities.py +0 -886
- ml_tools/_core/_ML_vision_models.py +0 -644
- ml_tools/_core/_data_exploration.py +0 -1901
- ml_tools/_core/_optimization_tools.py +0 -493
- ml_tools/_core/_schema.py +0 -359
- ml_tools/plot_fonts.py +0 -8
- ml_tools/schema.py +0 -12
- {dragon_ml_toolbox-19.13.0.dist-info → dragon_ml_toolbox-20.0.0.dist-info}/WHEEL +0 -0
- {dragon_ml_toolbox-19.13.0.dist-info → dragon_ml_toolbox-20.0.0.dist-info}/licenses/LICENSE +0 -0
- {dragon_ml_toolbox-19.13.0.dist-info → dragon_ml_toolbox-20.0.0.dist-info}/licenses/LICENSE-THIRD-PARTY.md +0 -0
- {dragon_ml_toolbox-19.13.0.dist-info → dragon_ml_toolbox-20.0.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
from .._core import get_logger
|
|
5
|
+
from ..path_manager import sanitize_filename
|
|
6
|
+
from ..keys._keys import MLTaskKeys
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
_LOGGER = get_logger("Finalized Configuration")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
# --- Finalize Configs ---
|
|
14
|
+
"FinalizeBinaryClassification",
|
|
15
|
+
"FinalizeBinarySegmentation",
|
|
16
|
+
"FinalizeBinaryImageClassification",
|
|
17
|
+
"FinalizeMultiClassClassification",
|
|
18
|
+
"FinalizeMultiClassImageClassification",
|
|
19
|
+
"FinalizeMultiClassSegmentation",
|
|
20
|
+
"FinalizeMultiLabelBinaryClassification",
|
|
21
|
+
"FinalizeMultiTargetRegression",
|
|
22
|
+
"FinalizeRegression",
|
|
23
|
+
"FinalizeObjectDetection",
|
|
24
|
+
"FinalizeSequenceSequencePrediction",
|
|
25
|
+
"FinalizeSequenceValuePrediction",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
# -------- Finalize classes --------
|
|
29
|
+
class _FinalizeModelTraining:
|
|
30
|
+
"""
|
|
31
|
+
Base class for finalizing model training.
|
|
32
|
+
|
|
33
|
+
This class is not intended to be instantiated directly. Instead, use one of its specific subclasses.
|
|
34
|
+
"""
|
|
35
|
+
def __init__(self,
|
|
36
|
+
filename: str,
|
|
37
|
+
) -> None:
|
|
38
|
+
self.filename = _validate_string(string=filename, attribute_name="filename", extension=".pth")
|
|
39
|
+
self.target_name: Optional[str] = None
|
|
40
|
+
self.target_names: Optional[list[str]] = None
|
|
41
|
+
self.classification_threshold: Optional[float] = None
|
|
42
|
+
self.class_map: Optional[dict[str,int]] = None
|
|
43
|
+
self.initial_sequence: Optional[np.ndarray] = None
|
|
44
|
+
self.sequence_length: Optional[int] = None
|
|
45
|
+
self.task: str = 'UNKNOWN'
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class FinalizeRegression(_FinalizeModelTraining):
|
|
49
|
+
"""Parameters for finalizing a single-target regression model."""
|
|
50
|
+
def __init__(self,
|
|
51
|
+
filename: str,
|
|
52
|
+
target_name: str,
|
|
53
|
+
) -> None:
|
|
54
|
+
"""Initializes the finalization parameters.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
filename (str): The name of the file to be saved.
|
|
58
|
+
target_name (str): The name of the target variable.
|
|
59
|
+
"""
|
|
60
|
+
super().__init__(filename=filename)
|
|
61
|
+
self.target_name = _validate_string(string=target_name, attribute_name="Target name")
|
|
62
|
+
self.task = MLTaskKeys.REGRESSION
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class FinalizeMultiTargetRegression(_FinalizeModelTraining):
|
|
66
|
+
"""Parameters for finalizing a multi-target regression model."""
|
|
67
|
+
def __init__(self,
|
|
68
|
+
filename: str,
|
|
69
|
+
target_names: list[str],
|
|
70
|
+
) -> None:
|
|
71
|
+
"""Initializes the finalization parameters.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
filename (str): The name of the file to be saved.
|
|
75
|
+
target_names (list[str]): A list of names for the target variables.
|
|
76
|
+
"""
|
|
77
|
+
super().__init__(filename=filename)
|
|
78
|
+
safe_names = [_validate_string(string=target_name, attribute_name="All target names") for target_name in target_names]
|
|
79
|
+
self.target_names = safe_names
|
|
80
|
+
self.task = MLTaskKeys.MULTITARGET_REGRESSION
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class FinalizeBinaryClassification(_FinalizeModelTraining):
|
|
84
|
+
"""Parameters for finalizing a binary classification model."""
|
|
85
|
+
def __init__(self,
|
|
86
|
+
filename: str,
|
|
87
|
+
target_name: str,
|
|
88
|
+
classification_threshold: float,
|
|
89
|
+
class_map: dict[str,int]
|
|
90
|
+
) -> None:
|
|
91
|
+
"""Initializes the finalization parameters.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
filename (str): The name of the file to be saved.
|
|
95
|
+
target_name (str): The name of the target variable.
|
|
96
|
+
classification_threshold (float): The cutoff threshold for classifying as the positive class.
|
|
97
|
+
class_map (dict[str,int]): A dictionary mapping class names (str)
|
|
98
|
+
to their integer representations (e.g., {'cat': 0, 'dog': 1}).
|
|
99
|
+
"""
|
|
100
|
+
super().__init__(filename=filename)
|
|
101
|
+
self.target_name = _validate_string(string=target_name, attribute_name="Target name")
|
|
102
|
+
self.classification_threshold = _validate_threshold(classification_threshold)
|
|
103
|
+
self.class_map = _validate_class_map(class_map)
|
|
104
|
+
self.task = MLTaskKeys.BINARY_CLASSIFICATION
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class FinalizeMultiClassClassification(_FinalizeModelTraining):
|
|
108
|
+
"""Parameters for finalizing a multi-class classification model."""
|
|
109
|
+
def __init__(self,
|
|
110
|
+
filename: str,
|
|
111
|
+
target_name: str,
|
|
112
|
+
class_map: dict[str,int]
|
|
113
|
+
) -> None:
|
|
114
|
+
"""Initializes the finalization parameters.
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
filename (str): The name of the file to be saved.
|
|
118
|
+
target_name (str): The name of the target variable.
|
|
119
|
+
class_map (dict[str,int]): A dictionary mapping class names (str)
|
|
120
|
+
to their integer representations (e.g., {'cat': 0, 'dog': 1}).
|
|
121
|
+
"""
|
|
122
|
+
super().__init__(filename=filename)
|
|
123
|
+
self.target_name = _validate_string(string=target_name, attribute_name="Target name")
|
|
124
|
+
self.class_map = _validate_class_map(class_map)
|
|
125
|
+
self.task = MLTaskKeys.MULTICLASS_CLASSIFICATION
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class FinalizeBinaryImageClassification(_FinalizeModelTraining):
|
|
129
|
+
"""Parameters for finalizing a binary image classification model."""
|
|
130
|
+
def __init__(self,
|
|
131
|
+
filename: str,
|
|
132
|
+
classification_threshold: float,
|
|
133
|
+
class_map: dict[str,int]
|
|
134
|
+
) -> None:
|
|
135
|
+
"""Initializes the finalization parameters.
|
|
136
|
+
|
|
137
|
+
Args:
|
|
138
|
+
filename (str): The name of the file to be saved.
|
|
139
|
+
classification_threshold (float): The cutoff threshold for
|
|
140
|
+
classifying as the positive class.
|
|
141
|
+
class_map (dict[str,int]): A dictionary mapping class names (str)
|
|
142
|
+
to their integer representations (e.g., {'cat': 0, 'dog': 1}).
|
|
143
|
+
"""
|
|
144
|
+
super().__init__(filename=filename)
|
|
145
|
+
self.classification_threshold = _validate_threshold(classification_threshold)
|
|
146
|
+
self.class_map = _validate_class_map(class_map)
|
|
147
|
+
self.task = MLTaskKeys.BINARY_IMAGE_CLASSIFICATION
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
class FinalizeMultiClassImageClassification(_FinalizeModelTraining):
|
|
151
|
+
"""Parameters for finalizing a multi-class image classification model."""
|
|
152
|
+
def __init__(self,
|
|
153
|
+
filename: str,
|
|
154
|
+
class_map: dict[str,int]
|
|
155
|
+
) -> None:
|
|
156
|
+
"""Initializes the finalization parameters.
|
|
157
|
+
|
|
158
|
+
Args:
|
|
159
|
+
filename (str): The name of the file to be saved.
|
|
160
|
+
class_map (dict[str,int]): A dictionary mapping class names (str)
|
|
161
|
+
to their integer representations (e.g., {'cat': 0, 'dog': 1}).
|
|
162
|
+
"""
|
|
163
|
+
super().__init__(filename=filename)
|
|
164
|
+
self.class_map = _validate_class_map(class_map)
|
|
165
|
+
self.task = MLTaskKeys.MULTICLASS_IMAGE_CLASSIFICATION
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class FinalizeMultiLabelBinaryClassification(_FinalizeModelTraining):
|
|
169
|
+
"""Parameters for finalizing a multi-label binary classification model."""
|
|
170
|
+
def __init__(self,
|
|
171
|
+
filename: str,
|
|
172
|
+
target_names: list[str],
|
|
173
|
+
classification_threshold: float,
|
|
174
|
+
) -> None:
|
|
175
|
+
"""Initializes the finalization parameters.
|
|
176
|
+
|
|
177
|
+
Args:
|
|
178
|
+
filename (str): The name of the file to be saved.
|
|
179
|
+
target_names (list[str]): A list of names for the target variables.
|
|
180
|
+
classification_threshold (float): The cutoff threshold for classifying as the positive class.
|
|
181
|
+
"""
|
|
182
|
+
super().__init__(filename=filename)
|
|
183
|
+
safe_names = [_validate_string(string=target_name, attribute_name="All target names") for target_name in target_names]
|
|
184
|
+
self.target_names = safe_names
|
|
185
|
+
self.classification_threshold = _validate_threshold(classification_threshold)
|
|
186
|
+
self.task = MLTaskKeys.MULTILABEL_BINARY_CLASSIFICATION
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
class FinalizeBinarySegmentation(_FinalizeModelTraining):
|
|
190
|
+
"""Parameters for finalizing a binary segmentation model."""
|
|
191
|
+
def __init__(self,
|
|
192
|
+
filename: str,
|
|
193
|
+
class_map: dict[str,int],
|
|
194
|
+
classification_threshold: float,
|
|
195
|
+
) -> None:
|
|
196
|
+
"""Initializes the finalization parameters.
|
|
197
|
+
|
|
198
|
+
Args:
|
|
199
|
+
filename (str): The name of the file to be saved.
|
|
200
|
+
classification_threshold (float): The cutoff threshold for classifying as the positive class (mask).
|
|
201
|
+
"""
|
|
202
|
+
super().__init__(filename=filename)
|
|
203
|
+
self.classification_threshold = _validate_threshold(classification_threshold)
|
|
204
|
+
self.class_map = _validate_class_map(class_map)
|
|
205
|
+
self.task = MLTaskKeys.BINARY_SEGMENTATION
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
class FinalizeMultiClassSegmentation(_FinalizeModelTraining):
|
|
209
|
+
"""Parameters for finalizing a multi-class segmentation model."""
|
|
210
|
+
def __init__(self,
|
|
211
|
+
filename: str,
|
|
212
|
+
class_map: dict[str,int]
|
|
213
|
+
) -> None:
|
|
214
|
+
"""Initializes the finalization parameters.
|
|
215
|
+
|
|
216
|
+
Args:
|
|
217
|
+
filename (str): The name of the file to be saved.
|
|
218
|
+
"""
|
|
219
|
+
super().__init__(filename=filename)
|
|
220
|
+
self.class_map = _validate_class_map(class_map)
|
|
221
|
+
self.task = MLTaskKeys.MULTICLASS_SEGMENTATION
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
class FinalizeObjectDetection(_FinalizeModelTraining):
|
|
225
|
+
"""Parameters for finalizing an object detection model."""
|
|
226
|
+
def __init__(self,
|
|
227
|
+
filename: str,
|
|
228
|
+
class_map: dict[str,int]
|
|
229
|
+
) -> None:
|
|
230
|
+
"""Initializes the finalization parameters.
|
|
231
|
+
|
|
232
|
+
Args:
|
|
233
|
+
filename (str): The name of the file to be saved.
|
|
234
|
+
"""
|
|
235
|
+
super().__init__(filename=filename)
|
|
236
|
+
self.class_map = _validate_class_map(class_map)
|
|
237
|
+
self.task = MLTaskKeys.OBJECT_DETECTION
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
class FinalizeSequenceSequencePrediction(_FinalizeModelTraining):
|
|
241
|
+
"""Parameters for finalizing a sequence-to-sequence prediction model."""
|
|
242
|
+
def __init__(self,
|
|
243
|
+
filename: str,
|
|
244
|
+
last_training_sequence: np.ndarray,
|
|
245
|
+
) -> None:
|
|
246
|
+
"""Initializes the finalization parameters.
|
|
247
|
+
|
|
248
|
+
Args:
|
|
249
|
+
filename (str): The name of the file to be saved.
|
|
250
|
+
last_training_sequence (np.ndarray): The last sequence from the training data, needed to start predictions.
|
|
251
|
+
"""
|
|
252
|
+
super().__init__(filename=filename)
|
|
253
|
+
|
|
254
|
+
if not isinstance(last_training_sequence, np.ndarray):
|
|
255
|
+
_LOGGER.error(f"The last training sequence must be a 1D numpy array, got {type(last_training_sequence)}.")
|
|
256
|
+
raise TypeError()
|
|
257
|
+
|
|
258
|
+
if last_training_sequence.ndim == 1:
|
|
259
|
+
# It's already 1D, (N,). This is valid.
|
|
260
|
+
self.initial_sequence = last_training_sequence
|
|
261
|
+
elif last_training_sequence.ndim == 2:
|
|
262
|
+
# Handle both (1, N) and (N, 1)
|
|
263
|
+
if last_training_sequence.shape[0] == 1:
|
|
264
|
+
self.initial_sequence = last_training_sequence.flatten()
|
|
265
|
+
elif last_training_sequence.shape[1] == 1:
|
|
266
|
+
self.initial_sequence = last_training_sequence.flatten()
|
|
267
|
+
else:
|
|
268
|
+
_LOGGER.error(f"The last training sequence must be a 1D numpy array, got shape {last_training_sequence.shape}.")
|
|
269
|
+
raise ValueError()
|
|
270
|
+
else:
|
|
271
|
+
# It's 3D or more, which is not supported
|
|
272
|
+
_LOGGER.error(f"The last training sequence must be a 1D numpy array, got shape {last_training_sequence.shape}.")
|
|
273
|
+
raise ValueError()
|
|
274
|
+
|
|
275
|
+
# Save the length of the validated 1D sequence
|
|
276
|
+
self.sequence_length = len(self.initial_sequence) # type: ignore
|
|
277
|
+
self.task = MLTaskKeys.SEQUENCE_SEQUENCE
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
class FinalizeSequenceValuePrediction(_FinalizeModelTraining):
|
|
281
|
+
"""Parameters for finalizing a sequence-to-value prediction model."""
|
|
282
|
+
def __init__(self,
|
|
283
|
+
filename: str,
|
|
284
|
+
last_training_sequence: np.ndarray,
|
|
285
|
+
) -> None:
|
|
286
|
+
"""Initializes the finalization parameters.
|
|
287
|
+
|
|
288
|
+
Args:
|
|
289
|
+
filename (str): The name of the file to be saved.
|
|
290
|
+
last_training_sequence (np.ndarray): The last sequence from the training data, needed to start predictions.
|
|
291
|
+
"""
|
|
292
|
+
super().__init__(filename=filename)
|
|
293
|
+
|
|
294
|
+
if not isinstance(last_training_sequence, np.ndarray):
|
|
295
|
+
_LOGGER.error(f"The last training sequence must be a 1D numpy array, got {type(last_training_sequence)}.")
|
|
296
|
+
raise TypeError()
|
|
297
|
+
|
|
298
|
+
if last_training_sequence.ndim == 1:
|
|
299
|
+
# It's already 1D, (N,). This is valid.
|
|
300
|
+
self.initial_sequence = last_training_sequence
|
|
301
|
+
elif last_training_sequence.ndim == 2:
|
|
302
|
+
# Handle both (1, N) and (N, 1)
|
|
303
|
+
if last_training_sequence.shape[0] == 1:
|
|
304
|
+
self.initial_sequence = last_training_sequence.flatten()
|
|
305
|
+
elif last_training_sequence.shape[1] == 1:
|
|
306
|
+
self.initial_sequence = last_training_sequence.flatten()
|
|
307
|
+
else:
|
|
308
|
+
_LOGGER.error(f"The last training sequence must be a 1D numpy array, got shape {last_training_sequence.shape}.")
|
|
309
|
+
raise ValueError()
|
|
310
|
+
else:
|
|
311
|
+
# It's 3D or more, which is not supported
|
|
312
|
+
_LOGGER.error(f"The last training sequence must be a 1D numpy array, got shape {last_training_sequence.shape}.")
|
|
313
|
+
raise ValueError()
|
|
314
|
+
|
|
315
|
+
# Save the length of the validated 1D sequence
|
|
316
|
+
self.sequence_length = len(self.initial_sequence) # type: ignore
|
|
317
|
+
self.task = MLTaskKeys.SEQUENCE_VALUE
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def _validate_string(string: str, attribute_name: str, extension: Optional[str]=None) -> str:
|
|
321
|
+
"""Helper for finalize classes"""
|
|
322
|
+
if not isinstance(string, str):
|
|
323
|
+
_LOGGER.error(f"{attribute_name} must be a string.")
|
|
324
|
+
raise TypeError()
|
|
325
|
+
|
|
326
|
+
if extension:
|
|
327
|
+
safe_name = sanitize_filename(string)
|
|
328
|
+
|
|
329
|
+
if not safe_name.endswith(extension):
|
|
330
|
+
safe_name += extension
|
|
331
|
+
else:
|
|
332
|
+
safe_name = string
|
|
333
|
+
|
|
334
|
+
return safe_name
|
|
335
|
+
|
|
336
|
+
def _validate_threshold(threshold: float):
|
|
337
|
+
"""Helper for finalize classes"""
|
|
338
|
+
if not isinstance(threshold, float):
|
|
339
|
+
_LOGGER.error(f"Classification threshold must be a float.")
|
|
340
|
+
raise TypeError()
|
|
341
|
+
elif threshold < 0.1 or threshold > 0.9:
|
|
342
|
+
_LOGGER.error(f"Classification threshold must be in the range [0.1, 0.9]")
|
|
343
|
+
raise ValueError()
|
|
344
|
+
|
|
345
|
+
return threshold
|
|
346
|
+
|
|
347
|
+
def _validate_class_map(map_dict: dict[str, int]):
|
|
348
|
+
"""Helper for finalize classes"""
|
|
349
|
+
if not isinstance(map_dict, dict):
|
|
350
|
+
_LOGGER.error(f"Class map must be a dictionary, but got {type(map_dict)}.")
|
|
351
|
+
raise TypeError()
|
|
352
|
+
|
|
353
|
+
if not map_dict:
|
|
354
|
+
_LOGGER.error("Class map dictionary cannot be empty.")
|
|
355
|
+
raise ValueError()
|
|
356
|
+
|
|
357
|
+
for key, val in map_dict.items():
|
|
358
|
+
if not isinstance(key, str):
|
|
359
|
+
_LOGGER.error(f"All keys in the class map must be strings, but found key: {key} ({type(key)}).")
|
|
360
|
+
raise TypeError()
|
|
361
|
+
if not isinstance(val, int):
|
|
362
|
+
_LOGGER.error(f"All values in the class map must be integers, but for key '{key}' found value: {val} ({type(val)}).")
|
|
363
|
+
raise TypeError()
|
|
364
|
+
|
|
365
|
+
return map_dict
|
|
366
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from .._core import _imprimir_disponibles
|
|
2
|
+
|
|
3
|
+
_GRUPOS = [
|
|
4
|
+
# --- Metrics Formats ---
|
|
5
|
+
"FormatRegressionMetrics",
|
|
6
|
+
"FormatMultiTargetRegressionMetrics",
|
|
7
|
+
"FormatBinaryClassificationMetrics",
|
|
8
|
+
"FormatMultiClassClassificationMetrics",
|
|
9
|
+
"FormatBinaryImageClassificationMetrics",
|
|
10
|
+
"FormatMultiClassImageClassificationMetrics",
|
|
11
|
+
"FormatMultiLabelBinaryClassificationMetrics",
|
|
12
|
+
"FormatBinarySegmentationMetrics",
|
|
13
|
+
"FormatMultiClassSegmentationMetrics",
|
|
14
|
+
"FormatSequenceValueMetrics",
|
|
15
|
+
"FormatSequenceSequenceMetrics",
|
|
16
|
+
|
|
17
|
+
# --- Finalize Configs ---
|
|
18
|
+
"FinalizeBinaryClassification",
|
|
19
|
+
"FinalizeBinarySegmentation",
|
|
20
|
+
"FinalizeBinaryImageClassification",
|
|
21
|
+
"FinalizeMultiClassClassification",
|
|
22
|
+
"FinalizeMultiClassImageClassification",
|
|
23
|
+
"FinalizeMultiClassSegmentation",
|
|
24
|
+
"FinalizeMultiLabelBinaryClassification",
|
|
25
|
+
"FinalizeMultiTargetRegression",
|
|
26
|
+
"FinalizeRegression",
|
|
27
|
+
"FinalizeObjectDetection",
|
|
28
|
+
"FinalizeSequenceSequencePrediction",
|
|
29
|
+
"FinalizeSequenceValuePrediction",
|
|
30
|
+
|
|
31
|
+
# --- Model Parameter Configs ---
|
|
32
|
+
"DragonMLPParams",
|
|
33
|
+
"DragonAttentionMLPParams",
|
|
34
|
+
"DragonMultiHeadAttentionNetParams",
|
|
35
|
+
"DragonTabularTransformerParams",
|
|
36
|
+
"DragonGateParams",
|
|
37
|
+
"DragonNodeParams",
|
|
38
|
+
"DragonTabNetParams",
|
|
39
|
+
"DragonAutoIntParams",
|
|
40
|
+
|
|
41
|
+
# --- Training Config ---
|
|
42
|
+
"DragonTrainingConfig",
|
|
43
|
+
"DragonParetoConfig",
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
def info():
|
|
47
|
+
_imprimir_disponibles(_GRUPOS)
|