Skip to main content

Automated propensity model selection and scoring for discrete/continuous actions.

Project description

AutoPropensity — Auto-select p(A|X) by Validation Log-Likelihood

Goal: Given a dataset with states X and actions A (either discrete or continuous), this library automatically searches a small, sensible family of propensity models and selects the configuration that maximizes validation log-likelihood. You can then rebuild that model on any subset/split and score p(A|X) for new points.

TL;DR — Pass your data and whether A is discrete or continuous. Get back a config you can reuse anywhere.


Why this is helpful

  • No guesswork: Stop hand-picking models every time you see new data.
  • Unified API: Works for both discrete and continuous action spaces.
  • Leak-free workflow: Tune once → save config → rebuild on any split (train/val/test/production).
  • Lightweight & type-safe: Small, readable code with few dependencies (scikit-learn, numpy, scipy, matplotlib for plots).

What it searches

By default the tuner explores:

  • Discrete A:
    • Logistic / Multinomial Regression (+ optional StandardScaler, PCA/PLS)
  • Continuous A:
    • Linear-Gaussian (residual sigma estimated)
    • Gaussian Process (with RBF + white noise)
    • Optional KDE for higher-dimensional cases (off by default in 1-D A for stability)
    • Optional ANN (MLP) toggle

Dimensionality reduction (PCA/PLS) and scaling are considered in the grid.

Selection metric: validation log-likelihood (LL).
For discrete models, “closer to 0” is better. For continuous densities, “higher” is better.


Quick Start

import auto_propensity as ap
from auto_propensity import PropensityModelBuilder

# X: (n, d_x), A: (n,) for discrete or (n, d_a)/(n,) for continuous
builder = PropensityModelBuilder(X, A, action_type='discrete' or 'continuous', test_size=0.25, random_state=42)
result = builder.tune(verbose=False)
best_cfg = result["config"]

# Rebuild a fresh model on any subset (no leakage)
pm = ap.make_from_config(X_train, A_train, best_cfg, random_state=42)
p, avg_ll, per_ll = ap.score_and_ll(pm, X_test, A_test)

Visualization

You can enable detailed tracing of the tuning process by setting builder.trace_on = True. This allows you to visualize and compare candidate models using the provided plotting functions:

  • plot_family_variants(): Compare variants within each model family.
  • plot_best_per_family(): Compare the best models across different families.

Example usage:

builder.trace_on = True
result = builder.tune(verbose=False)

import os, matplotlib.pyplot as plt
os.makedirs("figs", exist_ok=True)

fig1 = builder.plot_family_variants()
fig1.savefig("figs/variants_discrete.png", dpi=150, bbox_inches="tight")
plt.close(fig1)

fig2 = builder.plot_best_per_family()
fig2.savefig("figs/best_per_family_discrete.png", dpi=150, bbox_inches="tight")
plt.close(fig2)

Acknowledgment

Parts of the implementation and code structuring were developed with the assistance of ChatGPT.
The conceptual design and research ideas, however, were entirely original and not derived from ChatGPT.

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

auto_propensity-0.1.0.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

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

auto_propensity-0.1.0-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file auto_propensity-0.1.0.tar.gz.

File metadata

  • Download URL: auto_propensity-0.1.0.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.17

File hashes

Hashes for auto_propensity-0.1.0.tar.gz
Algorithm Hash digest
SHA256 80232133075d0b27736ee5ebfa91110236e763047c96846a5229f2f145179e1f
MD5 5d43f2524081dc1d4612c421e0d094f2
BLAKE2b-256 00824688c96d03c35622b16da6181b1436366a4c5b88b1a8fefb9a98b533bca7

See more details on using hashes here.

File details

Details for the file auto_propensity-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for auto_propensity-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 78cac935220f58b461c3852b54b3ce0c1ce39bf4a41b746e44ab09987b0618cd
MD5 b61f6c580178fe420537347802fb87cb
BLAKE2b-256 aaa5d74ad506673db7dccfe4ec62cf5568c19a6f8b15d25bf7a1d339ebacf548

See more details on using hashes here.

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