lir


Namelir JSON
Version 0.1.25 PyPI version JSON
download
home_pagehttps://github.com/NetherlandsForensicInstitute/lir
Summaryscripts for calculating likelihood ratios
upload_time2023-10-31 13:17:18
maintainer
docs_urlNone
authorNetherlands Forensic Institute
requires_python
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            LIR Python Likelihood Ratio Library
===================================

This library provides a collection of scripts to aid calibration, and
calculation and evaluation of Likelihood Ratios.

## A simple score-based LR system

A score-based LR system needs a scorer and a calibrator. The most basic setup
uses a training set and a test set. Both the scorer and the calibrator are
fitted on the training set.

```python
import lir
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split

# generate some data randomly from a normal distribution
X = np.concatenate([np.random.normal(loc=0, size=(100, 1)),
              np.random.normal(loc=1, size=(100, 1))])
y = np.concatenate([np.zeros(100), np.ones(100)])

# split the data into train and test
X_train, X_test, y_train, y_test = train_test_split(X, y)

# initialize a scorer and a calibrator
scorer = LogisticRegression(solver='lbfgs')  # choose any sklearn style classifier
calibrator = lir.KDECalibrator()  # use plain KDE for calibration
calibrated_scorer = lir.CalibratedScorer(scorer, calibrator)

# fit and predict
calibrated_scorer.fit(X_train, y_train)
lrs_test = calibrated_scorer.predict_lr(X_test)

# print the quality of the system as log likelihood ratio cost (lower is better)
print('The log likelihood ratio cost is', lir.metrics.cllr(lrs_test, y_test), '(lower is better)')
print('The discriminative power is', lir.metrics.cllr_min(lrs_test, y_test), '(lower is better)')

# plot calibration
import lir.plotting
with lir.plotting.show() as ax:
    ax.pav(lrs_test, y_test)
```

The log likelihood ratio cost (Cllr) may be used as a metric of performance.
In this case it should yield a value of around .8, but highly variable due to
the small number of samples. Increase the sample size to get more stable
results.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/NetherlandsForensicInstitute/lir",
    "name": "lir",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Netherlands Forensic Institute",
    "author_email": "fbda@nfi.nl",
    "download_url": "https://files.pythonhosted.org/packages/c1/4d/79b42c65b78b7913d5b50130339e7794d16331f4f2d9c8a44fe02c610348/lir-0.1.25.tar.gz",
    "platform": null,
    "description": "LIR Python Likelihood Ratio Library\n===================================\n\nThis library provides a collection of scripts to aid calibration, and\ncalculation and evaluation of Likelihood Ratios.\n\n## A simple score-based LR system\n\nA score-based LR system needs a scorer and a calibrator. The most basic setup\nuses a training set and a test set. Both the scorer and the calibrator are\nfitted on the training set.\n\n```python\nimport lir\nimport numpy as np\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.model_selection import train_test_split\n\n# generate some data randomly from a normal distribution\nX = np.concatenate([np.random.normal(loc=0, size=(100, 1)),\n              np.random.normal(loc=1, size=(100, 1))])\ny = np.concatenate([np.zeros(100), np.ones(100)])\n\n# split the data into train and test\nX_train, X_test, y_train, y_test = train_test_split(X, y)\n\n# initialize a scorer and a calibrator\nscorer = LogisticRegression(solver='lbfgs')  # choose any sklearn style classifier\ncalibrator = lir.KDECalibrator()  # use plain KDE for calibration\ncalibrated_scorer = lir.CalibratedScorer(scorer, calibrator)\n\n# fit and predict\ncalibrated_scorer.fit(X_train, y_train)\nlrs_test = calibrated_scorer.predict_lr(X_test)\n\n# print the quality of the system as log likelihood ratio cost (lower is better)\nprint('The log likelihood ratio cost is', lir.metrics.cllr(lrs_test, y_test), '(lower is better)')\nprint('The discriminative power is', lir.metrics.cllr_min(lrs_test, y_test), '(lower is better)')\n\n# plot calibration\nimport lir.plotting\nwith lir.plotting.show() as ax:\n    ax.pav(lrs_test, y_test)\n```\n\nThe log likelihood ratio cost (Cllr) may be used as a metric of performance.\nIn this case it should yield a value of around .8, but highly variable due to\nthe small number of samples. Increase the sample size to get more stable\nresults.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "scripts for calculating likelihood ratios",
    "version": "0.1.25",
    "project_urls": {
        "Homepage": "https://github.com/NetherlandsForensicInstitute/lir"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d253e7548be95d875b49a6ee5c61b17e10d8e8bdfeb16442ed82075ff2614db9",
                "md5": "f14dac40ce5b296b298f7aa37107779d",
                "sha256": "e0e16a3d27611e91c9faabf0f134cf5d341da497c1441985cf344f85097b6ae2"
            },
            "downloads": -1,
            "filename": "lir-0.1.25-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f14dac40ce5b296b298f7aa37107779d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 44618,
            "upload_time": "2023-10-31T13:17:16",
            "upload_time_iso_8601": "2023-10-31T13:17:16.359942Z",
            "url": "https://files.pythonhosted.org/packages/d2/53/e7548be95d875b49a6ee5c61b17e10d8e8bdfeb16442ed82075ff2614db9/lir-0.1.25-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c14d79b42c65b78b7913d5b50130339e7794d16331f4f2d9c8a44fe02c610348",
                "md5": "a97a872e6639af13668181a2b171e6c7",
                "sha256": "4a91eb7037cff3221cfec3a0bc3c07d4081449f544527e16899c485104643f24"
            },
            "downloads": -1,
            "filename": "lir-0.1.25.tar.gz",
            "has_sig": false,
            "md5_digest": "a97a872e6639af13668181a2b171e6c7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 37062,
            "upload_time": "2023-10-31T13:17:18",
            "upload_time_iso_8601": "2023-10-31T13:17:18.136480Z",
            "url": "https://files.pythonhosted.org/packages/c1/4d/79b42c65b78b7913d5b50130339e7794d16331f4f2d9c8a44fe02c610348/lir-0.1.25.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-31 13:17:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "NetherlandsForensicInstitute",
    "github_project": "lir",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "lir"
}
        
Elapsed time: 0.25300s