dragon-ml-toolbox 14.3.1__py3-none-any.whl → 14.8.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.
Potentially problematic release.
This version of dragon-ml-toolbox might be problematic. Click here for more details.
- {dragon_ml_toolbox-14.3.1.dist-info → dragon_ml_toolbox-14.8.0.dist-info}/METADATA +2 -1
- {dragon_ml_toolbox-14.3.1.dist-info → dragon_ml_toolbox-14.8.0.dist-info}/RECORD +17 -16
- ml_tools/ML_configuration.py +116 -0
- ml_tools/ML_datasetmaster.py +42 -0
- ml_tools/ML_evaluation.py +208 -63
- ml_tools/ML_evaluation_multi.py +40 -10
- ml_tools/ML_trainer.py +38 -12
- ml_tools/ML_utilities.py +50 -1
- ml_tools/ML_vision_datasetmaster.py +198 -60
- ml_tools/ML_vision_models.py +15 -1
- ml_tools/ML_vision_transformers.py +151 -6
- ml_tools/ensemble_evaluation.py +53 -10
- ml_tools/keys.py +2 -1
- {dragon_ml_toolbox-14.3.1.dist-info → dragon_ml_toolbox-14.8.0.dist-info}/WHEEL +0 -0
- {dragon_ml_toolbox-14.3.1.dist-info → dragon_ml_toolbox-14.8.0.dist-info}/licenses/LICENSE +0 -0
- {dragon_ml_toolbox-14.3.1.dist-info → dragon_ml_toolbox-14.8.0.dist-info}/licenses/LICENSE-THIRD-PARTY.md +0 -0
- {dragon_ml_toolbox-14.3.1.dist-info → dragon_ml_toolbox-14.8.0.dist-info}/top_level.txt +0 -0
ml_tools/ensemble_evaluation.py
CHANGED
|
@@ -112,7 +112,7 @@ def evaluate_model_classification(
|
|
|
112
112
|
report_df = pd.DataFrame(report_dict).iloc[:-1, :].T
|
|
113
113
|
plt.figure(figsize=figsize)
|
|
114
114
|
sns.heatmap(report_df, annot=True, cmap=heatmap_cmap, fmt='.2f',
|
|
115
|
-
annot_kws={"size": base_fontsize - 4})
|
|
115
|
+
annot_kws={"size": base_fontsize - 4}, vmin=0.0, vmax=1.0)
|
|
116
116
|
plt.title(f"{model_name} - {target_name}", fontsize=base_fontsize)
|
|
117
117
|
plt.xticks(fontsize=base_fontsize - 2)
|
|
118
118
|
plt.yticks(fontsize=base_fontsize - 2)
|
|
@@ -133,6 +133,7 @@ def evaluate_model_classification(
|
|
|
133
133
|
normalize="true",
|
|
134
134
|
ax=ax
|
|
135
135
|
)
|
|
136
|
+
disp.im_.set_clim(vmin=0.0, vmax=1.0)
|
|
136
137
|
|
|
137
138
|
ax.set_title(f"{model_name} - {target_name}", fontsize=base_fontsize)
|
|
138
139
|
ax.tick_params(axis='both', labelsize=base_fontsize)
|
|
@@ -327,7 +328,8 @@ def plot_calibration_curve(
|
|
|
327
328
|
target_name: str,
|
|
328
329
|
figure_size: tuple = (10, 10),
|
|
329
330
|
base_fontsize: int = 24,
|
|
330
|
-
n_bins: int = 15
|
|
331
|
+
n_bins: int = 15,
|
|
332
|
+
line_color: str = 'darkorange'
|
|
331
333
|
) -> plt.Figure: # type: ignore
|
|
332
334
|
"""
|
|
333
335
|
Plots the calibration curve (reliability diagram) for a classifier.
|
|
@@ -348,22 +350,63 @@ def plot_calibration_curve(
|
|
|
348
350
|
"""
|
|
349
351
|
fig, ax = plt.subplots(figsize=figure_size)
|
|
350
352
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
353
|
+
# --- Step 1: Get probabilities from the estimator ---
|
|
354
|
+
# We do this manually so we can pass them to from_predictions
|
|
355
|
+
try:
|
|
356
|
+
y_prob = model.predict_proba(x_test)
|
|
357
|
+
# Use probabilities for the positive class (assuming binary)
|
|
358
|
+
y_score = y_prob[:, 1]
|
|
359
|
+
except Exception as e:
|
|
360
|
+
_LOGGER.error(f"Could not get probabilities from model: {e}")
|
|
361
|
+
plt.close(fig)
|
|
362
|
+
return fig # Return empty figure
|
|
363
|
+
|
|
364
|
+
# --- Step 2: Get binned data *without* plotting ---
|
|
365
|
+
with plt.ioff():
|
|
366
|
+
fig_temp, ax_temp = plt.subplots()
|
|
367
|
+
cal_display_temp = CalibrationDisplay.from_predictions(
|
|
368
|
+
y_test,
|
|
369
|
+
y_score,
|
|
370
|
+
n_bins=n_bins,
|
|
371
|
+
ax=ax_temp,
|
|
372
|
+
name="temp"
|
|
373
|
+
)
|
|
374
|
+
line_x, line_y = cal_display_temp.line_.get_data() # type: ignore
|
|
375
|
+
plt.close(fig_temp)
|
|
376
|
+
|
|
377
|
+
# --- Step 3: Build the plot from scratch on ax ---
|
|
378
|
+
|
|
379
|
+
# 3a. Plot the ideal diagonal line
|
|
380
|
+
ax.plot([0, 1], [0, 1], 'k--', label='Perfectly calibrated')
|
|
381
|
+
|
|
382
|
+
# 3b. Use regplot for the regression line and its CI
|
|
383
|
+
sns.regplot(
|
|
384
|
+
x=line_x,
|
|
385
|
+
y=line_y,
|
|
386
|
+
ax=ax,
|
|
387
|
+
scatter=False, # No scatter dots
|
|
388
|
+
label=f"Calibration Curve ({n_bins} bins)",
|
|
389
|
+
line_kws={
|
|
390
|
+
'color': line_color,
|
|
391
|
+
'linestyle': '--',
|
|
392
|
+
'linewidth': 2
|
|
393
|
+
}
|
|
357
394
|
)
|
|
358
395
|
|
|
396
|
+
# --- Step 4: Apply original formatting ---
|
|
359
397
|
ax.set_title(f"{model_name} - Reliability Curve for {target_name}", fontsize=base_fontsize)
|
|
360
398
|
ax.tick_params(axis='both', labelsize=base_fontsize - 2)
|
|
361
399
|
ax.set_xlabel("Mean Predicted Probability", fontsize=base_fontsize)
|
|
362
400
|
ax.set_ylabel("Fraction of Positives", fontsize=base_fontsize)
|
|
363
|
-
|
|
401
|
+
|
|
402
|
+
# Set limits
|
|
403
|
+
ax.set_ylim(0.0, 1.0)
|
|
404
|
+
ax.set_xlim(0.0, 1.0)
|
|
405
|
+
|
|
406
|
+
ax.legend(fontsize=base_fontsize - 4, loc='lower right')
|
|
364
407
|
fig.tight_layout()
|
|
365
408
|
|
|
366
|
-
# Save figure
|
|
409
|
+
# --- Step 5: Save figure (using original logic) ---
|
|
367
410
|
save_path = make_fullpath(save_dir, make=True)
|
|
368
411
|
sanitized_target_name = sanitize_filename(target_name)
|
|
369
412
|
full_save_path = save_path / f"Calibration_Plot_{sanitized_target_name}.svg"
|
ml_tools/keys.py
CHANGED
|
@@ -104,8 +104,9 @@ class VisionTransformRecipeKeys:
|
|
|
104
104
|
TASK = "task"
|
|
105
105
|
PIPELINE = "pipeline"
|
|
106
106
|
NAME = "name"
|
|
107
|
-
KWARGS = "
|
|
107
|
+
KWARGS = "kwargs"
|
|
108
108
|
PRE_TRANSFORMS = "pre_transforms"
|
|
109
|
+
|
|
109
110
|
RESIZE_SIZE = "resize_size"
|
|
110
111
|
CROP_SIZE = "crop_size"
|
|
111
112
|
MEAN = "mean"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|