.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tabular/auto_checks/model_evaluation/plot_confusion_matrix_report.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_tabular_auto_checks_model_evaluation_plot_confusion_matrix_report.py: .. _tabular__confusion_matrix_report: Confusion Matrix Report *********************** This notebook provides an overview for using and understanding the Confusion Matrix Report check. **Structure:** * `What is the Confusion Matrix Report? <#what-is-the-confusion-matrix-report>`__ * `Generate data & model <#generate-data-model>`__ * `Run the check <#run-the-check>`__ What is the Confusion Matrix Report? ====================================== The ``ConfusionMatrixReport`` produces a confusion matrix visualization which summarizes the performance of the model. The confusion matrix contains the TP (true positive), FP (false positive), TN (true negative) and FN (false negative), from which we can derive the relevant metrics, such as accuracy, precision, recall etc. (`confusion matrix `__). .. GENERATED FROM PYTHON SOURCE LINES 26-28 Generate data & model ======================= .. GENERATED FROM PYTHON SOURCE LINES 28-47 .. code-block:: default import pandas as pd from sklearn.datasets import load_iris from sklearn.ensemble import AdaBoostClassifier from sklearn.model_selection import train_test_split from deepchecks.tabular import Dataset from deepchecks.tabular.checks import ConfusionMatrixReport iris = load_iris(as_frame=True) clf = AdaBoostClassifier() frame = iris.frame X = iris.data y = iris.target X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=42) clf.fit(X_train, y_train) ds = Dataset(pd.concat([X_test, y_test], axis=1), features=iris.feature_names, label='target') .. GENERATED FROM PYTHON SOURCE LINES 48-50 Run the check =============== .. GENERATED FROM PYTHON SOURCE LINES 50-55 .. code-block:: default check = ConfusionMatrixReport() result = check.run(ds, clf) result.show() .. raw:: html
Confusion Matrix Report


.. GENERATED FROM PYTHON SOURCE LINES 56-62 Define a condition ================== We can define our check a condition that will validate if all the misclassified cells/samples in the confusion matrix is below a certain threshold. Using the ``misclassified_samples_threshold`` argument, we can specify what percentage of the total samples our condition should use to validate the misclassified cells. .. GENERATED FROM PYTHON SOURCE LINES 62-70 .. code-block:: default # Let's add a condition and re-run the check: check = ConfusionMatrixReport() check.add_condition_misclassified_samples_lower_than_condition(misclassified_samples_threshold=0.2) result = check.run(ds, clf) result.show() #%% .. raw:: html
Confusion Matrix Report


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.194 seconds) .. _sphx_glr_download_tabular_auto_checks_model_evaluation_plot_confusion_matrix_report.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_confusion_matrix_report.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_confusion_matrix_report.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_