Skip to main content

Boosted linear models on HVRT cooperative geometry partitions

Project description

GeoLinear

Boosted piecewise-linear models on cooperative geometry partitions.

PyPI version License: AGPL-3.0 Python 3.10+


What is GeoLinear?

GeoLinear discovers cooperative geometry regimes in your data — groups of observations where features interact in similar ways — and fits an interpretable linear model inside each regime. Predictions are accumulated across boosting rounds.

The key insight is that many real-world relationships are piecewise-linear in cooperative geometry. A global linear model averages over regimes and loses the regime-specific signal. GeoLinear finds the regimes automatically (via HVRT) and lets the coefficients vary across them.

Round 1: HVRT partitions X → {cooperative, competitive, mixed} regimes
         Ridge fits within each partition on residuals
Round 2: New partitioning on updated residuals → new local Ridge models
...
Final prediction = Σ (learning_rate × stage_predictions) + intercept

Each partition's Ridge coefficients are directly interpretable as local relativities — exactly the quantities actuaries file with regulators.


Why it matters for actuaries

Insurance pricing models must be both accurate and interpretable. Regulators require filed relativities; black-box models are inadmissible. The usual compromise — vanilla GLM — leaves accuracy on the table when the true relationship is regime-switching.

GeoLinear bridges this gap:

  1. Fit GeoLinear on the training portfolio. Each partition's Ridge coefficients are the relativities for that cooperative geometry segment.
  2. File a meta-GLM: fit OLS(X → ŷ_GL) to compress the ensemble into a single interpretable GLM. The compression loss is typically small (R² drop < 2%).
  3. Audit trail: every prediction can be traced to a specific partition and its local coefficient vector.

See examples/insurance_pricing_demo.py for a worked actuarial example including relativities tables and the GLM bridge.


Installation

pip install geolinear

Requires a C++17 compiler and CMake (automatically satisfied on most systems; the cmake PyPI package is a reliable fallback).

For the examples:

pip install geolinear[examples]   # adds xgboost, optuna, matplotlib

Quick start

Regression

from geolinear import GeoLinear
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
from sklearn.metrics import r2_score

X, y = fetch_california_housing(return_X_y=True)
X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=0.2, random_state=0)

model = GeoLinear(n_rounds=20, learning_rate=0.1, alpha=1.0)
model.fit(X_tr, y_tr)
print(r2_score(y_te, model.predict(X_te)))   # ~0.72 default params

Classification

from geolinear import GeoLinearClassifier
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_auc_score

X, y = load_breast_cancer(return_X_y=True)
X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=0.2, random_state=0)

clf = GeoLinearClassifier(n_rounds=20, alpha=1.0)
clf.fit(X_tr, y_tr)
print(roc_auc_score(y_te, clf.predict_proba(X_te)[:, 1]))  # ~0.993

Pipeline + GridSearchCV

from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import GridSearchCV
from geolinear import GeoLinear

pipe = Pipeline([("scaler", StandardScaler()), ("gl", GeoLinear())])
grid = GridSearchCV(pipe, {"gl__alpha": [0.1, 1.0, 10.0], "gl__n_rounds": [10, 20]}, cv=5)
grid.fit(X_tr, y_tr)

Optuna HPO

import optuna
from geolinear import GeoLinear
from sklearn.model_selection import cross_val_score

def objective(trial):
    model = GeoLinear(
        n_rounds=trial.suggest_int("n_rounds", 10, 100),
        learning_rate=trial.suggest_float("learning_rate", 0.01, 0.3, log=True),
        alpha=trial.suggest_float("alpha", 0.01, 20.0, log=True),
        y_weight=trial.suggest_float("y_weight", 0.1, 1.0),
        base_learner=trial.suggest_categorical("base_learner", ["ridge", "lasso"]),
        hvrt_n_partitions=trial.suggest_int("hvrt_n_partitions", 3, 14),
        min_samples_partition=trial.suggest_int("min_samples_partition", 3, 25),
        hvrt_model=trial.suggest_categorical("hvrt_model", ["hvrt", "pyramid_hart", "fast_hvrt"]),
        use_t_feature=trial.suggest_categorical("use_t_feature", [False, True]),
        refit_interval=trial.suggest_categorical("refit_interval", [0, 1, 2]),
    )
    return cross_val_score(model, X_tr, y_tr, cv=5, scoring="r2").mean()

