Skip to main content

Prediction probabilities with a linear programming constraint during label assignment.

Project description

PredLP

Prediction probabilities with a linear programming constraint during label assignment.

Usage

Example label contraint imposed using the package predlp via this code:

from predlp.solver import pred_prob_lp

# ML outputs feed into predlp constraints
class_names = ['label_a', 'label_b', 'label_c']
label_counts = {'label_a': 2, 'label_b': 1, 'label_c': 1}
pred_probs = [
    [0.6*, 0.3,  0.1],
    [0.2,  0.5*, 0.3],
    [0.8*, 0.1,  0.1],
    [0.5,  0.1,  0.4*]
]

# Run through solver and optimize for probability scores
pred_after_lp = pred_prob_lp(class_names=class_names, label_counts= label_counts, pred_probs=pred_probs)

# Output of predlp, highlighted in array (*)
pred_after_lp == ['label_a', 'label_b', 'label_a', 'label_c']

Parameters

  • class_names (list): The list should be in the order that matches the pred_prob array. So if class 0 is ‘linear’ and class 1 is ‘programming’, then class_names = ['linear', 'programming'].
  • label_counts (dict): A dictionary specifying the expected count for each label. The keys represent the class (N), and the values (K) constraints.
  • pred_probs (np.array): A 2D array of shape (N, K) containing the model predicted probabilities for each label. Each row corresponds to a class, corresponding to the class_name parameter, and the columns represent probabilities for classes {0, 1, ..., K-1}.

Returns

  • pred_lp (list): A list of predicted labels, with a total length of N. The list satisfies the constraints defined by label_counts and is optimized to maximize the total probability score across all predictions.

Citation and related publications

Here are relevant papers to cite if you use this package:

Life in the FastText Lane: Harnessing Linear Programming Constrained Machine Learning for Classifications Revision (click to show bibtex)
@inproceedings{
    title={Life in the FastText Lane: Harnessing Linear Programming Constrained Machine Learning for Classifications Revision},
    author={Justin Evans, Laura Wile},
    conference={Statistics Canada's International Methodology Symposium: The Future of Official Statistics},
    year={2024}
}

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

predlp-0.1.0.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

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

predlp-0.1.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: predlp-0.1.0.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for predlp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 51014b933b65ed0b7a2550a36a5289c746b4249c79a1b74925a44408fb5c948f
MD5 4b7ead307bbfee186adfca8a0b4c2ea6
BLAKE2b-256 c1105e8860f512a580d2cbedb21c99051db79a4a56f94f1140a4695817029599

See more details on using hashes here.

Provenance

The following attestation bundles were made for predlp-0.1.0.tar.gz:

Publisher: release.yaml on justinj-evans/predlp

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

File details

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

File metadata

  • Download URL: predlp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for predlp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 216a63237a88e35d84f86078b30f8d10fbf4f6a401504be83631d6ca945fdb96
MD5 02fad3d954eec4d3a596b4cccfa1f054
BLAKE2b-256 56b1185627e77dc17a4b31775125824accca5807d4e8babba10302778bde7aa1

See more details on using hashes here.

Provenance

The following attestation bundles were made for predlp-0.1.0-py3-none-any.whl:

Publisher: release.yaml on justinj-evans/predlp

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