Statkit
Get 95% confidence intervals, p-values, and decision curves for your sci-kit learn models.
Contents
Quickstart
- Estimate 95% confidence intervals for your test scores.
For example, to compute a 95% confidence interval of the area under the receiver operating characteristic curve (ROC AUC):
from sklearn.metrics import roc_auc_score
from statkit.non_parametric import bootstrap_score
y_prob = model.predict_proba(X_test)[:, 1]
auc_95ci = bootstrap_score(y_test, y_prob, metric=roc_auc_score)
print('Area under the ROC curve:', auc_95ci)
- Compute p-value to test if one model is significantly better than another.
For example, to test if the area under the receiver operating characteristic curve (ROC AUC) of model 1 is significantly larger than model 2:
from sklearn.metrics import roc_auc_score
from statkit.non_parametric import paired_permutation_test
y_pred_1 = model_1.predict_proba(X_test)[:, 1]
y_pred_2 = model_2.predict_proba(X_test)[:, 1]
p_value = paired_permutation_test(y_test, y_pred_1, y_pred_2, metric=roc_auc_score)
- Perform decision curve analysis by making net benefit plots of your sci-kit learn models. Compare the utility of different models and with decision policies to always or never take an action/intervention.
from matplotlib import pyplot as plt
from sklearn.datasets import make_blobs
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.linear_model import LogisticRegression
from statkit.decision import NetBenefitDisplay
centers = [[0, 0], [1, 1]]
X_train, y_train = make_blobs(
centers=centers, cluster_std=1, n_samples=20, random_state=5
)
X_test, y_test = make_blobs(
centers=centers, cluster_std=1, n_samples=20, random_state=1005
)
baseline_model = LogisticRegression(random_state=5).fit(X_train, y_train)
y_pred_base = baseline_model.predict_proba(X_test)[:, 1]
tree_model = GradientBoostingClassifier(random_state=5).fit(X_train, y_train)
y_pred_tree = tree_model.predict_proba(X_test)[:, 1]
NetBenefitDisplay.from_predictions(y_test, y_pred_base, name='Baseline model')
NetBenefitDisplay.from_predictions(y_test, y_pred_tree, name='Gradient boosted trees', show_references=False, ax=plt.gca())
Detailed documentation can be on the Statkit API documentation pages.
Installation
pip3 install statkit
Support
You can open a ticket in the Issue tracker.
Contributing
We are open for contributions. If you open a pull request, make sure that your code is:
- Well documented,
- Code formatted with black,
- And contains an accompanying unit test.
Authors and acknowledgment
Hylke C. Donker
License
This code is licensed under the MIT license.
Metadata
Release files for statkit 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| statkit-1.1.0.tar.gz | 73.4 kB | Without provenance | Details for statkit-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| statkit-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for statkit-1.1.0-py3-none-any.whl |
Total release size: 97.0 kB
Release files / statkit-1.1.0.tar.gz
| Download URL | statkit-1.1.0.tar.gz |
|---|---|
| Size | 73.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fcfe90c94c0c5680d08a986b9af15d2fc678f6271b5f74afb1b36d63253073f0
|
|
BLAKE2b-256 checksum How to use checksums |
47f7da7f7879c36f2cbe02a818f121a1f8efa401ad22dd0b3cbc21ca7cf465c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Release files / statkit-1.1.0-py3-none-any.whl
| Download URL | statkit-1.1.0-py3-none-any.whl |
|---|---|
| Size | 23.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7dc0492bebb3eb1eaba58b731964ddad49e15fc6295b61d0d3afa98a4c6849a2
|
|
BLAKE2b-256 checksum How to use checksums |
b399d3b2511dcb7a38735f7748f4b62439a39b8d9b173cd16b17f5d2a9dbf5fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Security for statkit 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.