ins-pricing 0.3.1__tar.gz → 0.3.3__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.
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/PKG-INFO +162 -162
- ins_pricing-0.3.3/ins_pricing/cli/BayesOpt_entry.py +56 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/cli/utils/import_resolver.py +29 -3
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/cli/utils/notebook_utils.py +3 -2
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/__init__.py +4 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/models/model_ft_components.py +38 -12
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/models/model_gnn.py +114 -14
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/trainers/trainer_base.py +2 -1
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/trainers/trainer_gnn.py +2 -2
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/production/predict.py +5 -4
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/setup.py +1 -1
- ins_pricing-0.3.3/ins_pricing/utils/torch_compat.py +85 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing.egg-info/PKG-INFO +162 -162
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing.egg-info/SOURCES.txt +1 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/pyproject.toml +1 -1
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/setup.cfg +4 -4
- ins_pricing-0.3.1/ins_pricing/cli/BayesOpt_entry.py +0 -24
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/MANIFEST.in +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/README.md +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/CHANGELOG.md +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/README.md +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/RELEASE_NOTES_0.2.8.md +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/__init__.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/cli/BayesOpt_incremental.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/cli/Explain_Run.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/cli/Explain_entry.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/cli/Pricing_Run.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/cli/__init__.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/cli/bayesopt_entry_runner.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/cli/utils/__init__.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/cli/utils/cli_common.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/cli/utils/cli_config.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/cli/utils/evaluation_context.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/cli/utils/run_logging.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/cli/watchdog_run.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/docs/modelling/BayesOpt_USAGE.md +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/docs/modelling/README.md +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/exceptions.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/governance/README.md +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/governance/__init__.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/governance/approval.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/governance/audit.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/governance/registry.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/governance/release.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/__init__.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/BayesOpt.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/__init__.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/PHASE2_REFACTORING_SUMMARY.md +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/PHASE3_REFACTORING_SUMMARY.md +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/REFACTORING_SUMMARY.md +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/config_components.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/config_preprocess.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/core.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/model_explain_mixin.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/model_plotting_mixin.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/models/__init__.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/models/model_ft_trainer.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/models/model_resn.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/trainers/__init__.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/trainers/trainer_ft.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/trainers/trainer_glm.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/trainers/trainer_resn.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/trainers/trainer_xgb.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/utils/__init__.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/utils/constants.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/utils/distributed_utils.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/utils/io_utils.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/utils/metrics_and_devices.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/utils/torch_trainer_mixin.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/utils.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/bayesopt/utils_backup.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/core/evaluation.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/explain/__init__.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/explain/gradients.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/explain/metrics.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/explain/permutation.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/explain/shap_utils.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/plotting/__init__.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/plotting/common.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/plotting/curves.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/plotting/diagnostics.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/plotting/geo.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/modelling/plotting/importance.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/pricing/README.md +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/pricing/__init__.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/pricing/calibration.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/pricing/data_quality.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/pricing/exposure.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/pricing/factors.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/pricing/monitoring.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/pricing/rate_table.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/production/__init__.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/production/drift.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/production/monitoring.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/production/preprocess.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/production/scoring.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/reporting/README.md +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/reporting/__init__.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/reporting/report_builder.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/reporting/scheduler.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/governance/__init__.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/governance/test_audit.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/governance/test_registry.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/governance/test_release.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/modelling/conftest.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/modelling/test_cross_val_generic.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/modelling/test_distributed_utils.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/modelling/test_explain.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/modelling/test_geo_tokens_split.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/modelling/test_graph_cache.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/modelling/test_plotting.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/modelling/test_plotting_library.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/modelling/test_preprocessor.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/pricing/__init__.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/pricing/test_calibration.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/pricing/test_exposure.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/pricing/test_factors.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/pricing/test_rate_table.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/production/__init__.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/production/test_monitoring.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/production/test_predict.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/production/test_preprocess.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/tests/production/test_scoring.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/utils/__init__.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/utils/device.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/utils/logging.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/utils/metrics.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/utils/paths.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/utils/profiling.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing/utils/validation.py +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing.egg-info/dependency_links.txt +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing.egg-info/requires.txt +0 -0
- {ins_pricing-0.3.1 → ins_pricing-0.3.3}/ins_pricing.egg-info/top_level.txt +0 -0
|
@@ -1,162 +1,162 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: ins_pricing
|
|
3
|
-
Version: 0.3.
|
|
4
|
-
Summary: Reusable modelling, pricing, governance, and reporting utilities.
|
|
5
|
-
Author: meishi125478
|
|
6
|
-
License: Proprietary
|
|
7
|
-
Keywords: pricing,insurance,bayesopt,ml
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
11
|
-
Classifier: License :: Other/Proprietary License
|
|
12
|
-
Classifier: Operating System :: OS Independent
|
|
13
|
-
Classifier: Intended Audience :: Developers
|
|
14
|
-
Requires-Python: >=3.9
|
|
15
|
-
Description-Content-Type: text/markdown
|
|
16
|
-
Requires-Dist: numpy>=1.20
|
|
17
|
-
Requires-Dist: pandas>=1.4
|
|
18
|
-
Provides-Extra: bayesopt
|
|
19
|
-
Requires-Dist: torch>=1.13; extra == "bayesopt"
|
|
20
|
-
Requires-Dist: optuna>=3.0; extra == "bayesopt"
|
|
21
|
-
Requires-Dist: xgboost>=1.6; extra == "bayesopt"
|
|
22
|
-
Requires-Dist: scikit-learn>=1.1; extra == "bayesopt"
|
|
23
|
-
Requires-Dist: statsmodels>=0.13; extra == "bayesopt"
|
|
24
|
-
Requires-Dist: joblib>=1.2; extra == "bayesopt"
|
|
25
|
-
Requires-Dist: matplotlib>=3.5; extra == "bayesopt"
|
|
26
|
-
Provides-Extra: plotting
|
|
27
|
-
Requires-Dist: matplotlib>=3.5; extra == "plotting"
|
|
28
|
-
Requires-Dist: scikit-learn>=1.1; extra == "plotting"
|
|
29
|
-
Provides-Extra: explain
|
|
30
|
-
Requires-Dist: torch>=1.13; extra == "explain"
|
|
31
|
-
Requires-Dist: shap>=0.41; extra == "explain"
|
|
32
|
-
Requires-Dist: scikit-learn>=1.1; extra == "explain"
|
|
33
|
-
Provides-Extra: geo
|
|
34
|
-
Requires-Dist: contextily>=1.3; extra == "geo"
|
|
35
|
-
Requires-Dist: matplotlib>=3.5; extra == "geo"
|
|
36
|
-
Provides-Extra: gnn
|
|
37
|
-
Requires-Dist: torch>=1.13; extra == "gnn"
|
|
38
|
-
Requires-Dist: pynndescent>=0.5; extra == "gnn"
|
|
39
|
-
Requires-Dist: torch-geometric>=2.3; extra == "gnn"
|
|
40
|
-
Provides-Extra: all
|
|
41
|
-
Requires-Dist: torch>=1.13; extra == "all"
|
|
42
|
-
Requires-Dist: optuna>=3.0; extra == "all"
|
|
43
|
-
Requires-Dist: xgboost>=1.6; extra == "all"
|
|
44
|
-
Requires-Dist: scikit-learn>=1.1; extra == "all"
|
|
45
|
-
Requires-Dist: statsmodels>=0.13; extra == "all"
|
|
46
|
-
Requires-Dist: joblib>=1.2; extra == "all"
|
|
47
|
-
Requires-Dist: matplotlib>=3.5; extra == "all"
|
|
48
|
-
Requires-Dist: shap>=0.41; extra == "all"
|
|
49
|
-
Requires-Dist: contextily>=1.3; extra == "all"
|
|
50
|
-
Requires-Dist: pynndescent>=0.5; extra == "all"
|
|
51
|
-
Requires-Dist: torch-geometric>=2.3; extra == "all"
|
|
52
|
-
|
|
53
|
-
# Insurance-Pricing
|
|
54
|
-
|
|
55
|
-
A reusable toolkit for insurance modeling, pricing, governance, and reporting.
|
|
56
|
-
|
|
57
|
-
## Overview
|
|
58
|
-
|
|
59
|
-
Insurance-Pricing (ins_pricing) is an enterprise-grade Python library designed for machine learning model training, pricing calculations, and model governance workflows in the insurance industry.
|
|
60
|
-
|
|
61
|
-
### Core Modules
|
|
62
|
-
|
|
63
|
-
| Module | Description |
|
|
64
|
-
|--------|-------------|
|
|
65
|
-
| **modelling** | ML model training (GLM, XGBoost, ResNet, FT-Transformer, GNN) and model interpretability (SHAP, permutation importance) |
|
|
66
|
-
| **pricing** | Factor table construction, numeric binning, premium calibration, exposure calculation, PSI monitoring |
|
|
67
|
-
| **production** | Model prediction, batch scoring, data drift detection, production metrics monitoring |
|
|
68
|
-
| **governance** | Model registry, version management, approval workflows, audit logging |
|
|
69
|
-
| **reporting** | Report generation (Markdown format), report scheduling |
|
|
70
|
-
| **utils** | Data validation, performance profiling, device management, logging configuration |
|
|
71
|
-
|
|
72
|
-
### Quick Start
|
|
73
|
-
|
|
74
|
-
```python
|
|
75
|
-
# Model training with Bayesian optimization
|
|
76
|
-
from ins_pricing import bayesopt as ropt
|
|
77
|
-
|
|
78
|
-
model = ropt.BayesOptModel(
|
|
79
|
-
train_data, test_data,
|
|
80
|
-
model_name='my_model',
|
|
81
|
-
resp_nme='target',
|
|
82
|
-
weight_nme='weight',
|
|
83
|
-
factor_nmes=feature_list,
|
|
84
|
-
cate_list=categorical_features,
|
|
85
|
-
)
|
|
86
|
-
model.bayesopt_xgb(max_evals=100) # Train XGBoost
|
|
87
|
-
model.bayesopt_resnet(max_evals=50) # Train ResNet
|
|
88
|
-
model.bayesopt_ft(max_evals=50) # Train FT-Transformer
|
|
89
|
-
|
|
90
|
-
# Pricing: build factor table
|
|
91
|
-
from ins_pricing.pricing import build_factor_table
|
|
92
|
-
factors = build_factor_table(
|
|
93
|
-
df,
|
|
94
|
-
factor_col='age_band',
|
|
95
|
-
loss_col='claim_amount',
|
|
96
|
-
exposure_col='exposure',
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
# Production: batch scoring
|
|
100
|
-
from ins_pricing.production import batch_score
|
|
101
|
-
scores = batch_score(model.trainers['xgb'].predict, df)
|
|
102
|
-
|
|
103
|
-
# Model governance
|
|
104
|
-
from ins_pricing.governance import ModelRegistry
|
|
105
|
-
registry = ModelRegistry('models.json')
|
|
106
|
-
registry.register(model_name, version, metrics=metrics)
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### Project Structure
|
|
110
|
-
|
|
111
|
-
```
|
|
112
|
-
ins_pricing/
|
|
113
|
-
├── cli/ # Command-line entry points
|
|
114
|
-
├── modelling/
|
|
115
|
-
│ ├── core/bayesopt/ # ML model training core
|
|
116
|
-
│ ├── explain/ # Model interpretability
|
|
117
|
-
│ └── plotting/ # Model visualization
|
|
118
|
-
├── pricing/ # Insurance pricing module
|
|
119
|
-
├── production/ # Production deployment module
|
|
120
|
-
├── governance/ # Model governance
|
|
121
|
-
├── reporting/ # Report generation
|
|
122
|
-
├── utils/ # Utilities
|
|
123
|
-
└── tests/ # Test suite
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
### Installation
|
|
127
|
-
|
|
128
|
-
```bash
|
|
129
|
-
# Basic installation
|
|
130
|
-
pip install ins_pricing
|
|
131
|
-
|
|
132
|
-
# Full installation (all optional dependencies)
|
|
133
|
-
pip install ins_pricing[all]
|
|
134
|
-
|
|
135
|
-
# Install specific extras
|
|
136
|
-
pip install ins_pricing[bayesopt] # Model training
|
|
137
|
-
pip install ins_pricing[explain] # Model explanation
|
|
138
|
-
pip install ins_pricing[plotting] # Visualization
|
|
139
|
-
pip install ins_pricing[gnn] # Graph neural networks
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
#### Multi-platform & GPU installation notes
|
|
143
|
-
|
|
144
|
-
- **PyTorch (CPU/GPU/MPS)**: Install the correct PyTorch build for your platform/GPU first (CUDA on
|
|
145
|
-
Linux/Windows, ROCm on supported AMD platforms, or MPS on Apple Silicon). Then install the
|
|
146
|
-
optional extras you need (e.g., `bayesopt`, `explain`, or `gnn`). This avoids pip pulling a
|
|
147
|
-
mismatched wheel.
|
|
148
|
-
- **Torch Geometric (GNN)**: `torch-geometric` often requires platform-specific wheels (e.g.,
|
|
149
|
-
`torch-scatter`, `torch-sparse`). Follow the official PyG installation instructions for your
|
|
150
|
-
CUDA/ROCm/CPU environment, then install `ins_pricing[gnn]`.
|
|
151
|
-
- **Multi-GPU**: Training code will use CUDA when available and can enable multi-GPU via
|
|
152
|
-
`torch.distributed`/`DataParallel` where supported. On Windows, CUDA DDP is not supported and will
|
|
153
|
-
fall back to single-GPU or DataParallel where possible.
|
|
154
|
-
|
|
155
|
-
### Requirements
|
|
156
|
-
|
|
157
|
-
- Python >= 3.9
|
|
158
|
-
- Core dependencies: numpy >= 1.20, pandas >= 1.4
|
|
159
|
-
|
|
160
|
-
### License
|
|
161
|
-
|
|
162
|
-
Proprietary
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ins_pricing
|
|
3
|
+
Version: 0.3.3
|
|
4
|
+
Summary: Reusable modelling, pricing, governance, and reporting utilities.
|
|
5
|
+
Author: meishi125478
|
|
6
|
+
License: Proprietary
|
|
7
|
+
Keywords: pricing,insurance,bayesopt,ml
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
11
|
+
Classifier: License :: Other/Proprietary License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Requires-Python: >=3.9
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
Requires-Dist: numpy>=1.20
|
|
17
|
+
Requires-Dist: pandas>=1.4
|
|
18
|
+
Provides-Extra: bayesopt
|
|
19
|
+
Requires-Dist: torch>=1.13; extra == "bayesopt"
|
|
20
|
+
Requires-Dist: optuna>=3.0; extra == "bayesopt"
|
|
21
|
+
Requires-Dist: xgboost>=1.6; extra == "bayesopt"
|
|
22
|
+
Requires-Dist: scikit-learn>=1.1; extra == "bayesopt"
|
|
23
|
+
Requires-Dist: statsmodels>=0.13; extra == "bayesopt"
|
|
24
|
+
Requires-Dist: joblib>=1.2; extra == "bayesopt"
|
|
25
|
+
Requires-Dist: matplotlib>=3.5; extra == "bayesopt"
|
|
26
|
+
Provides-Extra: plotting
|
|
27
|
+
Requires-Dist: matplotlib>=3.5; extra == "plotting"
|
|
28
|
+
Requires-Dist: scikit-learn>=1.1; extra == "plotting"
|
|
29
|
+
Provides-Extra: explain
|
|
30
|
+
Requires-Dist: torch>=1.13; extra == "explain"
|
|
31
|
+
Requires-Dist: shap>=0.41; extra == "explain"
|
|
32
|
+
Requires-Dist: scikit-learn>=1.1; extra == "explain"
|
|
33
|
+
Provides-Extra: geo
|
|
34
|
+
Requires-Dist: contextily>=1.3; extra == "geo"
|
|
35
|
+
Requires-Dist: matplotlib>=3.5; extra == "geo"
|
|
36
|
+
Provides-Extra: gnn
|
|
37
|
+
Requires-Dist: torch>=1.13; extra == "gnn"
|
|
38
|
+
Requires-Dist: pynndescent>=0.5; extra == "gnn"
|
|
39
|
+
Requires-Dist: torch-geometric>=2.3; extra == "gnn"
|
|
40
|
+
Provides-Extra: all
|
|
41
|
+
Requires-Dist: torch>=1.13; extra == "all"
|
|
42
|
+
Requires-Dist: optuna>=3.0; extra == "all"
|
|
43
|
+
Requires-Dist: xgboost>=1.6; extra == "all"
|
|
44
|
+
Requires-Dist: scikit-learn>=1.1; extra == "all"
|
|
45
|
+
Requires-Dist: statsmodels>=0.13; extra == "all"
|
|
46
|
+
Requires-Dist: joblib>=1.2; extra == "all"
|
|
47
|
+
Requires-Dist: matplotlib>=3.5; extra == "all"
|
|
48
|
+
Requires-Dist: shap>=0.41; extra == "all"
|
|
49
|
+
Requires-Dist: contextily>=1.3; extra == "all"
|
|
50
|
+
Requires-Dist: pynndescent>=0.5; extra == "all"
|
|
51
|
+
Requires-Dist: torch-geometric>=2.3; extra == "all"
|
|
52
|
+
|
|
53
|
+
# Insurance-Pricing
|
|
54
|
+
|
|
55
|
+
A reusable toolkit for insurance modeling, pricing, governance, and reporting.
|
|
56
|
+
|
|
57
|
+
## Overview
|
|
58
|
+
|
|
59
|
+
Insurance-Pricing (ins_pricing) is an enterprise-grade Python library designed for machine learning model training, pricing calculations, and model governance workflows in the insurance industry.
|
|
60
|
+
|
|
61
|
+
### Core Modules
|
|
62
|
+
|
|
63
|
+
| Module | Description |
|
|
64
|
+
|--------|-------------|
|
|
65
|
+
| **modelling** | ML model training (GLM, XGBoost, ResNet, FT-Transformer, GNN) and model interpretability (SHAP, permutation importance) |
|
|
66
|
+
| **pricing** | Factor table construction, numeric binning, premium calibration, exposure calculation, PSI monitoring |
|
|
67
|
+
| **production** | Model prediction, batch scoring, data drift detection, production metrics monitoring |
|
|
68
|
+
| **governance** | Model registry, version management, approval workflows, audit logging |
|
|
69
|
+
| **reporting** | Report generation (Markdown format), report scheduling |
|
|
70
|
+
| **utils** | Data validation, performance profiling, device management, logging configuration |
|
|
71
|
+
|
|
72
|
+
### Quick Start
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
# Model training with Bayesian optimization
|
|
76
|
+
from ins_pricing import bayesopt as ropt
|
|
77
|
+
|
|
78
|
+
model = ropt.BayesOptModel(
|
|
79
|
+
train_data, test_data,
|
|
80
|
+
model_name='my_model',
|
|
81
|
+
resp_nme='target',
|
|
82
|
+
weight_nme='weight',
|
|
83
|
+
factor_nmes=feature_list,
|
|
84
|
+
cate_list=categorical_features,
|
|
85
|
+
)
|
|
86
|
+
model.bayesopt_xgb(max_evals=100) # Train XGBoost
|
|
87
|
+
model.bayesopt_resnet(max_evals=50) # Train ResNet
|
|
88
|
+
model.bayesopt_ft(max_evals=50) # Train FT-Transformer
|
|
89
|
+
|
|
90
|
+
# Pricing: build factor table
|
|
91
|
+
from ins_pricing.pricing import build_factor_table
|
|
92
|
+
factors = build_factor_table(
|
|
93
|
+
df,
|
|
94
|
+
factor_col='age_band',
|
|
95
|
+
loss_col='claim_amount',
|
|
96
|
+
exposure_col='exposure',
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
# Production: batch scoring
|
|
100
|
+
from ins_pricing.production import batch_score
|
|
101
|
+
scores = batch_score(model.trainers['xgb'].predict, df)
|
|
102
|
+
|
|
103
|
+
# Model governance
|
|
104
|
+
from ins_pricing.governance import ModelRegistry
|
|
105
|
+
registry = ModelRegistry('models.json')
|
|
106
|
+
registry.register(model_name, version, metrics=metrics)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Project Structure
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
ins_pricing/
|
|
113
|
+
├── cli/ # Command-line entry points
|
|
114
|
+
├── modelling/
|
|
115
|
+
│ ├── core/bayesopt/ # ML model training core
|
|
116
|
+
│ ├── explain/ # Model interpretability
|
|
117
|
+
│ └── plotting/ # Model visualization
|
|
118
|
+
├── pricing/ # Insurance pricing module
|
|
119
|
+
├── production/ # Production deployment module
|
|
120
|
+
├── governance/ # Model governance
|
|
121
|
+
├── reporting/ # Report generation
|
|
122
|
+
├── utils/ # Utilities
|
|
123
|
+
└── tests/ # Test suite
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Installation
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# Basic installation
|
|
130
|
+
pip install ins_pricing
|
|
131
|
+
|
|
132
|
+
# Full installation (all optional dependencies)
|
|
133
|
+
pip install ins_pricing[all]
|
|
134
|
+
|
|
135
|
+
# Install specific extras
|
|
136
|
+
pip install ins_pricing[bayesopt] # Model training
|
|
137
|
+
pip install ins_pricing[explain] # Model explanation
|
|
138
|
+
pip install ins_pricing[plotting] # Visualization
|
|
139
|
+
pip install ins_pricing[gnn] # Graph neural networks
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
#### Multi-platform & GPU installation notes
|
|
143
|
+
|
|
144
|
+
- **PyTorch (CPU/GPU/MPS)**: Install the correct PyTorch build for your platform/GPU first (CUDA on
|
|
145
|
+
Linux/Windows, ROCm on supported AMD platforms, or MPS on Apple Silicon). Then install the
|
|
146
|
+
optional extras you need (e.g., `bayesopt`, `explain`, or `gnn`). This avoids pip pulling a
|
|
147
|
+
mismatched wheel.
|
|
148
|
+
- **Torch Geometric (GNN)**: `torch-geometric` often requires platform-specific wheels (e.g.,
|
|
149
|
+
`torch-scatter`, `torch-sparse`). Follow the official PyG installation instructions for your
|
|
150
|
+
CUDA/ROCm/CPU environment, then install `ins_pricing[gnn]`.
|
|
151
|
+
- **Multi-GPU**: Training code will use CUDA when available and can enable multi-GPU via
|
|
152
|
+
`torch.distributed`/`DataParallel` where supported. On Windows, CUDA DDP is not supported and will
|
|
153
|
+
fall back to single-GPU or DataParallel where possible.
|
|
154
|
+
|
|
155
|
+
### Requirements
|
|
156
|
+
|
|
157
|
+
- Python >= 3.9
|
|
158
|
+
- Core dependencies: numpy >= 1.20, pandas >= 1.4
|
|
159
|
+
|
|
160
|
+
### License
|
|
161
|
+
|
|
162
|
+
Proprietary
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""Thin wrapper for the BayesOpt CLI entry point.
|
|
2
|
+
|
|
3
|
+
The main implementation lives in bayesopt_entry_runner.py.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
import json
|
|
10
|
+
import os
|
|
11
|
+
import sys
|
|
12
|
+
|
|
13
|
+
if __package__ in {None, ""}:
|
|
14
|
+
repo_root = Path(__file__).resolve().parents[2]
|
|
15
|
+
if str(repo_root) not in sys.path:
|
|
16
|
+
sys.path.insert(0, str(repo_root))
|
|
17
|
+
|
|
18
|
+
def _apply_env_from_config(argv: list[str]) -> None:
|
|
19
|
+
if "--config-json" not in argv:
|
|
20
|
+
return
|
|
21
|
+
idx = argv.index("--config-json")
|
|
22
|
+
if idx + 1 >= len(argv):
|
|
23
|
+
return
|
|
24
|
+
raw_path = argv[idx + 1]
|
|
25
|
+
try:
|
|
26
|
+
cfg_path = Path(raw_path).expanduser()
|
|
27
|
+
if not cfg_path.is_absolute():
|
|
28
|
+
cfg_path = cfg_path.resolve()
|
|
29
|
+
if not cfg_path.exists():
|
|
30
|
+
script_dir = Path(__file__).resolve().parents[1]
|
|
31
|
+
candidate = (script_dir / raw_path).resolve()
|
|
32
|
+
if candidate.exists():
|
|
33
|
+
cfg_path = candidate
|
|
34
|
+
if not cfg_path.exists():
|
|
35
|
+
return
|
|
36
|
+
cfg = json.loads(cfg_path.read_text(encoding="utf-8", errors="replace"))
|
|
37
|
+
env = cfg.get("env", {})
|
|
38
|
+
if isinstance(env, dict):
|
|
39
|
+
for key, value in env.items():
|
|
40
|
+
if key is None:
|
|
41
|
+
continue
|
|
42
|
+
os.environ.setdefault(str(key), str(value))
|
|
43
|
+
except Exception:
|
|
44
|
+
return
|
|
45
|
+
|
|
46
|
+
_apply_env_from_config(sys.argv)
|
|
47
|
+
|
|
48
|
+
try:
|
|
49
|
+
from .bayesopt_entry_runner import main
|
|
50
|
+
except Exception: # pragma: no cover
|
|
51
|
+
from ins_pricing.cli.bayesopt_entry_runner import main
|
|
52
|
+
|
|
53
|
+
__all__ = ["main"]
|
|
54
|
+
|
|
55
|
+
if __name__ == "__main__":
|
|
56
|
+
main()
|
|
@@ -13,6 +13,7 @@ Usage:
|
|
|
13
13
|
from __future__ import annotations
|
|
14
14
|
|
|
15
15
|
import importlib
|
|
16
|
+
import os
|
|
16
17
|
import sys
|
|
17
18
|
from dataclasses import dataclass, field
|
|
18
19
|
from pathlib import Path
|
|
@@ -70,14 +71,39 @@ class ResolvedImports:
|
|
|
70
71
|
plot_loss_curve: Optional[Callable] = None
|
|
71
72
|
|
|
72
73
|
|
|
74
|
+
def _debug_imports_enabled() -> bool:
|
|
75
|
+
value = os.environ.get("BAYESOPT_DEBUG_IMPORTS")
|
|
76
|
+
if value is None:
|
|
77
|
+
return False
|
|
78
|
+
return str(value).strip().lower() in {"1", "true", "yes", "y", "on"}
|
|
79
|
+
|
|
80
|
+
|
|
73
81
|
def _try_import(module_path: str, attr_name: Optional[str] = None) -> Optional[Any]:
|
|
74
82
|
"""Attempt to import a module or attribute, returning None on failure."""
|
|
75
83
|
try:
|
|
76
84
|
module = importlib.import_module(module_path)
|
|
77
85
|
if attr_name:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
86
|
+
result = getattr(module, attr_name, None)
|
|
87
|
+
else:
|
|
88
|
+
result = module
|
|
89
|
+
if _debug_imports_enabled():
|
|
90
|
+
origin = getattr(module, "__file__", None)
|
|
91
|
+
origin = origin or getattr(module, "__path__", None)
|
|
92
|
+
print(
|
|
93
|
+
f"[BAYESOPT_DEBUG_IMPORTS] imported {module_path}"
|
|
94
|
+
f"{'::' + attr_name if attr_name else ''} from {origin}",
|
|
95
|
+
file=sys.stderr,
|
|
96
|
+
flush=True,
|
|
97
|
+
)
|
|
98
|
+
return result
|
|
99
|
+
except Exception as exc:
|
|
100
|
+
if _debug_imports_enabled():
|
|
101
|
+
print(
|
|
102
|
+
f"[BAYESOPT_DEBUG_IMPORTS] failed import {module_path}"
|
|
103
|
+
f"{'::' + attr_name if attr_name else ''}: {exc.__class__.__name__}: {exc}",
|
|
104
|
+
file=sys.stderr,
|
|
105
|
+
flush=True,
|
|
106
|
+
)
|
|
81
107
|
return None
|
|
82
108
|
|
|
83
109
|
|
|
@@ -8,9 +8,9 @@ from pathlib import Path
|
|
|
8
8
|
from typing import Iterable, List, Optional, Sequence, cast
|
|
9
9
|
|
|
10
10
|
try:
|
|
11
|
-
from .cli_config import add_config_json_arg # type: ignore
|
|
11
|
+
from .cli_config import add_config_json_arg, set_env # type: ignore
|
|
12
12
|
except Exception: # pragma: no cover
|
|
13
|
-
from cli_config import add_config_json_arg # type: ignore
|
|
13
|
+
from cli_config import add_config_json_arg, set_env # type: ignore
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
def _find_ins_pricing_dir(cwd: Optional[Path] = None) -> Path:
|
|
@@ -261,6 +261,7 @@ def run_from_config(config_json: str | Path) -> subprocess.CompletedProcess:
|
|
|
261
261
|
if not config_path.is_absolute():
|
|
262
262
|
config_path = (pkg_dir / config_path).resolve() if (pkg_dir / config_path).exists() else config_path.resolve()
|
|
263
263
|
raw = json.loads(config_path.read_text(encoding="utf-8", errors="replace"))
|
|
264
|
+
set_env(raw.get("env", {}))
|
|
264
265
|
runner = cast(dict, raw.get("runner") or {})
|
|
265
266
|
|
|
266
267
|
mode = str(runner.get("mode") or "entry").strip().lower()
|
|
@@ -106,31 +106,58 @@ class ScaledTransformerEncoderLayer(nn.Module):
|
|
|
106
106
|
self.res_scale_attn = residual_scale_attn
|
|
107
107
|
self.res_scale_ffn = residual_scale_ffn
|
|
108
108
|
|
|
109
|
-
def forward(self, src, src_mask=None, src_key_padding_mask=None):
|
|
109
|
+
def forward(self, src, src_mask=None, src_key_padding_mask=None, is_causal: Optional[bool] = None, **_kwargs):
|
|
110
110
|
# Input tensor shape: (batch, seq_len, d_model).
|
|
111
111
|
x = src
|
|
112
112
|
|
|
113
113
|
if self.norm_first:
|
|
114
114
|
# Pre-norm before attention.
|
|
115
|
-
x = x + self._sa_block(
|
|
116
|
-
|
|
115
|
+
x = x + self._sa_block(
|
|
116
|
+
self.norm1(x),
|
|
117
|
+
src_mask,
|
|
118
|
+
src_key_padding_mask,
|
|
119
|
+
is_causal=is_causal,
|
|
120
|
+
)
|
|
117
121
|
x = x + self._ff_block(self.norm2(x))
|
|
118
122
|
else:
|
|
119
123
|
# Post-norm (usually disabled).
|
|
120
124
|
x = self.norm1(
|
|
121
|
-
x + self._sa_block(
|
|
125
|
+
x + self._sa_block(
|
|
126
|
+
x,
|
|
127
|
+
src_mask,
|
|
128
|
+
src_key_padding_mask,
|
|
129
|
+
is_causal=is_causal,
|
|
130
|
+
)
|
|
131
|
+
)
|
|
122
132
|
x = self.norm2(x + self._ff_block(x))
|
|
123
133
|
|
|
124
134
|
return x
|
|
125
135
|
|
|
126
|
-
def _sa_block(self, x, attn_mask, key_padding_mask):
|
|
136
|
+
def _sa_block(self, x, attn_mask, key_padding_mask, *, is_causal: Optional[bool] = None):
|
|
127
137
|
# Self-attention with residual scaling.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
138
|
+
if is_causal is None:
|
|
139
|
+
attn_out, _ = self.self_attn(
|
|
140
|
+
x, x, x,
|
|
141
|
+
attn_mask=attn_mask,
|
|
142
|
+
key_padding_mask=key_padding_mask,
|
|
143
|
+
need_weights=False,
|
|
144
|
+
)
|
|
145
|
+
else:
|
|
146
|
+
try:
|
|
147
|
+
attn_out, _ = self.self_attn(
|
|
148
|
+
x, x, x,
|
|
149
|
+
attn_mask=attn_mask,
|
|
150
|
+
key_padding_mask=key_padding_mask,
|
|
151
|
+
need_weights=False,
|
|
152
|
+
is_causal=is_causal,
|
|
153
|
+
)
|
|
154
|
+
except TypeError:
|
|
155
|
+
attn_out, _ = self.self_attn(
|
|
156
|
+
x, x, x,
|
|
157
|
+
attn_mask=attn_mask,
|
|
158
|
+
key_padding_mask=key_padding_mask,
|
|
159
|
+
need_weights=False,
|
|
160
|
+
)
|
|
134
161
|
return self.res_scale_attn * self.dropout1(attn_out)
|
|
135
162
|
|
|
136
163
|
def _ff_block(self, x):
|
|
@@ -313,4 +340,3 @@ class MaskedTabularDataset(Dataset):
|
|
|
313
340
|
None if self.X_cat_true is None else self.X_cat_true[idx],
|
|
314
341
|
None if self.cat_mask is None else self.cat_mask[idx],
|
|
315
342
|
)
|
|
316
|
-
|