Skip to main content

Python code to compute and plot (truncated, weighted) area under gain curves (agc)

Project description

AGC - Area under Gain Curves

Python code to compute and plot (truncated, weighted) area under gain curves (AGC)

For binary classification, gain curves are a nice alternative to ROC curves in that they can naturally be truncated to focus on the top scoring points only. Moreover, the data points can have weights. In this code, we provide two functions:

  • agc_score: Compute the area under the gain curve (AGC) for binary labelled data
  • gain_curve: Compute the proportion of data points and true positive rate for all thresholds, for plotting

The first function returns the normalized area by default (improvement over random, so this could be negative). The functions can be imported from the supplied agc.py file, or installed via pip install agc.

A simple example

## create toy binary labels and scores for illustration
labels = np.concatenate((np.repeat(1,100),np.repeat(0,900)))
scores = np.concatenate((np.random.uniform(.4,.8,100),np.random.uniform(.2,.6,900)))

## compute (normalized) area under the gain curve
print(agc_score(labels, scores))

## compute (un-normalized) area under the gain curve
print(agc_score(labels, scores, normalized=False))

## now the area for the top scoring 10% of the points
print(agc_score(labels, scores, truncate=0.1))

## or top scoring 100 points
print(agc_score(labels, scores, truncate=100))

More details in Notebooks:

For a quick introduction, see the following notebook: https://github.com/ftheberge/agc/blob/main/agc/agc_intro.ipynb also available in markup format: https://github.com/ftheberge/agc/blob/main/intro/agc_intro.md

For more details, see the notebook: https://github.com/ftheberge/agc/blob/main/agc/agc.ipynb also available in markup format: https://github.com/ftheberge/agc/blob/main/example/agc.md

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

agc-0.0.5.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

agc-0.0.5-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file agc-0.0.5.tar.gz.

File metadata

  • Download URL: agc-0.0.5.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.9

File hashes

Hashes for agc-0.0.5.tar.gz
Algorithm Hash digest
SHA256 31fa50b8015745fe2c302d69a9f176cf77f1379d79180b831315b7e30321a8cb
MD5 1e92926d6ba0f0de2ada55001c4864e0
BLAKE2b-256 c6ad6888fe6b0205f8bb31c9c2af9c1a4683f0fe17e6427f2434a8c251bae319

See more details on using hashes here.

File details

Details for the file agc-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: agc-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.9

File hashes

Hashes for agc-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 467485d687d63c384f74642f428ea127a67774bf1c7268b9277482df132bb998
MD5 35b556b4c7d07dfc8ffd44d217ba829c
BLAKE2b-256 d6d13e9bafc419ad96c5d54607fc51da85e1ff5a8f34d2d31ba9c61ba5f3061c

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