Skip to main content

Confidence intervals and p-values for sci-kit learn.

Project description

Statkit

Supplement your sci-kit learn models with 95 % confidence intervals, p-values, and decision curves.

Description

  • 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.

Net benefit curve

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.

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

statkit-0.2.1.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

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

statkit-0.2.1-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file statkit-0.2.1.tar.gz.

File metadata

  • Download URL: statkit-0.2.1.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for statkit-0.2.1.tar.gz
Algorithm Hash digest
SHA256 4d4556316b3baf6433976cee61f9d6a1f70b8cc2697f517f79c069294b2143f8
MD5 637e2b7fd65151e60b86bbf4e1f8e0e9
BLAKE2b-256 908d2ef5ca9416be5ae8549099eb1bb915cfc82bb075c5d07cc4a38795589312

See more details on using hashes here.

File details

Details for the file statkit-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: statkit-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for statkit-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 767dfdf8f68608dfe66fabf6596db4e39ce1659e8d88b85f91c7e540c45f8eb9
MD5 bddf045a3a3773cf7e69096c427d73d2
BLAKE2b-256 f65becb64c0992a6a6b8502b077c7cf2c3f4e32b3cb24e77eb56d1baeeb6d385

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