.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_classification_survival.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_classification_survival.py: Classification and survival =========================== The classification metrics come from scikit-learn and the survival estimate from lifelines; depictr redraws both under the shared theme. The survival figure adds a number-at-risk table beneath the curves in one call. .. GENERATED FROM PYTHON SOURCE LINES 9-17 .. code-block:: Python import numpy as np import depictr as dp ct = dp.clinical_trial() score = 1 / (1 + np.exp(-ct["biomarker"])) # a probability-like score .. GENERATED FROM PYTHON SOURCE LINES 18-19 An ROC curve with the area under the curve. .. GENERATED FROM PYTHON SOURCE LINES 19-22 .. code-block:: Python p = dp.roc_curve_plot(ct["adverse_event"], score) p .. image-sg:: /auto_examples/images/sphx_glr_plot_classification_survival_001.png :alt: plot classification survival :srcset: /auto_examples/images/sphx_glr_plot_classification_survival_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 23-24 A calibration (reliability) curve. .. GENERATED FROM PYTHON SOURCE LINES 24-27 .. code-block:: Python p = dp.calibration_plot(ct["adverse_event"], score) p .. image-sg:: /auto_examples/images/sphx_glr_plot_classification_survival_002.png :alt: plot classification survival :srcset: /auto_examples/images/sphx_glr_plot_classification_survival_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 28-29 A confusion-matrix heatmap, normalised by the true class. .. GENERATED FROM PYTHON SOURCE LINES 29-33 .. code-block:: Python p = dp.confusion_matrix_plot(ct["adverse_event"], (score > 0.12).astype(int), normalise="true") p .. image-sg:: /auto_examples/images/sphx_glr_plot_classification_survival_003.png :alt: plot classification survival :srcset: /auto_examples/images/sphx_glr_plot_classification_survival_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 34-36 Kaplan-Meier curves with a log-rank test and a number-at-risk table. The legend sits in the empty top-right the descending curves leave behind. .. GENERATED FROM PYTHON SOURCE LINES 36-39 .. code-block:: Python p = dp.survival_plot(ct["time"], ct["event"], group=ct["arm"], risk_table=True, legend_inside=True, title="Survival by arm") p .. image-sg:: /auto_examples/images/sphx_glr_plot_classification_survival_004.png :alt: plot classification survival :srcset: /auto_examples/images/sphx_glr_plot_classification_survival_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.719 seconds) .. _sphx_glr_download_auto_examples_plot_classification_survival.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_classification_survival.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_classification_survival.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_classification_survival.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_