### Install interpret with every dependency Source: https://interpret.ml/docs/installation-guide.html Builds the project, installs JavaScript dependencies, and installs the Python package with all optional dependencies. ```bash cd interpret ./build.sh # OR use build.bat on Windows cd shared/vis npm run clean && npm install && npm run build-prod cd ../../python/interpret-core pip install -e .[debug,notebook,plotly,lime,sensitivity,shap,linear,skoperules,treeinterpreter,aplr,dash,testing] ``` -------------------------------- ### Install interpret with every dependency (source) Source: https://interpret.ml/docs/deployment-guide.html Clones the interpret repository and runs the install script to install the full package from source. ```bash git clone https://github.com/interpretml/interpret.git && cd interpret/scripts && make install ``` -------------------------------- ### Install interpret with all dependencies (pip, conda, source) Source: https://interpret.ml/docs/_sources/deployment-guide.ipynb Use these commands to install the full `interpret` package, which includes all dependencies for visualization, glassbox models, and blackbox explanations. The pip command installs from PyPI, the conda command installs from conda-forge, and the source command clones the repository and runs the install script. ```shell pip install interpret ``` ```shell conda install -c conda-forge interpret ``` ```shell git clone https://github.com/interpretml/interpret.git && cd interpret/scripts && make install ``` -------------------------------- ### Install interpret with every dependency (pip) Source: https://interpret.ml/docs/deployment-guide.html Installs the full `interpret` package with all dependencies via pip. This is the default installation method. ```bash pip install interpret ``` -------------------------------- ### Install interpret-core with minimal dependencies (source) Source: https://interpret.ml/docs/deployment-guide.html Clones the interpret repository and runs the install-core script to install the minimal package from source. ```bash git clone https://github.com/interpretml/interpret.git && cd interpret/scripts && make install-core ``` -------------------------------- ### Install interpret-core with all extra tags (pip) Source: https://interpret.ml/docs/deployment-guide.html Installs `interpret-core` with all extra tags, which is equivalent to installing the full `interpret` package. This is only supported via pip. ```bash pip install interpret-core[debug,notebook,plotly,lime,sensitivity,shap,linear,skoperules,treeinterpreter,aplr,dash,testing] ``` -------------------------------- ### Install interpret and dependencies Source: https://interpret.ml/docs/python/examples/explain-blackbox-regressors.html Installs interpret, pandas, scikit-learn, and lime if interpret is not already installed. Uses pip with the --quiet flag. ```python # install interpret if not already installed try: import interpret except ModuleNotFoundError: !pip install --quiet interpret pandas scikit-learn lime ``` -------------------------------- ### VS Code launch configurations for Python and C++ Attach Source: https://interpret.ml/docs/debugging-guide.html Example launch.json configurations for attaching to a C++ process and launching the current Python file. ```json "configurations": [ { "name": "(Windows) Attach", "type": "cppvsdbg", "request": "attach", "processId": "${command:pickProcess}" }, { "name": "Python: Current File", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal" } ] ``` -------------------------------- ### Install interpret-core with minimal dependencies (conda) Source: https://interpret.ml/docs/deployment-guide.html Installs the minimal `interpret-core` package via conda from conda-forge. ```bash conda install -c conda-forge interpret-core ``` -------------------------------- ### Show a single explanation with interpret.show Source: https://interpret.ml/docs/_sources/framework.ipynb This example loads the Adult dataset, trains an ExplainableBoostingClassifier, and calls show to render a dropdown widget with an overview and per-feature graphs for a global explanation. ```python import numpy as np import pandas as pd from sklearn.model_selection import train_test_split from interpret.glassbox import ExplainableBoostingClassifier from interpret import show df = pd.read_csv( "https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data", ``` -------------------------------- ### Install interpret and dependencies Source: https://interpret.ml/docs/python/examples/differential-privacy.html Installs the interpret, pandas, and scikit-learn packages if interpret is not already installed. ```python try: import interpret except ModuleNotFoundError: !pip install --quiet interpret pandas scikit-learn ``` -------------------------------- ### Install interpret and scikit-learn if not already installed Source: https://interpret.ml/docs/python/examples/interpretable-regression.html Checks if the interpret package is importable; if not, installs interpret and scikit-learn using pip. This is a prerequisite for running the notebook. ```python # install interpret if not already installed try: import interpret except ModuleNotFoundError: !pip install --quiet interpret scikit-learn ``` -------------------------------- ### Install interpret-core with minimal dependencies (pip) Source: https://interpret.ml/docs/deployment-guide.html Installs the minimal `interpret-core` package via pip, which includes only dependencies required for EBM fitting, predicting, editing, serialization, and generating explanations. ```bash pip install interpret-core ``` -------------------------------- ### Install interpret-core with minimal dependencies (pip, conda, source) Source: https://interpret.ml/docs/_sources/deployment-guide.ipynb Use these commands to install the `interpret-core` package, which includes only the dependencies required for EBM fitting, predicting, editing, serialization, and generating explanations. This is suitable for production deployments with fewer dependencies. ```shell pip install interpret-core ``` ```shell conda install -c conda-forge interpret-core ``` ```shell git clone https://github.com/interpretml/interpret.git && cd interpret/scripts && make install-core ``` -------------------------------- ### Import boilerplate for EBM multiclass example Source: https://interpret.ml/docs/ebm-internals-multiclass.html Imports required libraries: interpret.show, ExplainableBoostingClassifier, and numpy. ```python # boilerplate from interpret import show from interpret.glassbox import ExplainableBoostingClassifier import numpy as np ``` -------------------------------- ### Install interpret with every dependency (conda) Source: https://interpret.ml/docs/deployment-guide.html Installs the full `interpret` package with all dependencies via conda from conda-forge. ```bash conda install -c conda-forge interpret ``` -------------------------------- ### Build a Blackbox Pipeline Source: https://interpret.ml/docs/index.html Example of creating a scikit-learn Pipeline with PCA and RandomForestClassifier for blackbox interpretability. ```APIDOC ## Build a Blackbox Pipeline ### Description Construct a blackbox machine learning pipeline that includes preprocessing steps (PCA) and a classifier (RandomForestClassifier) for interpretability. ### Code Example ```python from sklearn.ensemble import RandomForestClassifier from sklearn.decomposition import PCA from sklearn.pipeline import Pipeline # We have to transform categorical variables to use sklearn models X = pd.get_dummies(X, prefix_sep='.').astype(float) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=seed) #Blackbox system can include preprocessing, not just a classifier! pca = PCA() rf = RandomForestClassifier(random_state=seed) blackbox_model = Pipeline([('pca', pca), ('rf', rf)]) blackbox_model.fit(X_train, y_train) ``` ### Pipeline Parameters - **steps** (list of tuples) - Required - List of (name, estimator) tuples to be chained in sequential order. All steps must define `fit`; non-last steps must define `transform`. - **transform_input** (list of str, default=None) - Optional - Names of metadata parameters to be transformed by the pipeline before passing to the step consuming it. Requires metadata routing enabled. - **memory** (str or object with joblib.Memory interface, default=None) - Optional - Used to cache fitted transformers. If string, path to caching directory. - **verbose** (bool, default=False) - Optional - If True, prints time elapsed while fitting each step. ### PCA Parameters - **n_components** (int, float or 'mle', default=None) - Optional - Number of components to keep. If not set, all components are kept (min(n_samples, n_features)). If 'mle' and svd_solver='full', Minka's MLE is used. If 0 < n_components < 1 and svd_solver='full', selects number of components to explain variance greater than the percentage specified. ``` -------------------------------- ### Show multiple explanations for comparison with show([ebm_global, lr_global]) Source: https://interpret.ml/docs/framework.html Pass a list of explanation objects to the show function to display a comparison dashboard. This example compares the EBM global explanation with the Logistic Regression global explanation. ```python show([ebm_global, lr_global]) ``` -------------------------------- ### interpret.init_show_server(addr=None, base_url=None, use_relative_links=False) Source: https://interpret.ml/docs/python/api/init_show_server.html Initializes the show method's backing server. This function allows you to configure the server address, base URL path, and whether to use relative links in responses. ```APIDOC ## interpret.init_show_server(addr=None, base_url=None, use_relative_links=False) ### Description Initializes the show method's backing server. This function allows you to configure the server address, base URL path, and whether to use relative links in responses. ### Parameters - **addr** (tuple) - Optional - (ip, port) tuple as address to assign show method to. - **base_url** (str) - Optional - Base url path as string. Used mostly when server is running behind a proxy. - **use_relative_links** (bool) - Optional - Use relative links for what's returned to client. Otherwise have absolute links. ``` -------------------------------- ### Install interpret if not already installed Source: https://interpret.ml/docs/python/examples/prototype-selection.html Checks if the interpret package is available and installs it along with numpy, scikit-learn, and matplotlib if not. Uses a try/except block and a pip install command. ```python # install interpret if not already installed try: import interpret except ModuleNotFoundError: !pip install --quiet interpret numpy scikit-learn matplotlib ``` -------------------------------- ### Install interpret if not already installed Source: https://interpret.ml/docs/python/examples/custom-interactions.html Checks if the interpret package is importable; if not, installs interpret, pandas, and scikit-learn using pip. ```python # install interpret if not already installed try: import interpret except ModuleNotFoundError: !pip install --quiet interpret pandas scikit-learn ``` -------------------------------- ### LimeTabular.__init__ Source: https://interpret.ml/docs/python/api/LimeTabular.html Initializes the LimeTabular explainer with a model, data, and optional feature names and types. ```APIDOC ## LimeTabular.__init__ ### Description Initializes the LimeTabular class, exposing the LIME tabular explainer from the lime package in interpret API form. ### Method Constructor ### Signature _class_ interpret.blackbox.LimeTabular(_model_, _data_, _feature_names=None_, _feature_types=None_, _**_kwargs_) ### Parameters - **model** - Required - Model or prediction function of model (predict_proba for classification or predict for regression) - **data** - Required - Data used to initialize LIME with. - **feature_names** - Optional - List of feature names. - **feature_types** - Optional - List of feature types. - **kwargs** - Optional - Kwargs that will be sent to lime ``` -------------------------------- ### interpret.init_show_server Source: https://interpret.ml/docs/_sources/python/api/init_show_server.ipynb Initializes the show server for the interpret library. This function is part of the interpret package's public API. ```APIDOC ## interpret.init_show_server ### Description Initializes the show server for the interpret library. ### Method Function call ### Endpoint interpret.init_show_server ### Parameters No parameters documented. ### Request Example ```python import interpret interpret.init_show_server() ``` ### Response No return value documented. ``` -------------------------------- ### Output of intercept_ Source: https://interpret.ml/docs/ebm-internals-regression.html Example output showing the intercept value, which is 450.0 in this example. ```text 450.0 ``` -------------------------------- ### Generate full interpret dashboard with show() Source: https://interpret.ml/docs/faq.html Pass a list of explanations to show() to produce the full interpret dashboard. Passing a single explanation (not wrapped in a list) returns a small dropdown instead. ```python from interpret import show show(ebm_local) # Returns small dropdown show([ ebm_local ]) # Produces interpret dashboard ``` -------------------------------- ### Install EBM without other explainers using interpret-core Source: https://interpret.ml/docs/faq.html Use this pip command to install only the EBM explainer from the interpret-core base package, avoiding other dependencies. The 'required' tag is generally recommended for all installs. ```bash pip install interpret-core[required,ebm] ``` -------------------------------- ### LimeTabular.explain_local Source: https://interpret.ml/docs/python/api/LimeTabular.html Generates local explanations for provided instances using LIME. ```APIDOC ## LimeTabular.explain_local ### Description Generates local explanations for provided instances. ### Method explain_local(_X_, _y=None_, _name=None_, _**_kwargs_) ### Parameters - **X** - Required - Numpy array for X to explain. - **y** - Optional - Numpy vector for y to explain. - **name** - Optional - User-defined explanation name. - **kwargs** - Optional - Kwargs that will be sent to lime ### Returns An explanation object, visualizing feature-value pairs for each instance as horizontal bar charts. ``` -------------------------------- ### Local explanation with ShapKernel Source: https://interpret.ml/docs/python/examples/explain-blackbox-regressors.html Creates a SHAP Kernel local explainer. Requires a background dataset (here, the median of X_train) and a blackbox model. Explains the first five test instances and displays the explanation for the first instance. ```python from interpret.blackbox import ShapKernel background_val = pd.DataFrame(np.median(X_train, axis=0).reshape(1, -1), columns=X.columns) shap = ShapKernel(blackbox_model, background_val) shap_local = shap.explain_local(X_test[:5], y_test[:5], name='SHAP') show(shap_local, 0) ``` -------------------------------- ### explain_local(X, y=None, name=None, init_score=None) Source: https://interpret.ml/docs/python/api/ExplainableBoostingRegressor.html Provides local explanations for provided samples. ```APIDOC ## explain_local(X, y=None, name=None, init_score=None) ### Description Provide local explanations for provided samples. ### Parameters - **X** - Required - NumPy array for X to explain. - **y** - Optional - NumPy vector for y to explain. - **name** - Optional - User-defined explanation name. - **init_score** - Optional - Initial score. ``` -------------------------------- ### get_num_cv_folds Source: https://interpret.ml/docs/python/api/APLRRegressor.html Gets the number of cross-validation folds used during training. ```APIDOC ## get_num_cv_folds ### Description Gets the number of cross-validation folds used during training. ### Method get_num_cv_folds() ### Signature `get_num_cv_folds()` ### Parameters None. ### Returns The number of folds. ``` -------------------------------- ### Run unit tests Source: https://interpret.ml/docs/installation-guide.html Runs the unit tests using make test. ```bash cd interpret/scripts make test ``` -------------------------------- ### get_cv_y Source: https://interpret.ml/docs/python/api/APLRRegressor.html Gets the validation response values (y) for a specific cross-validation fold. ```APIDOC ## get_cv_y ### Description Gets the validation response values (y) for a specific cross-validation fold. ### Method get_cv_y(fold_index) ### Signature `get_cv_y(fold_index)` ### Parameters - **fold_index** (int) - Required - The index of the fold. ### Returns A numpy array containing the validation response values. ``` -------------------------------- ### get_cv_sample_weight Source: https://interpret.ml/docs/python/api/APLRRegressor.html Gets the validation sample weights for a specific cross-validation fold. ```APIDOC ## get_cv_sample_weight ### Description Gets the validation sample weights for a specific cross-validation fold. ### Method get_cv_sample_weight(fold_index) ### Signature `get_cv_sample_weight(fold_index)` ### Parameters - **fold_index** (int) - Required - The index of the fold. ### Returns A numpy array containing the validation sample weights. ``` -------------------------------- ### get_cv_validation_indexes Source: https://interpret.ml/docs/python/api/APLRRegressor.html Gets the original indexes of the validation observations for a specific cross-validation fold. ```APIDOC ## get_cv_validation_indexes ### Description Gets the original indexes of the validation observations for a specific cross-validation fold. ### Method get_cv_validation_indexes(fold_index) ### Signature `get_cv_validation_indexes(fold_index)` ### Parameters - **fold_index** (int) - Required - The index of the fold. ### Returns A numpy array containing the original indexes. ``` -------------------------------- ### Show local explanations for first 5 test samples Source: https://interpret.ml/docs/ebm.html Displays local explanations for the first five test samples using interpret.show. ```python show(ebm.explain_local(X_test[:5], y_test[:5]), 0) ``` -------------------------------- ### Load and prepare the Adult dataset Source: https://interpret.ml/docs/python/examples/custom-interactions.html Imports required libraries, loads the Adult dataset from the UCI repository, assigns column names, and creates train/test splits with a fixed random seed. ```python import numpy as np import pandas as pd from sklearn.model_selection import train_test_split from interpret.glassbox import ExplainableBoostingClassifier df = pd.read_csv( "https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data", header=None) df.columns = [ "Age", "WorkClass", "fnlwgt", "Education", "EducationNum", "MaritalStatus", "Occupation", "Relationship", "Race", "Gender", "CapitalGain", "CapitalLoss", "HoursPerWeek", "NativeCountry", "Income" ] X = df.iloc[:, :-1] y = df.iloc[:, -1] seed = 42 np.random.seed(seed) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=seed) ``` -------------------------------- ### AUC Output from Logistic Regression Source: https://interpret.ml/docs/lr.html The printed AUC value from the logistic regression training example, showing 0.998. ```text AUC: 0.998 ```