Behavioral Signal Analysis for User Understanding - Detect bots, shared accounts, and UI confusion
Project description
PyRevealed
Production-ready revealed preference analysis. Test if choices are internally consistent, quantify behavioral consistency, and analyze decision patterns.
Based on: Chambers, C. P., & Echenique, F. (2016). Revealed Preference Theory. Cambridge University Press.
Installation
pip install pyrevealed
For visualization support:
pip install pyrevealed[viz]
Quick Start
from pyrevealed import BehaviorLog, validate_consistency, compute_integrity_score
import numpy as np
# Two purchase observations: prices and quantities
log = BehaviorLog(
cost_vectors=np.array([[1.0, 2.0], [2.0, 1.0]]),
action_vectors=np.array([[3.0, 1.0], [1.0, 3.0]])
)
# Check if choices are consistent with utility maximization
is_consistent = validate_consistency(log) # True
# Get integrity score (0 = inconsistent, 1 = perfectly consistent)
result = compute_integrity_score(log)
print(f"Integrity: {result.efficiency_index:.2f}") # 1.00
Core Functions
| Function | Returns | Score Meaning |
|---|---|---|
validate_consistency(log) |
bool |
True = rational |
compute_integrity_score(log) |
AEIResult (0-1) |
1 = perfect |
compute_confusion_metric(log) |
MPIResult (0-1) |
0 = no cycles |
fit_latent_values(log) |
UtilityRecoveryResult |
Utility values |
compute_minimal_outlier_fraction(log) |
HoutmanMaksResult (0-1) |
0 = all consistent |
Quick interpretation: Integrity >= 0.95 is excellent, >= 0.90 is good, < 0.70 indicates problems.
Menu-Based Choice
For discrete choices without prices (surveys, recommendations, voting):
from pyrevealed import MenuChoiceLog, validate_menu_sarp, fit_menu_preferences
log = MenuChoiceLog(
menus=[frozenset({0, 1, 2}), frozenset({1, 2}), frozenset({0, 2})],
choices=[0, 1, 0],
item_labels=["Pizza", "Burger", "Salad"]
)
result = validate_menu_sarp(log)
print(f"Consistent: {result.is_consistent}")
prefs = fit_menu_preferences(log)
print(f"Preference order: {prefs.preference_order}")
Documentation
Tutorials
- Budget-Based Analysis - GARP, CCEI, MPI, Bronars power
- Menu-Based Choice - WARP, SARP, attention models
- Welfare Analysis - CV, EV, deadweight loss
- Demand Analysis - Slutsky matrix, integrability
- Stochastic & Production - Logit, IIA, firm behavior
- E-Commerce at Scale - 1.85M Amazon transactions
Features
- Consistency Testing: GARP, WARP, SARP axiom verification
- Behavioral Metrics: Afriat Efficiency Index, Money Pump Index
- Utility Recovery: Reconstruct utility functions from choices
- ML Integration: sklearn-compatible
PreferenceEncoder - Multiple Data Types: Budgets, menus, stochastic choice, production
- Production Ready: Fast parallel processing, validated against R's revealedPrefs
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyrevealed-0.4.2.tar.gz.
File metadata
- Download URL: pyrevealed-0.4.2.tar.gz
- Upload date:
- Size: 4.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da7e45e9a8ba6adce0befcd1651b98fb5fbdbd3f2ccdec27a2c974a05db959c2
|
|
| MD5 |
22ea14e29b500315f28319c344ae3d4d
|
|
| BLAKE2b-256 |
b3668b44fdc05abd2e7b6187bd9d5d98fb18a0a126e27ea2d1d752fae22fccc9
|
File details
Details for the file pyrevealed-0.4.2-py3-none-any.whl.
File metadata
- Download URL: pyrevealed-0.4.2-py3-none-any.whl
- Upload date:
- Size: 175.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab800f0abec141e46211fd5505819b14b79de370ef5d0d79f263decc4c8a3f16
|
|
| MD5 |
398b83b381e518891941327dfd130de6
|
|
| BLAKE2b-256 |
562dc05195635bbf2d44e3f91a03c2efa1a939b8a4294ee68d38ca6f61d680ec
|