.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples\3_models\plot_5_xgb2_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_3_models_plot_5_xgb2_cls.py: XGB-2 Classification (Taiwan Credit) ===================================== .. GENERATED FROM PYTHON SOURCE LINES 8-9 Experiment initialization and data preparation .. GENERATED FROM PYTHON SOURCE LINES 9-17 .. code-block:: Python 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-24 .. code-block:: Python exp.model_train(model=XGB2Classifier(), name='XGB2') # Train Model with monotonicity constraints on PAY_1 exp.model_train(model=XGB2Classifier(mono_increasing_list=("PAY_1", )), name="Mono-XGB2") .. GENERATED FROM PYTHON SOURCE LINES 25-26 Evaluate predictive performance of XGB2 .. GENERATED FROM PYTHON SOURCE LINES 26-28 .. code-block:: Python exp.model_diagnose(model='XGB2', show='accuracy_table') .. rst-class:: sphx-glr-script-out .. code-block:: none ACC AUC F1 LogLoss Brier Train 0.8219 0.7978 0.4759 0.4196 0.1316 Test 0.8290 0.7728 0.4797 0.4252 0.1319 Gap 0.0071 -0.0251 0.0038 0.0057 0.0004 .. GENERATED FROM PYTHON SOURCE LINES 29-30 Evaluate predictive performance of Mono-XGB2 .. GENERATED FROM PYTHON SOURCE LINES 30-32 .. code-block:: Python exp.model_diagnose(model='Mono-XGB2', show='accuracy_table') .. rst-class:: sphx-glr-script-out .. code-block:: none ACC AUC F1 LogLoss Brier Train 0.8216 0.7968 0.4780 0.4202 0.1318 Test 0.8288 0.7739 0.4816 0.4249 0.1320 Gap 0.0072 -0.0229 0.0036 0.0047 0.0001 .. GENERATED FROM PYTHON SOURCE LINES 33-34 Global effect plot for PAY_1 of XGB2 .. GENERATED FROM PYTHON SOURCE LINES 34-36 .. code-block:: Python exp.model_interpret(model='XGB2', show="global_effect_plot", uni_feature="PAY_1", original_scale=True, figsize=(5, 4)) .. image-sg:: /auto_examples/3_models/images/sphx_glr_plot_5_xgb2_cls_001.png :alt: PAY_1 (25.0%) :srcset: /auto_examples/3_models/images/sphx_glr_plot_5_xgb2_cls_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 37-38 Global effect plot for PAY_1 of Mono-XGB2 .. GENERATED FROM PYTHON SOURCE LINES 38-40 .. code-block:: Python exp.model_interpret(model='Mono-XGB2', show="global_effect_plot", uni_feature="PAY_1", original_scale=True, figsize=(5, 4)) .. image-sg:: /auto_examples/3_models/images/sphx_glr_plot_5_xgb2_cls_002.png :alt: PAY_1 (26.8%) :srcset: /auto_examples/3_models/images/sphx_glr_plot_5_xgb2_cls_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 41-42 Effect importance .. GENERATED FROM PYTHON SOURCE LINES 42-44 .. code-block:: Python exp.model_interpret(model='Mono-XGB2', show="global_ei", figsize=(5, 4)) .. image-sg:: /auto_examples/3_models/images/sphx_glr_plot_5_xgb2_cls_003.png :alt: Effect Importance :srcset: /auto_examples/3_models/images/sphx_glr_plot_5_xgb2_cls_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 45-46 Feature importance .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: Python exp.model_interpret(model='Mono-XGB2', show="global_fi", figsize=(5, 4)) .. image-sg:: /auto_examples/3_models/images/sphx_glr_plot_5_xgb2_cls_004.png :alt: Feature Importance :srcset: /auto_examples/3_models/images/sphx_glr_plot_5_xgb2_cls_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 49-50 Local interpretation by effect .. GENERATED FROM PYTHON SOURCE LINES 50-51 .. code-block:: Python exp.model_interpret(model='Mono-XGB2', show="local_ei", sample_id=0, original_scale=True, figsize=(5, 4)) .. image-sg:: /auto_examples/3_models/images/sphx_glr_plot_5_xgb2_cls_005.png :alt: Predicted: 0.1969 | Actual: 0.0000 :srcset: /auto_examples/3_models/images/sphx_glr_plot_5_xgb2_cls_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 52-53 Local interpretation by feature .. GENERATED FROM PYTHON SOURCE LINES 53-54 .. code-block:: Python exp.model_interpret(model='Mono-XGB2', show="local_fi", sample_id=0, original_scale=True, figsize=(5, 4)) .. image-sg:: /auto_examples/3_models/images/sphx_glr_plot_5_xgb2_cls_006.png :alt: Predicted: 0.1969 | Actual: 0.0000 :srcset: /auto_examples/3_models/images/sphx_glr_plot_5_xgb2_cls_006.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.422 seconds) .. _sphx_glr_download_auto_examples_3_models_plot_5_xgb2_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/3_models/plot_5_xgb2_cls.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_5_xgb2_cls.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_5_xgb2_cls.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_