Skip to main content

Patient Rule Induction Method for Python

This module implements the Patient Rule Induction Method (PRIM) for scenario discovery in Python. This is a standalone version of the PRIM algorithm implemented in the EMA Workbench by Jan Kwakkel, which is based on the sdtoolkit R package developed by RAND Corporation. All credit goes to Jan Kwakkel for developing the original code. This standalone version of PRIM was created and maintained by David Hadka.

Licensed under the GNU General Public License, version 3 or later.

Test and Publish PyPI PyPI

Installation

To install the latest PRIM release, run the following command:

    pip install prim

To install the latest development version of PRIM, run the following commands:

    pip install -U build setuptools
    git clone https://github.com/Project-Platypus/PRIM.git
    cd PRIM
    python -m build
    python -m pip install --editable .

Usage

Below shows the interactive use of the PRIM module for finding the first box. In this example, we are interested in cases where the response is greater than 0.5 (as indicated by the threshold and threshold_type arguments). After creating the Prim object, we invoke find_box() to find the first box containing cases of interest followed by box.show_tradeoff() to display the tradeoff between coverage and density for each peeling/pasting trajectory.

    import prim
    import pandas as pd
    import matplotlib.pyplot as plt

    df = pd.DataFrame(np.random.rand(1000, 3), columns=["x1", "x2", "x3"])
    response = df["x1"]*df["x2"] + 0.2*df["x3"]
    
    p = prim.Prim(df, response, threshold=0.5, threshold_type=">")
    
    box = p.find_box()
    box.show_tradeoff()
    
    plt.show()

You can interact with the tradeoff plot by hovering the mouse over points to view the stats, as shown below.

Tradeoff plot

Clicking a point shows additional details in a separate window.

Details view

This module extends EMA Workbench's support for categorical data by allowing the categorical data to be plotted in the pairwise scatter plot:

Categorical data

Also note the Prev / Next buttons on this window allowing navigation to adjacent peeling trajectories without having to return to the tradeoff plot.

Release files for PRIM 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PRIM 1.0.0
File Size Uploaded
prim-1.0.0.tar.gz 60.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for PRIM 1.0.0
File Interpreter ABI Platform
PRIM-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 116.2 kB

Release files / prim-1.0.0.tar.gz

Download URL prim-1.0.0.tar.gz
Size 60.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1b0be0860cfe23966493bbe901976054882e1edb4dd15bbf556311490ddc9620
BLAKE2b-256 checksum
How to use checksums
ca6f445620585de19c2554d7d313e56fa0737a2de9e3e3b3c472ae63c76c644d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release files / PRIM-1.0.0-py3-none-any.whl

Download URL PRIM-1.0.0-py3-none-any.whl
Size 55.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d43094feae47d3bac9b337935f5c2ccfddcf9003b36d493bd53f5928ccc45209
BLAKE2b-256 checksum
How to use checksums
2d3493bf57da77dbf54460891e0e243824e7d916e94b0907d0512395799bed00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.5.0

2 release files

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page