study = optuna.create_study(direction="maximize")
study.optimize(objective, n_trials=60)

Ecosystem: which tool to use?

GeoLinear is part of a family of cooperative-geometry libraries. The right choice depends on what "interpretable" means in your domain and the structure of your data.

Domain Primary need Recommended
Insurance pricing Filed relativities; regulator-auditable linear tariff GeoLinear
Credit risk / scoring Scorecard linearity; SR 11-7 model risk compliance GeoLinear
Utility rate-setting Filed tariff schedules with linear rate factors GeoLinear
Healthcare / clinical XGBoost-level performance with fully deterministic, auditable predictions GeoXGB
Ecology / environmental Nonlinear regime detection; richer explanation than SHAP via 100% determinism GeoXGB
Public policy Algorithmic accountability without linearity constraints GeoXGB
Personalised interventions Per-entity longitudinal data; individual treatment trajectories AutoITE

Rule of thumb: if your regulator or ethics board requires a linear equation you can file or defend, use GeoLinear. If you need XGBoost-class accuracy with fully deterministic predictions that provide richer interpretability than SHAP, use GeoXGB. If you have repeated observations per individual and want to model how treatment effects evolve over time for each entity, use AutoITE.


Benchmark results

80-trial Optuna HPO, GeoLinear (v0.3.0) vs XGBoost. use_t_feature included in GeoLinear's HPO search space so the optimizer can exploit cooperative geometry when it exists.

Regression R² — v0.3.0 (80-trial HPO)

DGP GL-HPO use_t XGB-HPO Gap
T-regime 0.569 0.296 +0.273 GL wins
3-regime 0.358 0.329 +0.029 GL wins
Friedman1 0.984 0.988 −0.003 (tie)
Linear 0.965 0.957 +0.008 GL wins
CalHousing 0.584 0.856 −0.271 XGB wins

Score: 3 wins · 1 tie · 1 loss.

use_t_feature is selected by HPO whenever the data has cooperative structure (T-regime, 3-regime). On smooth or axis-aligned DGPs (Friedman1, Linear) HPO correctly opts out. CalHousing remains XGBoost territory: spatial autocorrelation and threshold effects are better captured by axis-aligned splits than by pairwise cooperative geometry.

Classification AUC

Dataset GL-Ridge (default) GL-HPO XGB-HPO
Synthetic 0.940 0.957 0.981
BreastCancer 0.993 0.972 0.993

Default-parameter GL-Ridge matches XGBoost-HPO on BreastCancer (AUC 0.993 each).


API reference

GeoLinear (regressor)

Parameter Type Default Description
n_rounds int 20 Boosting rounds
learning_rate float 0.1 Shrinkage per round
y_weight float 0.5 HVRT outcome-blend (0 = geometry-only, 1 = y-driven)
base_learner str "ridge" "ridge", "ols", or "lasso"
alpha float 1.0 L2 regularisation within each partition
min_samples_partition int 5 Minimum samples to fit a partition model
hvrt_n_partitions int|None None Target partitions (None = HVRT auto-tune)
hvrt_min_samples_leaf int|None None HVRT min leaf size
hvrt_inner_rounds int 1 HVRT T-residual inner rounds per stage
partition_inner_rounds int 1 Base-learner rounds within each partition
refit_interval int 0 0 = fresh HVRT each round; k>0 = refit every k rounds (faster)
use_t_feature bool False Append per-sample T-statistic (S²−Q) as an extra linear feature
use_coop_weights bool False Scale features by |corr(z_k, S−z_k)|² before linear fit
random_state int 42 Seed (incremented per round for diverse partitionings)

GeoLinearClassifier accepts the same parameters.

Key methods

