.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/trust_classification.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_trust_classification.py: TrustReport for Classification ============================== Simple example on how to use the TrustReport class to analyze the explanations produced by ClassificationTrustee from a RandomForestClassifier from scikit-learn. Notice that using the method `TrustReport.load()`, one can load a previously generated report saved using `trust_report.save()`. .. GENERATED FROM PYTHON SOURCE LINES 10-58 .. code-block:: Python import os # importing required libraries # importing Scikit-learn library and datasets package from sklearn import datasets from sklearn.ensemble import RandomForestClassifier from trustee.report.trust import TrustReport OUTPUT_PATH = "out/" REPORT_PATH = f"{OUTPUT_PATH}/report/trust_report.obj" if os.path.exists(REPORT_PATH): print(f"Loading trust report from {REPORT_PATH}...") trust_report = TrustReport.load(REPORT_PATH) print("Done!") else: # Loading the iris plants dataset (classification) iris = datasets.load_iris() # dividing the datasets into two parts i.e. training datasets and test datasets X, y = datasets.load_iris(return_X_y=True, as_frame=True) # creating a RF classifier clf = RandomForestClassifier(n_estimators=100) # The trust report (can) fit and explain the classifier trust_report = TrustReport( clf, X=X, y=y, max_iter=5, num_pruning_iter=5, train_size=0.7, trustee_num_iter=10, trustee_num_stability_iter=5, trustee_sample_size=0.3, analyze_branches=True, analyze_stability=True, top_k=10, verbose=True, class_names=iris.target_names, feature_names=iris.feature_names, is_classify=True, ) print(trust_report) trust_report.save(OUTPUT_PATH) .. _sphx_glr_download_auto_examples_trust_classification.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: trust_classification.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: trust_classification.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: trust_classification.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_