dragon-ml-toolbox 6.1.1__tar.gz → 6.2.0__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.
- {dragon_ml_toolbox-6.1.1/dragon_ml_toolbox.egg-info → dragon_ml_toolbox-6.2.0}/PKG-INFO +1 -1
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0/dragon_ml_toolbox.egg-info}/PKG-INFO +1 -1
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/ML_callbacks.py +11 -3
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/ML_optimization.py +7 -7
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/SQL.py +5 -5
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/optimization_tools.py +5 -5
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/pyproject.toml +1 -1
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/LICENSE +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/LICENSE-THIRD-PARTY.md +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/README.md +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/dragon_ml_toolbox.egg-info/SOURCES.txt +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/dragon_ml_toolbox.egg-info/dependency_links.txt +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/dragon_ml_toolbox.egg-info/requires.txt +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/dragon_ml_toolbox.egg-info/top_level.txt +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/ETL_engineering.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/GUI_tools.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/MICE_imputation.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/ML_datasetmaster.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/ML_evaluation.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/ML_inference.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/ML_models.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/ML_trainer.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/PSO_optimization.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/RNN_forecast.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/VIF_factor.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/__init__.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/_logger.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/_script_info.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/custom_logger.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/data_exploration.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/ensemble_evaluation.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/ensemble_inference.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/ensemble_learning.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/handle_excel.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/keys.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/path_manager.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/ml_tools/utilities.py +0 -0
- {dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/setup.cfg +0 -0
|
@@ -201,7 +201,7 @@ class ModelCheckpoint(Callback):
|
|
|
201
201
|
mode (str): One of {'auto', 'min', 'max'}.
|
|
202
202
|
verbose (int): Verbosity mode.
|
|
203
203
|
"""
|
|
204
|
-
def __init__(self, save_dir: Union[str,Path], monitor: str = PyTorchLogKeys.VAL_LOSS,
|
|
204
|
+
def __init__(self, save_dir: Union[str,Path], checkpoint_name: Optional[str]=None, monitor: str = PyTorchLogKeys.VAL_LOSS,
|
|
205
205
|
save_best_only: bool = True, mode: Literal['auto', 'min', 'max']= 'auto', verbose: int = 0):
|
|
206
206
|
super().__init__()
|
|
207
207
|
self.save_dir = make_fullpath(save_dir, make=True, enforce="directory")
|
|
@@ -212,6 +212,7 @@ class ModelCheckpoint(Callback):
|
|
|
212
212
|
self.monitor = monitor
|
|
213
213
|
self.save_best_only = save_best_only
|
|
214
214
|
self.verbose = verbose
|
|
215
|
+
self.checkpoint_name = checkpoint_name
|
|
215
216
|
|
|
216
217
|
# State variables to be managed during training
|
|
217
218
|
self.saved_checkpoints = []
|
|
@@ -254,7 +255,10 @@ class ModelCheckpoint(Callback):
|
|
|
254
255
|
old_best_str = f"{self.best:.4f}" if self.best not in [np.inf, -np.inf] else "inf"
|
|
255
256
|
|
|
256
257
|
# Create a descriptive filename
|
|
257
|
-
|
|
258
|
+
if self.checkpoint_name is None:
|
|
259
|
+
filename = f"epoch_{epoch}-{self.monitor}_{current:.4f}.pth"
|
|
260
|
+
else:
|
|
261
|
+
filename = f"epoch{epoch}_{self.checkpoint_name}.pth"
|
|
258
262
|
new_filepath = self.save_dir / filename
|
|
259
263
|
|
|
260
264
|
if self.verbose > 0:
|
|
@@ -273,7 +277,11 @@ class ModelCheckpoint(Callback):
|
|
|
273
277
|
|
|
274
278
|
def _save_rolling_checkpoints(self, epoch, logs):
|
|
275
279
|
"""Saves the latest model and keeps only the most recent ones."""
|
|
276
|
-
|
|
280
|
+
current = logs.get(self.monitor)
|
|
281
|
+
if self.checkpoint_name is None:
|
|
282
|
+
filename = f"epoch_{epoch}-{self.monitor}_{current:.4f}.pth"
|
|
283
|
+
else:
|
|
284
|
+
filename = f"epoch{epoch}_{self.checkpoint_name}.pth"
|
|
277
285
|
filepath = self.save_dir / filename
|
|
278
286
|
|
|
279
287
|
if self.verbose > 0:
|
|
@@ -114,10 +114,10 @@ def create_pytorch_problem(
|
|
|
114
114
|
|
|
115
115
|
operators = [
|
|
116
116
|
SimulatedBinaryCrossOver(problem,
|
|
117
|
-
tournament_size=
|
|
118
|
-
eta=0.
|
|
117
|
+
tournament_size=3,
|
|
118
|
+
eta=0.6),
|
|
119
119
|
GaussianMutation(problem,
|
|
120
|
-
stdev=0.
|
|
120
|
+
stdev=0.4)
|
|
121
121
|
]
|
|
122
122
|
|
|
123
123
|
searcher_kwargs["operators"] = operators
|
|
@@ -240,7 +240,7 @@ def run_optimization(
|
|
|
240
240
|
|
|
241
241
|
# Process logger
|
|
242
242
|
if verbose:
|
|
243
|
-
_handle_pandas_log(pandas_logger, save_path=save_path)
|
|
243
|
+
_handle_pandas_log(pandas_logger, save_path=save_path, target_name=target_name)
|
|
244
244
|
|
|
245
245
|
_LOGGER.info(f"✅ Optimization complete. Best solution saved to '{csv_path.name}'")
|
|
246
246
|
return result_dict
|
|
@@ -293,15 +293,15 @@ def run_optimization(
|
|
|
293
293
|
|
|
294
294
|
# Process logger
|
|
295
295
|
if pandas_logger is not None:
|
|
296
|
-
_handle_pandas_log(pandas_logger, save_path=save_path)
|
|
296
|
+
_handle_pandas_log(pandas_logger, save_path=save_path, target_name=target_name)
|
|
297
297
|
|
|
298
298
|
_LOGGER.info(f"✅ Optimal solution space complete. Results saved to '{save_path}'")
|
|
299
299
|
return None
|
|
300
300
|
|
|
301
301
|
|
|
302
|
-
def _handle_pandas_log(logger: PandasLogger, save_path: Path):
|
|
302
|
+
def _handle_pandas_log(logger: PandasLogger, save_path: Path, target_name: str):
|
|
303
303
|
log_dataframe = logger.to_dataframe()
|
|
304
|
-
save_dataframe(df=log_dataframe, save_dir=save_path / "
|
|
304
|
+
save_dataframe(df=log_dataframe, save_dir=save_path / "EvolutionLogs", filename=target_name)
|
|
305
305
|
|
|
306
306
|
|
|
307
307
|
def info():
|
|
@@ -59,7 +59,7 @@ class DatabaseManager:
|
|
|
59
59
|
try:
|
|
60
60
|
self.conn = sqlite3.connect(self.db_path)
|
|
61
61
|
self.cursor = self.conn.cursor()
|
|
62
|
-
_LOGGER.info(f"
|
|
62
|
+
_LOGGER.info(f"❇️ Successfully connected to database: {self.db_path}")
|
|
63
63
|
return self
|
|
64
64
|
except sqlite3.Error as e:
|
|
65
65
|
_LOGGER.error(f"❌ Database connection failed: {e}")
|
|
@@ -99,7 +99,7 @@ class DatabaseManager:
|
|
|
99
99
|
|
|
100
100
|
query = f"CREATE TABLE {exists_clause} {table_name} ({columns_def})"
|
|
101
101
|
|
|
102
|
-
_LOGGER.info(f"
|
|
102
|
+
_LOGGER.info(f"➡️ Executing: {query}")
|
|
103
103
|
self.cursor.execute(query)
|
|
104
104
|
|
|
105
105
|
def insert_row(self, table_name: str, data: Dict[str, Any]):
|
|
@@ -192,7 +192,7 @@ class DatabaseManager:
|
|
|
192
192
|
query = f"INSERT INTO {table_name} ({columns}) VALUES ({placeholders})"
|
|
193
193
|
|
|
194
194
|
self.cursor.executemany(query, values_to_insert)
|
|
195
|
-
_LOGGER.info(f"
|
|
195
|
+
_LOGGER.info(f"➡️ Bulk inserted {len(values_to_insert)} rows into '{table_name}'.")
|
|
196
196
|
|
|
197
197
|
def insert_from_dataframe(self, table_name: str, df: pd.DataFrame, if_exists: Literal['fail', 'replace', 'append'] = 'append'):
|
|
198
198
|
"""
|
|
@@ -219,7 +219,7 @@ class DatabaseManager:
|
|
|
219
219
|
if_exists=if_exists,
|
|
220
220
|
index=False # Typically, we don't want to save the DataFrame index
|
|
221
221
|
)
|
|
222
|
-
_LOGGER.info(f"
|
|
222
|
+
_LOGGER.info(f"➡️ Wrote {len(df)} rows from DataFrame to table '{table_name}' using mode '{if_exists}'.")
|
|
223
223
|
|
|
224
224
|
def list_tables(self) -> List[str]:
|
|
225
225
|
"""Returns a list of all table names in the database."""
|
|
@@ -264,7 +264,7 @@ class DatabaseManager:
|
|
|
264
264
|
|
|
265
265
|
query = f"CREATE {unique_clause} INDEX IF NOT EXISTS {index_name} ON {table_name} ({column_name})"
|
|
266
266
|
|
|
267
|
-
_LOGGER.info(f"
|
|
267
|
+
_LOGGER.info(f"➡️ Executing: {query}")
|
|
268
268
|
self.cursor.execute(query)
|
|
269
269
|
|
|
270
270
|
|
|
@@ -29,24 +29,24 @@ def parse_lower_upper_bounds(source: dict[str,tuple[Any,Any]]):
|
|
|
29
29
|
return lower, upper
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
def plot_optimal_feature_distributions(results_dir: Union[str, Path]
|
|
32
|
+
def plot_optimal_feature_distributions(results_dir: Union[str, Path]):
|
|
33
33
|
"""
|
|
34
34
|
Analyzes optimization results and plots the distribution of optimal values for each feature.
|
|
35
35
|
|
|
36
36
|
For features with more than two unique values, this function generates a color-coded
|
|
37
37
|
Kernel Density Estimate (KDE) plot. For binary or constant features, it generates a bar plot
|
|
38
38
|
showing relative frequency.
|
|
39
|
+
|
|
40
|
+
Plots are saved in a subdirectory inside the source directory.
|
|
39
41
|
|
|
40
42
|
Parameters
|
|
41
43
|
----------
|
|
42
44
|
results_dir : str or Path
|
|
43
45
|
The path to the directory containing the optimization result CSV files.
|
|
44
|
-
save_dir : str or Path
|
|
45
|
-
The directory where the output plots will be saved.
|
|
46
46
|
"""
|
|
47
47
|
# Check results_dir and create output path
|
|
48
|
-
results_path = make_fullpath(results_dir)
|
|
49
|
-
output_path = make_fullpath(
|
|
48
|
+
results_path = make_fullpath(results_dir, enforce="directory")
|
|
49
|
+
output_path = make_fullpath(results_path / "DistributionPlots", make=True)
|
|
50
50
|
|
|
51
51
|
# Check that the directory contains csv files
|
|
52
52
|
list_csv_paths(results_path, verbose=False)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/dragon_ml_toolbox.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
{dragon_ml_toolbox-6.1.1 → dragon_ml_toolbox-6.2.0}/dragon_ml_toolbox.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|