ins-pricing 0.1.7__py3-none-any.whl → 0.1.9__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.
- ins_pricing/modelling/BayesOpt_entry.py +68 -10
- ins_pricing/modelling/BayesOpt_incremental.py +46 -6
- ins_pricing/modelling/bayesopt/core.py +80 -7
- ins_pricing/modelling/bayesopt/trainers.py +3 -3
- ins_pricing/modelling/plotting/diagnostics.py +24 -0
- ins_pricing/setup.py +1 -1
- {ins_pricing-0.1.7.dist-info → ins_pricing-0.1.9.dist-info}/METADATA +1 -1
- {ins_pricing-0.1.7.dist-info → ins_pricing-0.1.9.dist-info}/RECORD +10 -10
- {ins_pricing-0.1.7.dist-info → ins_pricing-0.1.9.dist-info}/WHEEL +0 -0
- {ins_pricing-0.1.7.dist-info → ins_pricing-0.1.9.dist-info}/top_level.txt +0 -0
|
@@ -250,22 +250,46 @@ def _plot_curves_for_model(model: ropt.BayesOptModel, trained_keys: List[str], c
|
|
|
250
250
|
[m for m in trained_keys if m in PLOT_MODEL_LABELS]
|
|
251
251
|
)
|
|
252
252
|
|
|
253
|
-
if oneway_enabled:
|
|
254
|
-
model.plot_oneway(n_bins=n_bins)
|
|
255
|
-
|
|
256
|
-
if not available_models:
|
|
257
|
-
return
|
|
258
|
-
|
|
259
253
|
lift_models = plot_cfg.get("lift_models")
|
|
260
254
|
if lift_models is None:
|
|
261
|
-
lift_models = [
|
|
262
|
-
m for m, enabled in legacy_lift_flags.items() if enabled]
|
|
255
|
+
lift_models = [m for m, enabled in legacy_lift_flags.items() if enabled]
|
|
263
256
|
if not lift_models:
|
|
264
257
|
lift_models = available_models
|
|
265
258
|
lift_models = dedupe_preserve_order(
|
|
266
259
|
[m for m in lift_models if m in available_models]
|
|
267
260
|
)
|
|
268
261
|
|
|
262
|
+
if oneway_enabled:
|
|
263
|
+
oneway_pred = bool(plot_cfg.get("oneway_pred", False))
|
|
264
|
+
oneway_pred_models = plot_cfg.get("oneway_pred_models")
|
|
265
|
+
pred_plotted = False
|
|
266
|
+
if oneway_pred:
|
|
267
|
+
if oneway_pred_models is None:
|
|
268
|
+
oneway_pred_models = lift_models or available_models
|
|
269
|
+
oneway_pred_models = dedupe_preserve_order(
|
|
270
|
+
[m for m in oneway_pred_models if m in available_models]
|
|
271
|
+
)
|
|
272
|
+
for model_key in oneway_pred_models:
|
|
273
|
+
label, pred_nme = PLOT_MODEL_LABELS[model_key]
|
|
274
|
+
if pred_nme not in model.train_data.columns:
|
|
275
|
+
print(
|
|
276
|
+
f"[Oneway] Missing prediction column '{pred_nme}'; skip.",
|
|
277
|
+
flush=True,
|
|
278
|
+
)
|
|
279
|
+
continue
|
|
280
|
+
model.plot_oneway(
|
|
281
|
+
n_bins=n_bins,
|
|
282
|
+
pred_col=pred_nme,
|
|
283
|
+
pred_label=label,
|
|
284
|
+
plot_subdir="oneway/post",
|
|
285
|
+
)
|
|
286
|
+
pred_plotted = True
|
|
287
|
+
if not oneway_pred or not pred_plotted:
|
|
288
|
+
model.plot_oneway(n_bins=n_bins, plot_subdir="oneway/post")
|
|
289
|
+
|
|
290
|
+
if not available_models:
|
|
291
|
+
return
|
|
292
|
+
|
|
269
293
|
for model_key in lift_models:
|
|
270
294
|
label, pred_nme = PLOT_MODEL_LABELS[model_key]
|
|
271
295
|
model.plot_lift(model_label=label, pred_nme=pred_nme, n_bins=n_bins)
|
|
@@ -302,10 +326,10 @@ def _plot_loss_curve_for_trainer(model_name: str, trainer) -> None:
|
|
|
302
326
|
return
|
|
303
327
|
try:
|
|
304
328
|
plot_dir = trainer.output.plot_path(
|
|
305
|
-
f"loss_{model_name}_{trainer.model_name_prefix}.png"
|
|
329
|
+
f"{model_name}/loss/loss_{model_name}_{trainer.model_name_prefix}.png"
|
|
306
330
|
)
|
|
307
331
|
except Exception:
|
|
308
|
-
default_dir = Path("plot")
|
|
332
|
+
default_dir = Path("plot") / model_name / "loss"
|
|
309
333
|
default_dir.mkdir(parents=True, exist_ok=True)
|
|
310
334
|
plot_dir = str(
|
|
311
335
|
default_dir / f"loss_{model_name}_{trainer.model_name_prefix}.png")
|
|
@@ -359,6 +383,24 @@ def train_from_config(args: argparse.Namespace) -> None:
|
|
|
359
383
|
dist_world_size = _safe_int_env("WORLD_SIZE", 1)
|
|
360
384
|
dist_rank = _safe_int_env("RANK", 0)
|
|
361
385
|
dist_active = dist_world_size > 1
|
|
386
|
+
def _ddp_barrier(reason: str) -> None:
|
|
387
|
+
if not dist_active:
|
|
388
|
+
return
|
|
389
|
+
torch_mod = getattr(ropt, "torch", None)
|
|
390
|
+
dist_mod = getattr(torch_mod, "distributed", None)
|
|
391
|
+
if dist_mod is None:
|
|
392
|
+
return
|
|
393
|
+
try:
|
|
394
|
+
if not getattr(dist_mod, "is_available", lambda: False)():
|
|
395
|
+
return
|
|
396
|
+
if not dist_mod.is_initialized():
|
|
397
|
+
ddp_ok, _, _, _ = ropt.DistributedUtils.setup_ddp()
|
|
398
|
+
if not ddp_ok or not dist_mod.is_initialized():
|
|
399
|
+
return
|
|
400
|
+
dist_mod.barrier()
|
|
401
|
+
except Exception as exc:
|
|
402
|
+
print(f"[DDP] barrier failed during {reason}: {exc}", flush=True)
|
|
403
|
+
raise
|
|
362
404
|
|
|
363
405
|
data_dir = Path(cfg["data_dir"])
|
|
364
406
|
data_dir.mkdir(parents=True, exist_ok=True)
|
|
@@ -486,6 +528,19 @@ def train_from_config(args: argparse.Namespace) -> None:
|
|
|
486
528
|
reuse_best_params=reuse_best_params,
|
|
487
529
|
)
|
|
488
530
|
|
|
531
|
+
if plot_requested:
|
|
532
|
+
plot_cfg = cfg.get("plot", {})
|
|
533
|
+
legacy_lift_flags = {
|
|
534
|
+
"glm": cfg.get("plot_lift_glm", False),
|
|
535
|
+
"xgb": cfg.get("plot_lift_xgb", False),
|
|
536
|
+
"resn": cfg.get("plot_lift_resn", False),
|
|
537
|
+
"ft": cfg.get("plot_lift_ft", False),
|
|
538
|
+
}
|
|
539
|
+
plot_enabled = plot_cfg.get("enable", any(legacy_lift_flags.values()))
|
|
540
|
+
if plot_enabled and plot_cfg.get("pre_oneway", False) and plot_cfg.get("oneway", True):
|
|
541
|
+
n_bins = int(plot_cfg.get("n_bins", 10))
|
|
542
|
+
model.plot_oneway(n_bins=n_bins, plot_subdir="oneway/pre")
|
|
543
|
+
|
|
489
544
|
if "all" in args.model_keys:
|
|
490
545
|
requested_keys = ["glm", "xgb", "resn", "ft", "gnn"]
|
|
491
546
|
else:
|
|
@@ -536,6 +591,7 @@ def train_from_config(args: argparse.Namespace) -> None:
|
|
|
536
591
|
print(
|
|
537
592
|
f"[Rank {dist_rank}] Skip {model_name}/{key} because trainer is not DDP-enabled."
|
|
538
593
|
)
|
|
594
|
+
_ddp_barrier(f"skip_non_ddp_{model_name}_{key}")
|
|
539
595
|
continue
|
|
540
596
|
|
|
541
597
|
print(
|
|
@@ -545,6 +601,8 @@ def train_from_config(args: argparse.Namespace) -> None:
|
|
|
545
601
|
_plot_loss_curve_for_trainer(model_name, model.trainers[key])
|
|
546
602
|
if key in PYTORCH_TRAINERS:
|
|
547
603
|
ropt.free_cuda()
|
|
604
|
+
if dist_active and not trainer_uses_ddp:
|
|
605
|
+
_ddp_barrier(f"finish_non_ddp_{model_name}_{key}")
|
|
548
606
|
executed_keys.append(key)
|
|
549
607
|
|
|
550
608
|
if not executed_keys:
|
|
@@ -285,16 +285,43 @@ def _plot_curves_for_model(model: ropt.BayesOptModel, trained: List[str], cfg: D
|
|
|
285
285
|
oneway_enabled = plot_cfg.get("oneway", True)
|
|
286
286
|
available = dedupe_preserve_order([k for k in trained if k in PLOT_MODEL_LABELS])
|
|
287
287
|
|
|
288
|
-
if oneway_enabled:
|
|
289
|
-
model.plot_oneway(n_bins=n_bins)
|
|
290
|
-
if not available:
|
|
291
|
-
return
|
|
292
|
-
|
|
293
288
|
lift_models = plot_cfg.get("lift_models")
|
|
294
289
|
if lift_models is None:
|
|
295
|
-
lift_models = [m for m, flag in legacy_flags.items() if flag]
|
|
290
|
+
lift_models = [m for m, flag in legacy_flags.items() if flag]
|
|
291
|
+
if not lift_models:
|
|
292
|
+
lift_models = available
|
|
296
293
|
lift_models = dedupe_preserve_order([m for m in lift_models if m in available])
|
|
297
294
|
|
|
295
|
+
if oneway_enabled:
|
|
296
|
+
oneway_pred = bool(plot_cfg.get("oneway_pred", False))
|
|
297
|
+
oneway_pred_models = plot_cfg.get("oneway_pred_models")
|
|
298
|
+
pred_plotted = False
|
|
299
|
+
if oneway_pred:
|
|
300
|
+
if oneway_pred_models is None:
|
|
301
|
+
oneway_pred_models = lift_models or available
|
|
302
|
+
oneway_pred_models = dedupe_preserve_order(
|
|
303
|
+
[m for m in oneway_pred_models if m in available]
|
|
304
|
+
)
|
|
305
|
+
for model_key in oneway_pred_models:
|
|
306
|
+
label, pred_nme = PLOT_MODEL_LABELS[model_key]
|
|
307
|
+
if pred_nme not in model.train_data.columns:
|
|
308
|
+
print(
|
|
309
|
+
f"[Oneway] Missing prediction column '{pred_nme}'; skip.",
|
|
310
|
+
flush=True,
|
|
311
|
+
)
|
|
312
|
+
continue
|
|
313
|
+
model.plot_oneway(
|
|
314
|
+
n_bins=n_bins,
|
|
315
|
+
pred_col=pred_nme,
|
|
316
|
+
pred_label=label,
|
|
317
|
+
plot_subdir="oneway/post",
|
|
318
|
+
)
|
|
319
|
+
pred_plotted = True
|
|
320
|
+
if not oneway_pred or not pred_plotted:
|
|
321
|
+
model.plot_oneway(n_bins=n_bins, plot_subdir="oneway/post")
|
|
322
|
+
if not available:
|
|
323
|
+
return
|
|
324
|
+
|
|
298
325
|
for key in lift_models:
|
|
299
326
|
label, pred_nme = PLOT_MODEL_LABELS[key]
|
|
300
327
|
model.plot_lift(model_label=label, pred_nme=pred_nme, n_bins=n_bins)
|
|
@@ -558,6 +585,19 @@ class IncrementalUpdateRunner:
|
|
|
558
585
|
infer_categorical_max_ratio=float(self.cfg.get("infer_categorical_max_ratio", 0.05)),
|
|
559
586
|
)
|
|
560
587
|
|
|
588
|
+
if self.plot_requested and not self.args.dry_run:
|
|
589
|
+
plot_cfg = self.cfg.get("plot", {})
|
|
590
|
+
legacy_flags = {
|
|
591
|
+
"glm": self.cfg.get("plot_lift_glm", False),
|
|
592
|
+
"xgb": self.cfg.get("plot_lift_xgb", False),
|
|
593
|
+
"resn": self.cfg.get("plot_lift_resn", False),
|
|
594
|
+
"ft": self.cfg.get("plot_lift_ft", False),
|
|
595
|
+
}
|
|
596
|
+
plot_enabled = plot_cfg.get("enable", any(legacy_flags.values()))
|
|
597
|
+
if plot_enabled and plot_cfg.get("pre_oneway", False) and plot_cfg.get("oneway", True):
|
|
598
|
+
n_bins = int(plot_cfg.get("n_bins", 10))
|
|
599
|
+
model.plot_oneway(n_bins=n_bins, plot_subdir="oneway/pre")
|
|
600
|
+
|
|
561
601
|
requested_keys = self._requested_model_keys(model.trainers)
|
|
562
602
|
executed_keys: List[str] = []
|
|
563
603
|
param_sources: Dict[str, str] = {}
|
|
@@ -474,10 +474,39 @@ class BayesOptModel:
|
|
|
474
474
|
]
|
|
475
475
|
|
|
476
476
|
# Single-factor plotting helper.
|
|
477
|
-
def plot_oneway(
|
|
477
|
+
def plot_oneway(
|
|
478
|
+
self,
|
|
479
|
+
n_bins=10,
|
|
480
|
+
pred_col: Optional[str] = None,
|
|
481
|
+
pred_label: Optional[str] = None,
|
|
482
|
+
pred_weighted: Optional[bool] = None,
|
|
483
|
+
plot_subdir: Optional[str] = None,
|
|
484
|
+
):
|
|
478
485
|
if plt is None and plot_diagnostics is None:
|
|
479
486
|
_plot_skip("oneway plot")
|
|
480
487
|
return
|
|
488
|
+
if pred_col is not None and pred_col not in self.train_data.columns:
|
|
489
|
+
print(
|
|
490
|
+
f"[Oneway] Missing prediction column '{pred_col}'; skip predicted line.",
|
|
491
|
+
flush=True,
|
|
492
|
+
)
|
|
493
|
+
pred_col = None
|
|
494
|
+
if pred_weighted is None and pred_col is not None:
|
|
495
|
+
pred_weighted = pred_col.startswith("w_pred_")
|
|
496
|
+
if pred_weighted is None:
|
|
497
|
+
pred_weighted = False
|
|
498
|
+
plot_subdir = plot_subdir.strip("/\\") if plot_subdir else "oneway"
|
|
499
|
+
plot_prefix = f"{self.model_nme}/{plot_subdir}"
|
|
500
|
+
|
|
501
|
+
def _safe_tag(value: str) -> str:
|
|
502
|
+
return (
|
|
503
|
+
value.strip()
|
|
504
|
+
.replace(" ", "_")
|
|
505
|
+
.replace("/", "_")
|
|
506
|
+
.replace("\\", "_")
|
|
507
|
+
.replace(":", "_")
|
|
508
|
+
)
|
|
509
|
+
|
|
481
510
|
if plot_diagnostics is None:
|
|
482
511
|
for c in self.factor_nmes:
|
|
483
512
|
fig = plt.figure(figsize=(7, 5))
|
|
@@ -492,14 +521,32 @@ class BayesOptModel:
|
|
|
492
521
|
duplicates='drop' # Drop duplicate quantiles to avoid errors.
|
|
493
522
|
)
|
|
494
523
|
plot_source = self.train_data.assign(**{group_col: bins})
|
|
524
|
+
if pred_col is not None and pred_col in plot_source.columns:
|
|
525
|
+
if pred_weighted:
|
|
526
|
+
plot_source = plot_source.assign(
|
|
527
|
+
_pred_w=plot_source[pred_col]
|
|
528
|
+
)
|
|
529
|
+
else:
|
|
530
|
+
plot_source = plot_source.assign(
|
|
531
|
+
_pred_w=plot_source[pred_col] * plot_source[self.weight_nme]
|
|
532
|
+
)
|
|
495
533
|
plot_data = plot_source.groupby(
|
|
496
534
|
[group_col], observed=True).sum(numeric_only=True)
|
|
497
535
|
plot_data.reset_index(inplace=True)
|
|
498
536
|
plot_data['act_v'] = plot_data['w_act'] / \
|
|
499
537
|
plot_data[self.weight_nme]
|
|
538
|
+
if pred_col is not None and "_pred_w" in plot_data.columns:
|
|
539
|
+
plot_data["pred_v"] = plot_data["_pred_w"] / plot_data[self.weight_nme]
|
|
500
540
|
ax = fig.add_subplot(111)
|
|
501
541
|
ax.plot(plot_data.index, plot_data['act_v'],
|
|
502
542
|
label='Actual', color='red')
|
|
543
|
+
if pred_col is not None and "pred_v" in plot_data.columns:
|
|
544
|
+
ax.plot(
|
|
545
|
+
plot_data.index,
|
|
546
|
+
plot_data["pred_v"],
|
|
547
|
+
label=pred_label or "Predicted",
|
|
548
|
+
color="tab:blue",
|
|
549
|
+
)
|
|
503
550
|
ax.set_title(
|
|
504
551
|
'Analysis of %s : Train Data' % group_col,
|
|
505
552
|
fontsize=8)
|
|
@@ -518,8 +565,15 @@ class BayesOptModel:
|
|
|
518
565
|
plt.yticks(fontsize=6)
|
|
519
566
|
plt.margins(0.05)
|
|
520
567
|
plt.subplots_adjust(wspace=0.3)
|
|
568
|
+
if pred_col is not None and "pred_v" in plot_data.columns:
|
|
569
|
+
ax.legend(fontsize=6)
|
|
570
|
+
pred_tag = _safe_tag(pred_label or pred_col) if pred_col else None
|
|
571
|
+
if pred_tag:
|
|
572
|
+
filename = f'00_{self.model_nme}_{group_col}_oneway_{pred_tag}.png'
|
|
573
|
+
else:
|
|
574
|
+
filename = f'00_{self.model_nme}_{group_col}_oneway.png'
|
|
521
575
|
save_path = self.output_manager.plot_path(
|
|
522
|
-
f'
|
|
576
|
+
f'{plot_prefix}/{filename}')
|
|
523
577
|
plt.savefig(save_path, dpi=300)
|
|
524
578
|
plt.close(fig)
|
|
525
579
|
return
|
|
@@ -532,14 +586,22 @@ class BayesOptModel:
|
|
|
532
586
|
is_cat = c in (self.cate_list or [])
|
|
533
587
|
group_col = c if is_cat else f"{c}_bins"
|
|
534
588
|
title = f"Analysis of {group_col} : Train Data"
|
|
589
|
+
pred_tag = _safe_tag(pred_label or pred_col) if pred_col else None
|
|
590
|
+
if pred_tag:
|
|
591
|
+
filename = f"00_{self.model_nme}_{group_col}_oneway_{pred_tag}.png"
|
|
592
|
+
else:
|
|
593
|
+
filename = f"00_{self.model_nme}_{group_col}_oneway.png"
|
|
535
594
|
save_path = self.output_manager.plot_path(
|
|
536
|
-
f"
|
|
595
|
+
f"{plot_prefix}/{filename}"
|
|
537
596
|
)
|
|
538
597
|
plot_diagnostics.plot_oneway(
|
|
539
598
|
self.train_data,
|
|
540
599
|
feature=c,
|
|
541
600
|
weight_col=self.weight_nme,
|
|
542
601
|
target_col="w_act",
|
|
602
|
+
pred_col=pred_col,
|
|
603
|
+
pred_weighted=pred_weighted,
|
|
604
|
+
pred_label=pred_label,
|
|
543
605
|
n_bins=n_bins,
|
|
544
606
|
is_categorical=is_cat,
|
|
545
607
|
title=title,
|
|
@@ -855,6 +917,15 @@ class BayesOptModel:
|
|
|
855
917
|
if model_label.startswith(k):
|
|
856
918
|
pred_nme = v
|
|
857
919
|
break
|
|
920
|
+
safe_label = (
|
|
921
|
+
str(model_label)
|
|
922
|
+
.replace(" ", "_")
|
|
923
|
+
.replace("/", "_")
|
|
924
|
+
.replace("\\", "_")
|
|
925
|
+
.replace(":", "_")
|
|
926
|
+
)
|
|
927
|
+
plot_prefix = f"{self.model_nme}/lift"
|
|
928
|
+
filename = f"01_{self.model_nme}_{safe_label}_lift.png"
|
|
858
929
|
|
|
859
930
|
datasets = []
|
|
860
931
|
for title, data in [
|
|
@@ -900,7 +971,7 @@ class BayesOptModel:
|
|
|
900
971
|
|
|
901
972
|
plt.subplots_adjust(wspace=0.3)
|
|
902
973
|
save_path = self.output_manager.plot_path(
|
|
903
|
-
f
|
|
974
|
+
f"{plot_prefix}/{filename}")
|
|
904
975
|
plt.savefig(save_path, dpi=300)
|
|
905
976
|
plt.show()
|
|
906
977
|
plt.close(fig)
|
|
@@ -945,7 +1016,7 @@ class BayesOptModel:
|
|
|
945
1016
|
|
|
946
1017
|
plt.subplots_adjust(wspace=0.3)
|
|
947
1018
|
save_path = self.output_manager.plot_path(
|
|
948
|
-
f
|
|
1019
|
+
f"{plot_prefix}/{filename}")
|
|
949
1020
|
if finalize_figure:
|
|
950
1021
|
finalize_figure(fig, save_path=save_path, show=True, style=style)
|
|
951
1022
|
else:
|
|
@@ -977,6 +1048,8 @@ class BayesOptModel:
|
|
|
977
1048
|
name1, name2 = model_comp
|
|
978
1049
|
if name1 not in model_name_map or name2 not in model_name_map:
|
|
979
1050
|
raise ValueError(f"Unsupported model key. Choose from {list(model_name_map.keys())}.")
|
|
1051
|
+
plot_prefix = f"{self.model_nme}/double_lift"
|
|
1052
|
+
filename = f"02_{self.model_nme}_dlift_{name1}_vs_{name2}.png"
|
|
980
1053
|
|
|
981
1054
|
datasets = []
|
|
982
1055
|
for data_name, data in [('Train Data', self.train_data),
|
|
@@ -1030,7 +1103,7 @@ class BayesOptModel:
|
|
|
1030
1103
|
|
|
1031
1104
|
plt.subplots_adjust(bottom=0.25, top=0.95, right=0.8, wspace=0.3)
|
|
1032
1105
|
save_path = self.output_manager.plot_path(
|
|
1033
|
-
f
|
|
1106
|
+
f"{plot_prefix}/{filename}")
|
|
1034
1107
|
plt.savefig(save_path, dpi=300)
|
|
1035
1108
|
plt.show()
|
|
1036
1109
|
plt.close(fig)
|
|
@@ -1089,7 +1162,7 @@ class BayesOptModel:
|
|
|
1089
1162
|
|
|
1090
1163
|
plt.subplots_adjust(bottom=0.25, top=0.95, right=0.8, wspace=0.3)
|
|
1091
1164
|
save_path = self.output_manager.plot_path(
|
|
1092
|
-
f
|
|
1165
|
+
f"{plot_prefix}/{filename}")
|
|
1093
1166
|
if finalize_figure:
|
|
1094
1167
|
finalize_figure(fig, save_path=save_path, show=True, style=style)
|
|
1095
1168
|
else:
|
|
@@ -1733,7 +1733,7 @@ class ResNetTrainer(TrainerBase):
|
|
|
1733
1733
|
self.model.epochs = int(refit_epochs)
|
|
1734
1734
|
self.best_params = params
|
|
1735
1735
|
loss_plot_path = self.output.plot_path(
|
|
1736
|
-
f'loss_{self.ctx.model_nme}_{self.model_name_prefix}.png')
|
|
1736
|
+
f'{self.ctx.model_nme}/loss/loss_{self.ctx.model_nme}_{self.model_name_prefix}.png')
|
|
1737
1737
|
self.model.loss_curve_path = loss_plot_path
|
|
1738
1738
|
|
|
1739
1739
|
self._fit_predict_cache(
|
|
@@ -2190,7 +2190,7 @@ class FTTrainer(TrainerBase):
|
|
|
2190
2190
|
self.model.set_params(resolved_params)
|
|
2191
2191
|
self.best_params = resolved_params
|
|
2192
2192
|
loss_plot_path = self.output.plot_path(
|
|
2193
|
-
f'loss_{self.ctx.model_nme}_{self.model_name_prefix}.png')
|
|
2193
|
+
f'{self.ctx.model_nme}/loss/loss_{self.ctx.model_nme}_{self.model_name_prefix}.png')
|
|
2194
2194
|
self.model.loss_curve_path = loss_plot_path
|
|
2195
2195
|
geo_train = self.ctx.train_geo_tokens
|
|
2196
2196
|
geo_test = self.ctx.test_geo_tokens
|
|
@@ -2395,7 +2395,7 @@ class FTTrainer(TrainerBase):
|
|
|
2395
2395
|
self.model.set_params(resolved_params)
|
|
2396
2396
|
|
|
2397
2397
|
loss_plot_path = self.output.plot_path(
|
|
2398
|
-
f'loss_{self.ctx.model_nme}_FTTransformerUnsupervised.png')
|
|
2398
|
+
f'{self.ctx.model_nme}/loss/loss_{self.ctx.model_nme}_FTTransformerUnsupervised.png')
|
|
2399
2399
|
self.model.loss_curve_path = loss_plot_path
|
|
2400
2400
|
|
|
2401
2401
|
# Build a simple holdout split for pretraining early stopping.
|
|
@@ -72,6 +72,9 @@ def plot_oneway(
|
|
|
72
72
|
feature: str,
|
|
73
73
|
weight_col: str,
|
|
74
74
|
target_col: str,
|
|
75
|
+
pred_col: Optional[str] = None,
|
|
76
|
+
pred_weighted: bool = False,
|
|
77
|
+
pred_label: Optional[str] = None,
|
|
75
78
|
n_bins: int = 10,
|
|
76
79
|
is_categorical: bool = False,
|
|
77
80
|
title: Optional[str] = None,
|
|
@@ -86,6 +89,8 @@ def plot_oneway(
|
|
|
86
89
|
raise KeyError(f"weight_col '{weight_col}' not found in data.")
|
|
87
90
|
if target_col not in df.columns:
|
|
88
91
|
raise KeyError(f"target_col '{target_col}' not found in data.")
|
|
92
|
+
if pred_col is not None and pred_col not in df.columns:
|
|
93
|
+
raise KeyError(f"pred_col '{pred_col}' not found in data.")
|
|
89
94
|
|
|
90
95
|
style = style or PlotStyle()
|
|
91
96
|
title = title or f"Analysis of {feature}"
|
|
@@ -102,11 +107,21 @@ def plot_oneway(
|
|
|
102
107
|
bins = pd.cut(series, bins=max(1, int(n_bins)), duplicates="drop")
|
|
103
108
|
plot_source = df.assign(**{group_col: bins})
|
|
104
109
|
|
|
110
|
+
if pred_col is not None:
|
|
111
|
+
if pred_weighted:
|
|
112
|
+
plot_source = plot_source.assign(_pred_w=plot_source[pred_col])
|
|
113
|
+
else:
|
|
114
|
+
plot_source = plot_source.assign(
|
|
115
|
+
_pred_w=plot_source[pred_col] * plot_source[weight_col]
|
|
116
|
+
)
|
|
117
|
+
|
|
105
118
|
plot_data = plot_source.groupby([group_col], observed=True).sum(numeric_only=True)
|
|
106
119
|
plot_data.reset_index(inplace=True)
|
|
107
120
|
|
|
108
121
|
denom = np.maximum(plot_data[weight_col].to_numpy(dtype=float), EPS)
|
|
109
122
|
plot_data["act_v"] = plot_data[target_col].to_numpy(dtype=float) / denom
|
|
123
|
+
if pred_col is not None:
|
|
124
|
+
plot_data["pred_v"] = plot_data["_pred_w"].to_numpy(dtype=float) / denom
|
|
110
125
|
|
|
111
126
|
created_fig = ax is None
|
|
112
127
|
if created_fig:
|
|
@@ -115,6 +130,13 @@ def plot_oneway(
|
|
|
115
130
|
fig = ax.figure
|
|
116
131
|
|
|
117
132
|
ax.plot(plot_data.index, plot_data["act_v"], label="Actual", color="red")
|
|
133
|
+
if pred_col is not None:
|
|
134
|
+
ax.plot(
|
|
135
|
+
plot_data.index,
|
|
136
|
+
plot_data["pred_v"],
|
|
137
|
+
label=pred_label or "Predicted",
|
|
138
|
+
color=style.palette[0],
|
|
139
|
+
)
|
|
118
140
|
ax.set_title(title, fontsize=style.title_size)
|
|
119
141
|
ax.set_xticks(plot_data.index)
|
|
120
142
|
labels = plot_data[group_col].astype(str).tolist()
|
|
@@ -123,6 +145,8 @@ def plot_oneway(
|
|
|
123
145
|
ax.tick_params(axis="y", labelsize=style.tick_size)
|
|
124
146
|
if style.grid:
|
|
125
147
|
ax.grid(True, linestyle=style.grid_style, alpha=style.grid_alpha)
|
|
148
|
+
if pred_col is not None:
|
|
149
|
+
ax.legend(fontsize=style.legend_size)
|
|
126
150
|
|
|
127
151
|
ax2 = ax.twinx()
|
|
128
152
|
ax2.bar(
|
ins_pricing/setup.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
ins_pricing/README.md,sha256=vufPPg719SZzrtcplnIN5BJvBsXKzIgxCUeCrWUzobM,2495
|
|
2
2
|
ins_pricing/__init__.py,sha256=hhZymgqtvilNC4WrZFXuT3-o0INSoVuRR-HA5EqyGAY,3085
|
|
3
|
-
ins_pricing/setup.py,sha256=
|
|
3
|
+
ins_pricing/setup.py,sha256=q5H6Ukbhgnu5NphpC0g3QtG4_8rCTvlGVkFH_KNqhr0,2034
|
|
4
4
|
ins_pricing/governance/README.md,sha256=XnXLS5RPzWhEiicJ3WtGmpN935jppHhPftA9Lo2DPnQ,511
|
|
5
5
|
ins_pricing/governance/__init__.py,sha256=d8tiDhOvHvAvgSohY1xv0vuEeHj8Gl1apQtw7ryEKM0,517
|
|
6
6
|
ins_pricing/governance/approval.py,sha256=cjJQjU1ziR-d-9wVSXyMyX6S5zijJqDWERZNxjqGAUE,2879
|
|
@@ -9,8 +9,8 @@ ins_pricing/governance/registry.py,sha256=2uxQL6qMGY5IYWJti9MpaV_auvL--piJaasFrX
|
|
|
9
9
|
ins_pricing/governance/release.py,sha256=ltyFIdeKbwj9fnEDxcQCURaQ5Zc_j0mqXFPNunmX_NQ,4743
|
|
10
10
|
ins_pricing/modelling/BayesOpt.py,sha256=i2tB3c6EeucjKAsHyicGDNU7DVVCTihg-TgSoM1y18E,3332
|
|
11
11
|
ins_pricing/modelling/BayesOpt_USAGE.md,sha256=x_CXot3RvGRYtt2xU2lrEfmtTbh2KGTryC3BJEZaoBw,39333
|
|
12
|
-
ins_pricing/modelling/BayesOpt_entry.py,sha256=
|
|
13
|
-
ins_pricing/modelling/BayesOpt_incremental.py,sha256=
|
|
12
|
+
ins_pricing/modelling/BayesOpt_entry.py,sha256=WdVaxeNfQTEplzx9r0dhaOfJCOEADcRipFNuN3yLgXI,24301
|
|
13
|
+
ins_pricing/modelling/BayesOpt_incremental.py,sha256=JKaRgsGY49OFE6cfQa5aAf8GzC2_bT7m8P99-S9E9Ss,30437
|
|
14
14
|
ins_pricing/modelling/Explain_Run.py,sha256=y-OKxmT475iRtDBukXh7jwiBiRmjh7ywCVhRFKk4EZw,962
|
|
15
15
|
ins_pricing/modelling/Explain_entry.py,sha256=e7EviU2fIWwyBsmoTq2ZM_rDKjZypQnFH68Q_rZVz1U,21330
|
|
16
16
|
ins_pricing/modelling/Pricing_Run.py,sha256=4BrUHhy4auzlbXopdocMV0Qn9_1b1Rjheq_sc5wM6D0,1009
|
|
@@ -22,9 +22,9 @@ ins_pricing/modelling/run_logging.py,sha256=V3Wh2EV6c1Mo0QTvfe4hl2J4LOR6bdQsT210
|
|
|
22
22
|
ins_pricing/modelling/watchdog_run.py,sha256=-gv72vcZqTYCvtDgnQTbSUWH_3icmraf7F09IX8_etI,6176
|
|
23
23
|
ins_pricing/modelling/bayesopt/__init__.py,sha256=5WGZeQI9B1P9OXQUgq7XogcjAbv2oXnp076bW16e_ss,1955
|
|
24
24
|
ins_pricing/modelling/bayesopt/config_preprocess.py,sha256=3CP_zsCcZnCTb2qXkvFNStL6lKNYeOT3uNypVw8bB4I,12326
|
|
25
|
-
ins_pricing/modelling/bayesopt/core.py,sha256=
|
|
25
|
+
ins_pricing/modelling/bayesopt/core.py,sha256=y5I8RRrSrhHPAri_oHiJ046kIa8ClmLfLolenJA2_v8,66967
|
|
26
26
|
ins_pricing/modelling/bayesopt/models.py,sha256=ajUTKoaumz1mKYnT3Toi7tUHkNO1Wlqex8kpoI2cv2I,90892
|
|
27
|
-
ins_pricing/modelling/bayesopt/trainers.py,sha256=
|
|
27
|
+
ins_pricing/modelling/bayesopt/trainers.py,sha256=Lpd2p1bDjyjPc-_fdr4guRaKkzjmtcJpdkVjXm3TLO8,103719
|
|
28
28
|
ins_pricing/modelling/bayesopt/utils.py,sha256=B837DYa5-6IY6A0_e-NiZY-VAJKUaQFMWEQ-LDLx1yI,41815
|
|
29
29
|
ins_pricing/modelling/explain/__init__.py,sha256=CPoGzGu8TTO3FOXjxoXC13VkuIDCf3YTH6L3BqJq3Ok,1171
|
|
30
30
|
ins_pricing/modelling/explain/gradients.py,sha256=9TqCws_p49nFxVMcjVxe4KCZ7frezeL0uV_LCdoM5yo,11088
|
|
@@ -34,7 +34,7 @@ ins_pricing/modelling/explain/shap_utils.py,sha256=IkijzxBeawyDIXiVxUUkvcC0MrHnt
|
|
|
34
34
|
ins_pricing/modelling/plotting/__init__.py,sha256=BBQKcE7IYUYObFrjpSnfNS6rmzc80Lae7oEqxKz-vEk,1058
|
|
35
35
|
ins_pricing/modelling/plotting/common.py,sha256=_kFq7JMA0LnKIp4bqAFvr-24VaHjj9pegDMm1qP9_7Y,1439
|
|
36
36
|
ins_pricing/modelling/plotting/curves.py,sha256=hGjpuALDwO0wDyWkIsBHZ4rqDGwPnkNdDZCIdgLW4II,18419
|
|
37
|
-
ins_pricing/modelling/plotting/diagnostics.py,sha256=
|
|
37
|
+
ins_pricing/modelling/plotting/diagnostics.py,sha256=AlkBtHuezRoDgMeXm56A1bK6Kn0rWOBy4Uts_xOocrs,5164
|
|
38
38
|
ins_pricing/modelling/plotting/geo.py,sha256=sRJTYOcAphNFM-oww4qbw9MoZneBCJtur96sYuqSNkw,11009
|
|
39
39
|
ins_pricing/modelling/plotting/importance.py,sha256=xs3l9uW_rCrakoA__fanIph6DK2jN_DugsKASAzteJU,3666
|
|
40
40
|
ins_pricing/modelling/tests/conftest.py,sha256=0KUXnkTgIGEIsf0J4uzIx5Kq4JkDyFo81Mv0qvIzW9k,180
|
|
@@ -163,7 +163,7 @@ user_packages legacy/Try/ModelBayesOptSearch.py,sha256=Co--dkbKxqpl-2tP9zEYmcEos
|
|
|
163
163
|
user_packages legacy/Try/ResNetBayesOptSearch.py,sha256=mp38lBs-TE3lAc8t8o4He5y1iwGIgrlPerurh_xRmqs,10942
|
|
164
164
|
user_packages legacy/Try/XgbBayesOptSearch.py,sha256=pWjlyT5FSK4zNnng0ZrpTIF5o-wBwuavxFA0LE4B4oE,5534
|
|
165
165
|
user_packages legacy/Try/xgbbayesopt.py,sha256=Vow-wrxcwozbTDPKJcl3ZzYgShd-4oks5Kzs74kXUvA,22754
|
|
166
|
-
ins_pricing-0.1.
|
|
167
|
-
ins_pricing-0.1.
|
|
168
|
-
ins_pricing-0.1.
|
|
169
|
-
ins_pricing-0.1.
|
|
166
|
+
ins_pricing-0.1.9.dist-info/METADATA,sha256=M6t36S64nSeohvrp_YyShibCvoARz9-SGRQI2mMUK84,3650
|
|
167
|
+
ins_pricing-0.1.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
168
|
+
ins_pricing-0.1.9.dist-info/top_level.txt,sha256=CUUE4W0DghRtQubDfBbIr2Kcvhdu-rOXxDD8Atjm_-c,66
|
|
169
|
+
ins_pricing-0.1.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|