Skip to main content

A simple random baseline that accounts for evaluation set size and reuse

Project description

Maximum random baseline

This package implements a simple random baseline that accounts for dataset size and evaluation set reuse.

The baseline is the expected maximum accuracy across multiple random classifiers, as described in Stronger Random Baselines for In-Context Learning.

Installation

You can install this package with pip:

pip install max-random-baseline

This package requires numpy and the PoiBin Python implementation of Poisson binomial random variables. For ease of installation, PoiBin is included in this package. PoiBin is copyright (c) 2016 Mika J. Straka under an MIT License.

Quick start

The simplest way to get baseline numbers is to import and call the function max_random_baseline:

from max_random_baseline import max_random_baseline

The syntax is max_random_baseline(n, p, t):

  • n: number of examples in the dataset
  • p: probability of guessing correctly on a single example. In the binary classification setting, p = 0.5.
  • t: number of random classifiers to take the maximum over. For example, if you are comparing the baseline to the best validation accuracy across 10 different classifiers, then set t = 10.

For example, to get the expected maximum accuracy among 10 classifiers that guess uniformly at random on a binary classification task with n = 100 examples: max_random_baseline(100, 0.5, 10).

Datasets with different numbers of labels for each example

There are additional formats for specifiying the probability of guessing correctly on each example. Say you have a dataset with n = 100 examples, where 50 of the examples have 2 possible labels (0.5 probability of guessing correctly) and the other 50 have 5 possible labels (0.2 probability of guessing correctly). The two equivalent syntaxes for getting the maximum random baseline for this dataset with t = 10 are:

  • max_random_baseline(100, {2: 50, 5: 50}, 10)

    The second argument maps a number of possible labels to the number of examples with that many labels.

  • max_random_baseline(100, [0.5] * 50 + [0.2] * 50, 10)

    The second argument is a list of n probabilities, one for each of the examples.

Additional features

  • max_random_p_value(acc, n, p, t)

    Returns the $p$-value of a given accuracy acc with respect to the maximum random baseline with parameters n, p, t.

  • max_random_pmf(num_correct, n, p, t)

    Evaluates the probability mass function of the maximum order statistic of t draws from the Poisson binomial random variable with parameters n and p at the value num_correct. Note that num_correct is an integer between 0 and n (inclusive) rather than an accuracy.

  • max_random_F(num_correct, n, p, t)

    Evaluates the distribution function of the maximum order statistic of t draws from the Poisson binomial random variable with parameters n and p at the value num_correct. Note that num_correct is an integer between 0 and n (inclusive) rather than an accuracy.

In all cases, the parameters n, p, and t are as described above. For all of these functions, the p argument can also take the additional formats described above.

We also expose the class MaxOrderStatisticPoissonBinomial, allowing for faster calculations of the baseline when the values of n and p are fixed (t can still take different values).

For example, to print the maximum random baseline for fixed n=100 and p=0.5 with two values of t:

from max_random_baseline import MaxOrderStatisticPoissonBinomial
max_order_statistic = MaxOrderStatisticPoissonBinomial(100, 0.5)
print(max_order_statistic.max_random_baseline(t=10))
print(max_order_statistic.max_random_baseline(t=100))

Parameter ranges used in the paper have been tested. Calculating values for large n will take a while. If you find numerical instability outside these ranges, please report an issue.

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

max_random_baseline-0.1.1.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

max_random_baseline-0.1.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file max_random_baseline-0.1.1.tar.gz.

File metadata

  • Download URL: max_random_baseline-0.1.1.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.6

File hashes

Hashes for max_random_baseline-0.1.1.tar.gz
Algorithm Hash digest
SHA256 dd6c8f4a683c4acf89fce09b4e773a612eebede5a90b758d2bad9407d8bfd63a
MD5 39e939545d2066b5e4e140ae4416fe61
BLAKE2b-256 bbd062d8d610a1d7092e47d0c66208cd58c65fac1c336312351610d3a03997d4

See more details on using hashes here.

File details

Details for the file max_random_baseline-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for max_random_baseline-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c5eeb38d9d7f6b528295aad9d34fca861449aa88ee988878a84291ee37e7d630
MD5 4ed24f9b6d2ac5a89534bb63f541b5f1
BLAKE2b-256 e95557e8f4a0e567d28bc08f991d8146591d1bcadc51810bd38d6b6b09d03148

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