.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples\4_testing\plot_1_weakspot_cls.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 or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_4_testing_plot_1_weakspot_cls.py: WeakSpot: Classification ===================================== .. GENERATED FROM PYTHON SOURCE LINES 8-9 Experiment initialization and data preparation .. GENERATED FROM PYTHON SOURCE LINES 9-17 .. code-block:: default from piml import Experiment from piml.models import XGB2Classifier exp = Experiment() exp.data_loader(data="TaiwanCredit", silent=True) exp.data_summary(feature_exclude=["LIMIT_BAL", "SEX", "EDUCATION", "MARRIAGE", "AGE"], silent=True) exp.data_prepare(target="FlagDefault", task_type="classification", silent=True) .. GENERATED FROM PYTHON SOURCE LINES 18-19 Train Model .. GENERATED FROM PYTHON SOURCE LINES 19-21 .. code-block:: default exp.model_train(XGB2Classifier(), name="XGB2") .. GENERATED FROM PYTHON SOURCE LINES 22-23 Histogram-based weakspot for a single feature .. GENERATED FROM PYTHON SOURCE LINES 23-28 .. code-block:: default results = exp.model_diagnose(model="XGB2", show="weakspot", slice_method="histogram", slice_features=["PAY_1"], threshold=1.1, min_samples=100, return_data=True, figsize=(5, 4)) results.data .. image-sg:: /auto_examples/4_testing/images/sphx_glr_plot_1_weakspot_cls_001.png :alt: Weak Regions :srcset: /auto_examples/4_testing/images/sphx_glr_plot_1_weakspot_cls_001.png :class: sphx-glr-single-img .. raw:: html
[PAY_1 PAY_1) #Test #Train test_ACC train_ACC Gap
0 0.2 0.8 1350 5440 0.7052 0.6888 0.0164


.. GENERATED FROM PYTHON SOURCE LINES 29-30 Histogram-based weakspot for two features .. GENERATED FROM PYTHON SOURCE LINES 30-35 .. code-block:: default results = exp.model_diagnose(model="XGB2", show="weakspot", slice_method="histogram", slice_features=["PAY_1", "PAY_2"], threshold=1.1, min_samples=100, return_data=True, figsize=(5, 4)) results.data .. image-sg:: /auto_examples/4_testing/images/sphx_glr_plot_1_weakspot_cls_002.png :alt: Weak Regions :srcset: /auto_examples/4_testing/images/sphx_glr_plot_1_weakspot_cls_002.png :class: sphx-glr-single-img .. raw:: html
[PAY_1 PAY_1) [PAY_2 PAY_2) #Test #Train test_ACC train_ACC Gap
0 0.4 0.5 0.3750 0.5625 69 244 0.8551 0.7336 0.1215
1 0.3 0.4 0.0000 0.2500 191 800 0.6963 0.6675 0.0288
2 0.2 0.3 0.1111 0.2222 268 956 0.7276 0.7207 0.0069
3 0.3 0.4 0.3750 0.6250 322 1354 0.7205 0.7164 0.0041
4 0.2 0.3 0.3333 0.5556 351 1430 0.6154 0.6119 0.0035
5 0.0 0.1 0.3750 0.6250 77 357 0.6234 0.6303 -0.0069


.. GENERATED FROM PYTHON SOURCE LINES 36-37 Histogram-based weakspot for a single feature on test set .. GENERATED FROM PYTHON SOURCE LINES 37-41 .. code-block:: default results = exp.model_diagnose(model="XGB2", show="weakspot", slice_method="histogram", slice_features=["PAY_1"], threshold=1.1, min_samples=100, use_test=True, return_data=True, figsize=(5, 4)) results.data .. image-sg:: /auto_examples/4_testing/images/sphx_glr_plot_1_weakspot_cls_003.png :alt: Weak Regions :srcset: /auto_examples/4_testing/images/sphx_glr_plot_1_weakspot_cls_003.png :class: sphx-glr-single-img .. raw:: html
[PAY_1 PAY_1) #Test #Train test_ACC train_ACC Gap
0 0.2222 0.4444 1265 5090 0.6964 0.6876 0.0088


.. GENERATED FROM PYTHON SOURCE LINES 42-43 Histogram-based weakspot for a single feature using AUC metric .. GENERATED FROM PYTHON SOURCE LINES 43-48 .. code-block:: default results = exp.model_diagnose(model="XGB2", show="weakspot", slice_method="histogram", slice_features=["PAY_1"], threshold=1.1, min_samples=100, metric="AUC", return_data=True, figsize=(5, 4)) results.data .. image-sg:: /auto_examples/4_testing/images/sphx_glr_plot_1_weakspot_cls_004.png :alt: Weak Regions :srcset: /auto_examples/4_testing/images/sphx_glr_plot_1_weakspot_cls_004.png :class: sphx-glr-single-img .. raw:: html
[PAY_1 PAY_1) #Test #Train test_AUC train_AUC Gap
0 0.2 0.3 752 2936 0.6478 0.7071 -0.0593
1 0.1 0.2 3521 13975 0.6350 0.6970 -0.0620
2 0.3 0.4 513 2154 0.5481 0.6325 -0.0844
3 0.5 0.6 14 62 0.5250 0.7179 -0.1929
4 0.6 0.7 1 25 NaN 0.6314 NaN
5 0.7 0.8 1 10 NaN 0.4400 NaN


.. GENERATED FROM PYTHON SOURCE LINES 49-50 Tree-based weakspot for a single feature using ACC metric .. GENERATED FROM PYTHON SOURCE LINES 50-55 .. code-block:: default results = exp.model_diagnose(model="XGB2", show="weakspot", slice_method="tree", slice_features=["PAY_1"], threshold=1.1, min_samples=100, metric="ACC", return_data=True, figsize=(5, 4)) results.data .. image-sg:: /auto_examples/4_testing/images/sphx_glr_plot_1_weakspot_cls_005.png :alt: Weak Regions :srcset: /auto_examples/4_testing/images/sphx_glr_plot_1_weakspot_cls_005.png :class: sphx-glr-single-img .. raw:: html
[PAY_1 PAY_1) #Test #Train test_ACC train_ACC Gap
0 0.2778 1.0000 602 2528 0.7276 0.6994 0.0282
1 0.1667 0.2778 752 2936 0.6862 0.6798 0.0063


.. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 44.136 seconds) **Estimated memory usage:** 43 MB .. _sphx_glr_download_auto_examples_4_testing_plot_1_weakspot_cls.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/selfexplainml/piml-toolbox/main?urlpath=lab/tree/./docs/_build/html/notebooks/auto_examples/4_testing/plot_1_weakspot_cls.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_1_weakspot_cls.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_1_weakspot_cls.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_