Skip to main content

Python library to score predictions

Project description

Code style: Black tests

Python Prediction Scorer

The purpose of this library is to help you compare predictions.

Installation

pip install predictionscorer

Usage

For example, say that George and Kramer were predicting the outcome of the 2016 US presidential election. George said that Donald Trump had a 40 percent probability of winning, while Kramer put Trump's chances at 65 percent.

Considering that Trump won, Kramer's prediction was better than George's. But how much better? In order to find out, we must assign numerical scores to their predictions and compare them. That's what this library does.

The following code scores the predictions.

from predictionscorer import calculators, predictions

george = predictions.Prediction(
    probabilities=[60, 40] # George put Clinton at 60 % and Trump at 40 %.
)
kramer = predictions.Prediction(
    probabilities=[35, 65] # Kramer put Clinton at 35 % and Trump at 65 %.
)

brier = calculators.Brier(
    true_alternative_index=1 # Alternative 0 is Hillary Clinton. Alternative 1 is Donald Trump.
)

print(brier.calculate(george)) # Decimal('0.72')
print(str(brier.calculate(kramer))) # '0.245'

As you can see, Kramer's score is lower than George's. How can a better prediction give a lower score? The thing is, with Brier scores, the lower, the better. To help your intuition, you can consider a Brier score as the distance from the truth. (A perfect prediction yields 0, while the worst possible prediction yields 2.)

Questions where the order of alternatives matters is currently not supported.

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

predictionscorer-0.1.1.tar.gz (2.7 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: predictionscorer-0.1.1.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for predictionscorer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 802589e77f42601c2963fa8fbab9b3e754605cf2ad1a186e6fcfa779def184a7
MD5 9a6140195f67f614c11d6077783bf86f
BLAKE2b-256 5e12934c7b2db3123d6196e837879463661c4e1a34f4afcd275914c621efbc66

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page