model.fit(X, y)                          # fit
model.predict(X)                         # regression predictions
clf.predict_proba(X)                     # class probabilities, shape (n, 2)
model.feature_importances(feature_names) # weighted mean |coef| across partitions/stages
model.stages_                            # list of (None, dict[partition_id, RidgeModel])

License

GNU Affero General Public License v3.0 or later. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geolinear-0.3.0.tar.gz (109.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

geolinear-0.3.0-cp313-cp313-win_amd64.whl (268.4 kB view details)

Uploaded CPython 3.13Windows x86-64

geolinear-0.3.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (352.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

geolinear-0.3.0-cp313-cp313-macosx_11_0_arm64.whl (293.2 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

geolinear-0.3.0-cp312-cp312-win_amd64.whl (268.4 kB view details)

Uploaded CPython 3.12Windows x86-64

geolinear-0.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (352.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

geolinear-0.3.0-cp312-cp312-macosx_11_0_arm64.whl (293.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

geolinear-0.3.0-cp311-cp311-win_amd64.whl (267.1 kB view details)

Uploaded CPython 3.11Windows x86-64

geolinear-0.3.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (351.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

geolinear-0.3.0-cp311-cp311-macosx_11_0_arm64.whl (291.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

geolinear-0.3.0-cp310-cp310-win_amd64.whl (266.5 kB view details)

Uploaded CPython 3.10Windows x86-64

geolinear-0.3.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (351.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

geolinear-0.3.0-cp310-cp310-macosx_11_0_arm64.whl (290.6 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file geolinear-0.3.0.tar.gz.

File metadata

  • Download URL: geolinear-0.3.0.tar.gz
  • Upload date:
  • Size: 109.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for geolinear-0.3.0.tar.gz
Algorithm Hash digest
SHA256 66d00994a41e70cac785b7b982a000dcc6571bc9eedf8f39c891d5ff33ffe5ca
MD5 f2730d5746e091715a5932b75fd7abc7
BLAKE2b-256 edca348b3cc28f85f43ec24e31e8a1b0ba39ab945f97a12168cb133d9a2a95cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for geolinear-0.3.0.tar.gz:

Publisher: build_wheels.yml on jpeaceau/GeoLinear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file geolinear-0.3.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: geolinear-0.3.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 268.4 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for geolinear-0.3.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 a16eb5f36f4be9728bb76f29c984e1629a5b452a4a32f74e0d090dc2b2130b63
MD5 f4d21013bb39aacaec8f384fa0aa3445
BLAKE2b-256 fded95e31a949fe8df04f94acc44997adc576043f192929554d6cacf2aa38e1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for geolinear-0.3.0-cp313-cp313-win_amd64.whl:

Publisher: build_wheels.yml on jpeaceau/GeoLinear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file geolinear-0.3.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for geolinear-0.3.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9365369f30917da18f043f6ef778ff6fde003e5238ee43da00e145f29a1ed9fe
MD5 dbd86460c713fe9552ff0e9ca297ff54
BLAKE2b-256 cd601a60c1565e72d3e3716a906eb67084f9674acb78cb342a0764d6260fd3b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for geolinear-0.3.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yml on jpeaceau/GeoLinear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file geolinear-0.3.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for geolinear-0.3.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8577db311fe79a1d6442786e176bc2e90e609448ca153221ac091c6742ded993
MD5 5f50b476410436e147d5a573c4f24b26
BLAKE2b-256 eaacc50dd3d6c11efff8f0f72a7e023ed764d923332801d4506124de5d6936f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for geolinear-0.3.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: build_wheels.yml on jpeaceau/GeoLinear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file geolinear-0.3.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: geolinear-0.3.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 268.4 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for geolinear-0.3.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b9af4adfddf5726b15f898491caad454207d48f3eb1c6420b9a9393e3675f416
MD5 25eb500493ff710a8d3634faca0ab7e9
BLAKE2b-256 12d46612a09ddbec0a2b9df86686816e191daf261dab4fcae0a49ce3448315b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for geolinear-0.3.0-cp312-cp312-win_amd64.whl:

Publisher: build_wheels.yml on jpeaceau/GeoLinear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file geolinear-0.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for geolinear-0.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6aabf724931cdf6fd8348a1596a51910d5446524636ef65fe23abd28447de151
MD5 67c92ab05dfec8b01f3d6b98ec2f2609
BLAKE2b-256 dc68e57d5a97afee05168b7cf542c502d555c721bd9507fac385a95f796acf66

See more details on using hashes here.

Provenance

The following attestation bundles were made for geolinear-0.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yml on jpeaceau/GeoLinear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file geolinear-0.3.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for geolinear-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7fa82d891f9477aa68429b23b95f0995e6a86b1c9cf3796fac32dc2fcaa5b4d7
MD5 22ae7e3fe89a43d842f3aa6dd186cd13
BLAKE2b-256 156a34686c12bee8643cb7bb2811057488f43eba5d6d615d427c65db21bd3e54

See more details on using hashes here.

Provenance

The following attestation bundles were made for geolinear-0.3.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: build_wheels.yml on jpeaceau/GeoLinear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file geolinear-0.3.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: geolinear-0.3.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 267.1 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for geolinear-0.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 015720004547eabcb9753a45e2ccc9894b4d7fa5700935e593579996c341dd46
MD5 77dbda09ef0d0f71d24227f1f5c5fea8
BLAKE2b-256 bf36b6426cb423dece306725f345d4bedfb7b3b8c90150c529fa39e7069fd017

See more details on using hashes here.

Provenance

The following attestation bundles were made for geolinear-0.3.0-cp311-cp311-win_amd64.whl:

Publisher: build_wheels.yml on jpeaceau/GeoLinear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file geolinear-0.3.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for geolinear-0.3.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 035f751bff92bc4809ae000f40b91c0e971d72053c795f5ec12e899b5dd4193f
MD5 fbe1e1334d265c54a5659d957927476e
BLAKE2b-256 f09c626873dee56757630d99e0bebc270211ed959638b8c4dcaec81656ca78ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for geolinear-0.3.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yml on jpeaceau/GeoLinear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file geolinear-0.3.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for geolinear-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d568f5b1bfa9bfe09161f1cb83b6b19480a18d259a44102125e3bb73b34ab9d4
MD5 fb907e204ad75237ed91b98d9e1ee5cd
BLAKE2b-256 0a43a6a8706f56119be866fc9d98aeb05640332b5be6c87e6f9fd7a0b5ec4fa1

See more details on using hashes here.

Provenance

The following attestation bundles were made for geolinear-0.3.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: build_wheels.yml on jpeaceau/GeoLinear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file geolinear-0.3.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: geolinear-0.3.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 266.5 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for geolinear-0.3.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 7e07c0ee9cb091005a898f82cc66fc3f8071ccf323fe9222a038a6791468539f
MD5 807978dabe843f72317ad65a6e6fba37
BLAKE2b-256 52df6d5a254ba5bbc638de436cdef94cc1ff7d2b03f385d4cf2e0a9f0c437c24

See more details on using hashes here.

Provenance

The following attestation bundles were made for geolinear-0.3.0-cp310-cp310-win_amd64.whl:

Publisher: build_wheels.yml on jpeaceau/GeoLinear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file geolinear-0.3.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for geolinear-0.3.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 df0e3be903128ce44127482836e6858c594bb91ac1c6cce45e88626c33584bcd
MD5 f39d1428146547be963b6263c0e1ebf1
BLAKE2b-256 eab246747a7be899038501843a6578c8a292f5d4ee71a2498920aeb21ba2a7a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for geolinear-0.3.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yml on jpeaceau/GeoLinear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file geolinear-0.3.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for geolinear-0.3.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6bb8d124a01f3f8c70cc2fb37627f96973a7169838e16b7c7d738c15607036f6
MD5 3205ff8fc569206aa8920ca0b96785df
BLAKE2b-256 b7c07267d5e3eb1647cf74eeeff1d97c01afb566a5e8a66a2160b7200a3da0fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for geolinear-0.3.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: build_wheels.yml on jpeaceau/GeoLinear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page