Coder Social home page Coder Social logo

interpretml / interpret-community Goto Github PK

View Code? Open in Web Editor NEW
412.0 20.0 84.0 46.66 MB

Interpret Community extends Interpret repository with additional interpretability techniques and utility functions to handle real-world datasets and workflows.

Home Page: https://interpret-community.readthedocs.io/en/latest/index.html

License: MIT License

Python 88.68% Jupyter Notebook 11.07% PowerShell 0.25%
explainer interpretable-models mimic-explainer tabular-explainer explanationdashboard machine-learning pytorch deep-learning python

interpret-community's Introduction

PyPI MIT license versions

Build Status

Interpret Community SDK

Interpret-Community is an experimental repository extending Interpret, with additional interpretability techniques and utility functions to handle real-world datasets and workflows for explaining models trained on tabular data. This repository contains the Interpret-Community SDK and Jupyter notebooks with examples to showcase its use.

Contents

Overview of Interpret-Community

Interpret-Community extends the Interpret repository and incorporates further community developed and experimental interpretability techniques and functionalities that are designed to enable interpretability for real world scenarios. Interpret-Community enables adding new experimental techniques (or functionalities) and performing comparative analysis to evaluate them.

Interpret-Community

  1. Actively incorporates innovative experimental interpretability techniques and allows for further expansion by researchers and data scientists
  2. Applies optimizations to make it possible to run interpretability techniques on real-world datasets at scale
  3. Provides improvements such as the capability to "reverse the feature engineering pipeline" to provide model insights in terms of the original raw features rather than engineered features
  4. Provides interactive and exploratory visualizations to empower data scientists to gain meaningful insight into their data

Installation

The package can be installed from pypi with:

      pip install interpret-community

For more installation information, please see the website documentation at https://interpret-community.readthedocs.io/en/latest/overview.html#getting-started

Documentation website

For more information, please visit the documentation website, which also includes detailed API documentation generated by sphinx: https://interpret-community.readthedocs.io/en/latest/index.html

Supported Models

This API supports models that are trained on datasets in Python numpy.ndarray, pandas.DataFrame, or scipy.sparse.csr_matrix format.

The explanation functions accept both models and pipelines as input as long as the model or pipeline implements a predict or predict_proba function that conforms to the Scikit convention. If not compatible, you can wrap your model's prediction function into a wrapper function that transforms the output into the format that is supported (predict or predict_proba of Scikit), and pass that wrapper function to your selected interpretability techniques.

If a pipeline script is provided, the explanation function assumes that the running pipeline script returns a prediction. The repository also supports models trained via PyTorch, TensorFlow, and Keras deep learning frameworks.

Supported Explainers

The following are a list of the explainers available in the community repository:

Interpretability Technique Description Type
SHAP Kernel Explainer SHAP's Kernel explainer uses a specially weighted local linear regression to estimate SHAP values for any model. Model-agnostic
GPU SHAP Kernel Explainer GPU Kernel explainer uses cuML's GPU accelerated version of SHAP's Kernel Explainer to estimate SHAP values for any model. It's main advantage is to provide acceleration to fast GPU models, like those in cuML. But it can also be used with CPU-based models, where speedups can still be achieved but they might be limited due to data transfers and speed of models themselves. Model-agnostic
SHAP Tree Explainer SHAP’s Tree explainer, which focuses on the polynomial time fast SHAP value estimation algorithm specific to trees and ensembles of trees. Model-specific
SHAP Deep Explainer Based on the explanation from SHAP, Deep Explainer "is a high-speed approximation algorithm for SHAP values in deep learning models that builds on a connection with DeepLIFT described in the SHAP NIPS paper. TensorFlow models and Keras models using the TensorFlow backend are supported (there is also preliminary support for PyTorch)". Model-specific
SHAP Linear Explainer SHAP's Linear explainer computes SHAP values for a linear model, optionally accounting for inter-feature correlations. Model-specific
Mimic Explainer (Global Surrogate) Mimic explainer is based on the idea of training global surrogate models to mimic blackbox models. A global surrogate model is an intrinsically interpretable model that is trained to approximate the predictions of any black box model as accurately as possible. Data scientists can interpret the surrogate model to draw conclusions about the black box model. You can use one of the following interpretable models as your surrogate model: LightGBM (LGBMExplainableModel), Linear Regression (LinearExplainableModel), Stochastic Gradient Descent explainable model (SGDExplainableModel), and Decision Tree (DecisionTreeExplainableModel). Model-agnostic
Permutation Feature Importance Explainer (PFI) Permutation Feature Importance is a technique used to explain classification and regression models that is inspired by Breiman's Random Forests paper (see section 10). At a high level, the way it works is by randomly shuffling data one feature at a time for the entire dataset and calculating how much the performance metric of interest changes. The larger the change, the more important that feature is. PFI can explain the overall behavior of any underlying model but does not explain individual predictions. Model-agnostic
LIME Explainer Local Interpretable Model-agnostic Explanations (LIME) is a local linear approximation of the model's behavior. The explainer wraps the LIME tabular explainer with a uniform API and additional functionality. Model-agnostic

Besides the interpretability techniques described above, Interpret-Community supports another SHAP-based explainer, called TabularExplainer. Depending on the model, TabularExplainer uses one of the supported SHAP explainers:

Original Model Invoked Explainer
Tree-based models SHAP TreeExplainer
Deep Neural Network models SHAP DeepExplainer
Linear models SHAP LinearExplainer
None of the above SHAP KernelExplainer or GPUKernelExplainer

Using Interpret-Community

The explainers in interpret-community have one common API, where you first construct the explainer from the model or prediction function:

from interpret.ext.blackbox import TabularExplainer

# "features" and "classes" fields are optional
explainer = TabularExplainer(model,
                             x_train,
                             features=breast_cancer_data.feature_names,
                             classes=classes)

Explanations can then be computed on the evaluation examples:

# you can use the training data or the test data here
global_explanation = explainer.explain_global(x_train)

# explain the first five data points in the test set
local_explanation = explainer.explain_local(x_test[0:5])

For more usage information, please see Use Interpret-Community

Visualizations

Install the raiwidgets package, the ExplanationDashboard has moved to the responsible-ai-toolbox repo:

pip install raiwidgets

Load the visualization dashboard in your notebook to understand and interpret your model:

from raiwidgets import ExplanationDashboard

ExplanationDashboard(global_explanation, model, dataset=x_test, trueY=y_test)

Once you load the visualization dashboard, you can investigate different aspects of your dataset and trained model via four tab views:

  • Model Performance
  • Data Explorer
  • Aggregate Feature Importance
  • Individual Feature Importance and What-If

For more information about the visualizations, please see Visualizations

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to the Github Developer Certificate of Origin, DCO. For details, please visit https://probot.github.io/apps/dco/.

The Developer Certificate of Origin (DCO) is a lightweight way for contributors to certify that they wrote or otherwise have the right to submit the code they are contributing to the project. Here is the full text of the DCO, reformatted for readability:

By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or
(b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or
(c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.
(d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved.
Contributors sign-off that they adhere to these requirements by adding a Signed-off-by line to commit messages.
This is my commit message

Signed-off-by: Random J Developer <[email protected]>
Git even has a -s command line option to append this automatically to your commit message:
$ git commit -s -m 'This is my commit message'

When you submit a pull request, a DCO bot will automatically determine whether you need to certify. Simply follow the instructions provided by the bot.

Code of Conduct

This project has adopted the his project has adopted the GitHub Community Guidelines.

Reporting Security Issues

Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) at [email protected]. You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the Security TechCenter.

interpret-community's People

Contributors

bethz avatar dependabot[bot] avatar eedeleon avatar gaugup avatar gregorybchris avatar imatiach-msft avatar janhavi13 avatar marksoper avatar mesameki avatar microsoftopensource avatar mizeljko avatar msftgits avatar nanthini10 avatar riedgar-ms avatar rihorn2 avatar rogerhe avatar scottcode avatar tirkarthi avatar vingu avatar vmagelo avatar wamartin-aml avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

interpret-community's Issues

Explanation Dashboard for local explanation throwing KeyError - "intercept"

Describe the bug
I tried to display the Explanation Dashboard for local explanation on my local Windows system. It's throwing a KeyError "intercept" pointing to "explanation_dashboard_input.py" from "widget" module.

Expected behavior
I should be getting the Dashboard displayed.

Screenshots
If applicable, add screenshots to help explain your problem.
image

Importing TabularExplainer

Describe the bug
Hi! I have a problem when importing TabularExplainer ( I am getting this error "Cannot find reference "TabularExplainer" in 'init.py' "). I am using PyCharm as IDEA and anaconda3.

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'anacondaprompt' (base environment)
  2. pip install interpret-community
  3. going to the Pycharm project
  4. from interpret.ext.blackbox import TabularExplainer
  5. the import throws the error

change wording in nb Explain-regression-local

Describe the bug
When running PFI, comment in nb says:

Note: PFIExplainer does not support local explanations

Should change to say:
Do not run this cell if using PFIExplainer

To Reproduce
Steps to reproduce the behavior:
Run notebook

Expected behavior
More detailed error.

Screenshots
If applicable, add screenshots to help explain your problem.
image

cannot import TabularExplainer from interpret.ext.blackbox

Describe the bug
Help! Just cannot import TabularExplainer from interpret.ext.blackbox. My interpret version is 0.2.1 and python version is 3.7. Not know if that is the reason?
89726026-8dd0e700-da48-11ea-921f-f0b1dac47544

I copy the code from a Microsoft tutorial...
89726051-cec8fb80-da48-11ea-8d4e-e7c0a401cf2b

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

InterpretML Dashboard What-if-datapoints not available for perturbation

As per your sample video on the github site - https://www.youtube.com/watch?v=WwBeKMQ0-I8&ab_channel=MicrosoftDeveloper perturbation points should be available in the last tab of the dashboard (What-if datapoint). I've attached a screenshot of the video that shows the option to perturb the points.

InterpretML_What_If_datapoints_as_shown_in_video

But when I'm trying to create a similar notebook in Colab I get the dashboard but I do not get the option to perturb the datapoints. I've attached the screenshot for this case also.

InterpretML_What_If_datapoints_missing

Please advise why am I not getting the option to perturb the datapoints ?

NB VM does not always display, even with refresh

Describe the bug
Run any nb in ml.azure.com and the dashboard frequently does not display.

To Reproduce
Steps to reproduce the behavior:

  1. run any notebook in ml.azure.com
  • this is NOT when Jupyter or Jupyter lab is selected separately

Expected behavior
Expect to see dashboard

Desktop (please complete the following information):
Chrome

Object of type 'Timestamp' is not JSON serializable

Hi all,

I'm trying to show the Explanation Dashboard in the following way:

raw_explanations = client.download_model_explanation(raw=True)

ExplanationDashboard(raw_explanations, explainer_setup_class.automl_pipeline, datasetX=explainer_setup_class.X_test_raw)

but I'm getting the following error:


TypeError Traceback (most recent call last)
in
3 print(raw_explanations.get_feature_importance_dict())
4
----> 5 ExplanationDashboard(raw_explanations, explainer_setup_class.automl_pipeline, datasetX=explainer_setup_class.X_test_raw)

/anaconda/envs/azureml_py36/lib/python3.6/site-packages/interpret_community/widget/explanation_dashboard.py in init(self, explanation, model, dataset, true_y, classes, features, port, use_cdn, datasetX, trueY, locale, public_ip, with_credentials)
261 if ExplanationDashboard.service.env != "cloud":
262 explanation_input.enable_predict_url()
--> 263 html = generate_inline_html(explanation_input, local_url)
264 ExplanationDashboard.explanations[str(ExplanationDashboard.model_count)] = explanation_input
265

/anaconda/envs/azureml_py36/lib/python3.6/site-packages/interpret_community/widget/explanation_dashboard.py in generate_inline_html(explanation_input_object, local_url)
294
295 def generate_inline_html(explanation_input_object, local_url):
--> 296 explanation_input = json.dumps(explanation_input_object.dashboard_input)
297 return ExplanationDashboard.default_template.render(explanation=explanation_input,
298 main_js=ExplanationDashboard._dashboard_js,

/anaconda/envs/azureml_py36/lib/python3.6/json/init.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
229 cls is None and indent is None and separators is None and
230 default is None and not sort_keys and not kw):
--> 231 return _default_encoder.encode(obj)
232 if cls is None:
233 cls = JSONEncoder

/anaconda/envs/azureml_py36/lib/python3.6/json/encoder.py in encode(self, o)
197 # exceptions aren't as detailed. The list call should be roughly
198 # equivalent to the PySequence_Fast that ''.join() would do.
--> 199 chunks = self.iterencode(o, _one_shot=True)
200 if not isinstance(chunks, (list, tuple)):
201 chunks = list(chunks)

/anaconda/envs/azureml_py36/lib/python3.6/json/encoder.py in iterencode(self, o, _one_shot)
255 self.key_separator, self.item_separator, self.sort_keys,
256 self.skipkeys, _one_shot)
--> 257 return _iterencode(o, 0)
258
259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,

/anaconda/envs/azureml_py36/lib/python3.6/json/encoder.py in default(self, o)
178 """
179 raise TypeError("Object of type '%s' is not JSON serializable" %
--> 180 o.class.name)
181
182 def encode(self, o):

TypeError: Object of type 'Timestamp' is not JSON serializable

Is this a known bug?

I've just spun up a new Compute Instance to try this code, so I'm using the following packages:

  • ML Python SDK (1.16.0)
  • interpret-community (0.15.1)
  • interpret-core (0.2.1)

ExplanationDashboard widget fails with PFI

Describe the bug
ExplanationDashboard widget fails with PFI because expected values are missing

To Reproduce
Steps to reproduce the behavior:

  1. Run the multiclass notebook with PFI, see error when running widget

Expected behavior
Widget should work

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: windows
  • Browser any
  • Version master

Can't make dashboard(runs forever) on remote private cloud

As the picture shows, the ExplanationDashboard function runs forever even with only 10 test data (data is tabular with 91 columns).
Because the jupyter notebook is on the remote private cloud, and i don't have full privilege on this cloud,
I suspect that it is the problem with IP address or something server-related problems.

I can successfully execute other functions(local or global feature importance) and all original InterpretML functions(although
I have to do the visualization on the notebook inline, and if opened on new tab, the access will be denied).

Is it possible to make the visualization without posting it to local server?

Sorry for my weak english.

image

Way to view the dashboard locally on browser

Is there a way to get the url to open the dashboard on the browser locally? The previous interpret repo has a show_link functionality that does this.

How can this be done for the ExplanationDashboard function?

Issue due to pytorch not being installed needs a try-catch

Describe the bug
When setting up pfi in /notebooks/explain-regression-local.ipynb notebook, an error occurs when using PFI when pytorch is not installed.

To Reproduce
run nb.

Screenshots
If applicable, add screenshots to help explain your problem.
image

Additional context
Add any other context about the problem here.

PR-Gate pipeline fail

The PR-Gate pipeline

To Reproduce
Steps to reproduce the behavior:

  1. Run PR-Gate pipeline
  2. Note Seg Fault in devops test log

Expected behavior
Expected tests to pass

Additional context
Changes in 3rd party versions have been indicated to cause issue.

No Dashboard output

Dashboard output is not generating when I generate global explanations and dashboards in the same code cell.

image

global_explanation = explainer.explain_global(x_test)
ExplanationDashboard(global_explanation, model, datasetX=x_test)

Can you please let me know how to extract the dashboard without executing in two separate cells.

NB VM dashboard error with jupyter lab selection

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to ml.azure.com
  2. select explain-regression-local.ipynb
  3. select Jupyter-> Jupyter Lab
  4. run nb
    nb ran until dashboard and then error.

Expected behavior
did not expect error

Screenshots
If applicable, add screenshots to help explain your problem.
image

Desktop (please complete the following information):

  • OS: [e.g. iOS]
    Edge

dashboard with PFI fails when going to the non-default tab

Describe the bug
dashboard with PFI fails when going to the non-default tab

To Reproduce
Steps to reproduce the behavior:

  1. run multiclass notebook with PFI and the explanation dashboard
  2. although it appears, when going to the lower tab it hits and error and crashes the visualization

Expected behavior
Show the tab's visualization

error "Notebook does not appear to be JSON...."

Describe the bug
When loading a jupyter notebook, this error occurs:
Unreadable Notebook: /path/FILENAME.ipynb NotJSONError("Notebook does not appear to be JSON: ''...",)

To Reproduce
Steps to reproduce the behavior:

  1. Go to the repo
  2. set up env
  3. run jupyter notebook
  4. open notebook
  5. See error

Expected behavior
Jupyter notebook runs notebook

Screenshots
If applicable, add screenshots to help explain your problem.
image

Desktop (please complete the following information):
Edge Browser

Additional context
Add any other context about the problem here.

Azure DSVM(ubuntu 18.04) can't run ExplanationDashboard

Describe the bug
Azure DSVM(ubuntu 18.04) can't run ExplanationDashboard
pic1

To Reproduce

  1. creating the data science VM-ubuntu 18.04 resources;
  2. running interpretability script , reference scripts from https://github.com/interpretml/interpret-community/blob/master/notebooks/explain-regression-local.ipynb;
  3. After running the following script, a visualization panel will appear in the Jupypter notebook environment (see the figure),
    from interpret_community.widget import ExplanationDashboard
    ExplanationDashboard(global_explanation, model, datasetX=x_test)
  4. But after clicking "Open in new tab" in the output visualization panel, the IP address of the created VM public network cannot be located, but it is directly located to http://localhost:5001/1, so the model cannot be accessed in the browser Interpretability panel.

Expected behavior
it shall navigate to the public IP address of azure DSVM

Screenshots
see the attachment

Desktop (please complete the following information):

  • OS : ubuntu 18.04
  • Browser : chrome

Smartphone (please complete the following information):
not applicable

Additional context

Documentation for BaseExplanation class?

Is your feature request related to a problem? Please describe.
Per this issue: Azure/MachineLearningNotebooks#1125

Well many users may not know what a BaseExplanation object is and likely isn't documented elsewhere. In similar documentation the BaseExplanation would contain a link, to another place where BaseExplanation is explained. Upload model requires a BaseExplanation, download model returns a BaseExplanation. But the BaseExplanation object itself is undocumented.
When you look into the BaseExplanation object itself, it has a lot of properties and methods. I would recommend creating a separate doc page about that object so that a user could use the methods of that object. This would make it easier to be certain that a user's application accomplishes what they assume it will do.

Describe the solution you'd like

Clear documentation of the class's method and attributes

Describe alternatives you've considered

Additional context
the ExplanationClient class page says that .download_model_explanation() returns a BaseExplanation but there's no page for that class.

Issue with dashboard not starting: ordering?

Describe the bug
Dashboard did not start for explain-binary-classification notebook when running mimic explainer. Brandon suggested for Ilya to review.

To Reproduce
Steps to reproduce the behavior:
Run notebook

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.
image

Browser:
Edge

skipped test: test_explain_model_lightgbm_binary

Describe the bug
This is a reminder that this test is skipped for now.
Message from test:
skipping test until shap TreeExplainer for lightgbm binary classifier fixed

To Reproduce
Steps to reproduce the behavior:

  1. Go to devops
  2. Check nightly log

Expected behavior
test would run

Screenshots
If applicable, add screenshots to help explain your problem.
image

Additional context
Add any other context about the problem here.

Problem with license file when running pip install .

Describe the bug
If user runs "pip install ." the installation fails with error:

error: [Errno 2] No such file or directory: 'LICENSE.txt'

The file needs to be copied from the directory above to the current directory to fix the build. Not sure how to optimally resolve this, one option may be to have duplicate license files.

Save the explainer

It would be great if the Explainer generated can be saved so as to be able to reuse later on and not wait for it to be created once again. It would be especially helpful in cases when the inference time is larger for the model.

Issue with XGBoost + binary classification when using TreeExplainer

Describe the bug
User reported issue.
XGBoost + binary classification when using TreeExplainer fails due to bad shape.

SHAP TreeExplainer returns the wrong format for feature contribution values (lightgbm had similar issue but it was already fixed with PR shap/shap#690), we have a disabled test here:

https://github.com/interpretml/interpret-community/blob/master/test/test_explain_model.py#L362

The fix requires a PR to SHAP

To Reproduce
Steps to reproduce the behavior:

  1. Run TreeExplainer on XGBoost binary classifier
  2. See error

Expected behavior
Explanation should be returned

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):
Any

Smartphone (please complete the following information):
Any

Additional context
Add any other context about the problem here.

About mimic explainer:

Sorry, not sure if its appropriate to ask questions via issues, but I see no other ways of doing it.

As my understanding, Mimic explainer is kind of like LIME, but using 4 : LightGBM , Linear Regression , Stochastic Gradient Descent , and Decision Tree as surrogate model.

My question is, is it appropriate to use Mimic's LightGBM to explain my LightGBM model?(does it make sense?)
Or another way to put it, how should i explain my LightGBM model?

And is there any way to learn more about Mimic explainer? like research paper documents or something.
Thank you!

Fastest way to publish the dashboard on web

It’s often requested to publish the dashboard on the web in order to make it available to users (not in a notebook).

Is it possible? If so, what are the best/fastest ways to do that? Would be great if you could share both an on-premises solution (using open source stuff) and an Azure solution.

greenlet dependency issues

Describe the bug
Greenlet dependency in interpret-core is causing issues for interpret-community package, where the package may not install or the extension system may fail if an older version is installed via conda

To Reproduce
Steps to reproduce the behavior:

  1. Create an environment with an older version of greenlet
  2. try to "pip install interpret-community", see error

Expected behavior
Installation should work

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Any
  • Browser Any
  • Version master

Update repo to match agreed DevOps Architecture

Modify the repo to match the agreed DevOps Architecture.
Make Devops folder for yml.
Add folder devops with new yml. Removing current will be a future pr.
update devops name from interpret-extensions to interpret-community.
add badges for new pipelines.

pip order install issue

Describe the bug
When running python 3.5 or 3.7, the import of interpret-community fails.
This is fixed by the recent release (#?)

To Reproduce
Steps to reproduce the behavior:

  1. conda create -n name python=3.5
  2. activate name
  3. pip install interpret-community
  4. python
  5. from interpret.ext.blackbox import TabularExplainer
  6. may have lightgbm warnings
  7. then it should have no other warnings
  8. exit()
  9. pip install Jupyter

rerun python lines
there should be no warnings

Expected behavior
no warnings

Desktop (please complete the following information):
chrome and edge

nb warnings: simple-feature-transformation-exp nb tabular explainer

Describe the bug
simple-feature-transformation-exp nb during tabular explainer use

To Reproduce
Steps to reproduce the behavior:

  1. run notebook
  2. warning occurs during cell to explain model using tabularexplainer

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.
image

Desktop (please complete the following information):
Edge

Additional context
Add any other context about the problem here.

How to use the Image explainer

Describe the bug
A clear and concise description of what the bug is.

I am unable to understand how to use this program to run my CNN model through it, in order to know which pixels are the essential ones.

To Reproduce
Steps to reproduce the behavior:

  1. Follow your "Getting Started"
  2. Open "notebooks/explain-multiclass-classification-local.ipynb"
  3. Look at the image;
    image
  4. Try to understand how one is supposed to use the Image Kernel mentioned in the image.

Expected behavior
I expect to have a clear and concise way of using your tool in order to obtain some explanation as to what my CNN model is looking at when making predictions.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows
  • Browser: Chrome
  • Version

Additional context
I feel like I am just missing the part of your README-files where you explain how to use the Image Explainer mentioned in the image above.

I can also note that I have a .pb (TensorFlow) model, and a .onnx model.

Error while Uploading Model Explainations using Azure-Interpret ExplanationClient

Our model is RandomForestRegressor from sklearn.ensemble.

import lightgbm
from interpret.ext.blackbox import PFIExplainer
#from interpret.ext.glassbox import DecisionTreeExplainableModel
from azureml.contrib.interpret.explanation.explanation_client import ExplanationClient
model = train_model(X_train_df,y_train_df)

explainer = PFIExplainer(model, features = feature_names)

global_explanation = explainer.explain_global(X_test_df[0:50],true_labels=y_test_df[0:50])

explain_client = ExplanationClient.from_run(run)
explain_client.upload_model_explanation(global_explanation)

We are getting the following error

Traceback (most recent call last):
  File "training/train.py", line 83, in <module>
    explain_client.upload_model_explanation(global_explanation)
  File "/azureml-envs/azureml_d5d57a45ca9af991b8408524822c201f/lib/python3.6/site-packages/azureml/interpret/_internal/explanation_client.py", line 793, in upload_model_explanation
    asset_type=History.ASSET_TYPE
TypeError: create_asset() got an unexpected keyword argument 'asset_type'

We have tried - TabularExplainer, MimicExplainer(with DecisionTreeExplainableModel) but all of them result in the same error.

ExplanationDashboard fails trying to connect to IPv6

Describe the bug
On a system that doesn't support or doesn't allow opening ports using IPv6, creating an ExplanationDashboard fails, saying that it couldn't find/open any available port.

To Reproduce
Steps to reproduce the behavior:

  1. Use a system that doesn't support or allow IPv6 to refer to localhost
  2. Instantiate the `ExplanationDashboard

Expected behavior
I expected the dashboard to initialize, including creating and running the Flask app in the backend.

Environment:

  • OS: RHEL 7.7
  • Browser: Chrome
  • interpret_community version 0.10.2

Cause
Identified the location causing the problem as the _local_port_available method (full reference: interpret_community.widget.explanation_dashboard.ExplanationDashboard.DashboardService._local_port_available. It tries both the specified IP address as well as the IPv6 version of localhost. Without the IPv6 check it works on my server.

I recommend removing that check, because it unnecessarily bypasses the user-specified IP. If the user wants to use an IPv6 address, they can specify so explicitly.

The number of feature names is not right when use 'LinearExplainableModel' for MimicExplainer

We are using MimicExplainer with LinearExplainableModel. And we got this error when the model task is classification, but if we change to use LGBMNExplainableModel, no error occurred.

Traceback (most recent call last):
  File "E:/scripts/interpret_debug.py", line 44, in <module>
    explanation = explainer.explain_global(evaluation_examples=data_x)
  File "E:\anaconda3\envs\ModuleX\lib\site-packages\interpret_community\mimic\mimic_explainer.py", line 413, in explain_global
    return _aggregate_global_from_local_explanation(**kwargs)
  File "E:\anaconda3\envs\ModuleX\lib\site-packages\interpret_community\explanation\explanation.py", line 1543, in _aggregate_global_from_local_explanation
    kwargs = _get_aggregate_kwargs(local_explanation, include_local, features, explanation_id, **kwargs)
  File "E:\anaconda3\envs\ModuleX\lib\site-packages\interpret_community\explanation\explanation.py", line 1491, in _get_aggregate_kwargs
    kwargs[ExplainParams.NUM_FEATURES] = local_explanation.num_features
  File "E:\anaconda3\envs\ModuleX\lib\site-packages\interpret_community\explanation\explanation.py", line 276, in num_features
    raise Exception('The number of feature names passed in must be the same as the number of '
Exception: The number of feature names passed in must be the same as the number of columns in the data.

After some debugging, it looks like the kwargs[ExplainParams.NUM_FEATURES] is not set as expected if the raw_importances is a 1d list of sparse matrix in explanation.py:

def _create_raw_feats_local_explanation(engineered_feats_explanation, feature_maps=None, **kwargs):
raw_importances = engineered_feats_explanation.get_raw_feature_importances(feature_maps)
is_1d = not isinstance(raw_importances[0], list)
is_3d = not is_1d and isinstance(raw_importances[0][0], list)
if is_1d:
kwargs[ExplainParams.NUM_FEATURES] = len(raw_importances)
else:
kwargs[ExplainParams.NUM_FEATURES] = len(raw_importances[0][0]) if is_3d else len(raw_importances[0])
return _create_local_explanation(local_importance_values=np.array(raw_importances), **kwargs)

And this error can be reproduced by the following codes:

import scipy
import pandas as pd
import numpy as np
from sklearn.preprocessing import OneHotEncoder
from sklearn.linear_model import LogisticRegression
from interpret_community.mimic.models.linear_model import LinearExplainableModel
from interpret_community.mimic.mimic_explainer import MimicExplainer
from interpret_community.common.constants import ModelTask
from interpret_community.mimic.models.lightgbm_model import LGBMExplainableModel

# prepare sample dataset
n_samples = 100
n_cat_features = 15

cat_feature_names = [f'cat_feature_{i}' for i in range(n_cat_features)]
cat_features = np.random.choice(['a', 'b', 'c', 'd'], (n_samples, n_cat_features))

data_x = pd.DataFrame(cat_features, columns=cat_feature_names)
data_y = np.random.choice(['0', '1'], n_samples)

# prepare feature encoders
cat_feature_encoders = [OneHotEncoder().fit(cat_features[:, i].reshape(-1, 1)) for i in range(n_cat_features)]

# fit binary classification model
encoded_cat_features = [cat_feature_encoders[i].transform(cat_features[:, i].reshape(-1, 1)) for i in
                        range(n_cat_features)]
encoded_cat_features = scipy.sparse.hstack(encoded_cat_features, format='csr')

model = LogisticRegression(random_state=42).fit(encoded_cat_features, data_y)

# generate explanation
cat_transformations = [([cat_feature_name], encoder) for cat_feature_name, encoder in
                       zip(cat_feature_names, cat_feature_encoders)]

explainer = MimicExplainer(model=model,
                           initialization_examples=data_x,
                           explainable_model=LinearExplainableModel,  # if use 'LGBMExplainableModel', no error raised
                           explainable_model_args={'sparse_data': True},
                           augment_data=False,
                           features=cat_feature_names,
                           classes=['0', '1'],
                           transformations=cat_transformations,
                           model_task=ModelTask.Classification)
explanation = explainer.explain_global(evaluation_examples=data_x)

lightgbm tests failing for mac build pipeline

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

ModuleNotFoundError: No module named 'shap.common'

Describe the bug
Hi when I tried to run the Mimic Explainer on AML, I got this error:
from interpret_community.mimic import MimicExplainer
File "/azureml-envs/azureml_c79128fc6072dcd6abe8fafd8aef7fd3/lib/python3.6/site-packages/interpret_community/init.py", line 11, in
from .tabular_explainer import TabularExplainer
File "/azureml-envs/azureml_c79128fc6072dcd6abe8fafd8aef7fd3/lib/python3.6/site-packages/interpret_community/tabular_explainer.py", line 9, in
from .dataset.decorator import tabular_decorator
File "/azureml-envs/azureml_c79128fc6072dcd6abe8fafd8aef7fd3/lib/python3.6/site-packages/interpret_community/dataset/decorator.py", line 7, in
from .dataset_wrapper import DatasetWrapper
File "/azureml-envs/azureml_c79128fc6072dcd6abe8fafd8aef7fd3/lib/python3.6/site-packages/interpret_community/dataset/dataset_wrapper.py", line 11, in
from ..common.explanation_utils import _summarize_data, _generate_augmented_data
File "/azureml-envs/azureml_c79128fc6072dcd6abe8fafd8aef7fd3/lib/python3.6/site-packages/interpret_community/common/explanation_utils.py", line 19, in
from shap.common import DenseData
ModuleNotFoundError: No module named 'shap.common'

I‘ve installed interpret-community and azureml-interpret in my enviroment.

Expected behavior
How to fix this in AML?

Imports fail on notebook VM

Describe the bug
On creation of a new notebook VM, there have been multiple failures to import azureml.contrib, so the dashboard can't be used.

To Reproduce
Steps to reproduce the behavior:

  1. Create new notebook VM with default settings
  2. Run all for local regression notebook
  3. Scroll down to the dashboard section once it's done
  4. See error

Was fixed by importing the dashboard from interpret-community instead.

Screen Shot 2019-10-31 at 10 37 28 AM

nb warnings: simple-feature-transformation-exp nb warning when doing global explaining using local comp

Describe the bug
warning in simple-feature-transformation-exp

To Reproduce
Steps to reproduce the behavior:

  1. run nb
  2. try global explainer with local component'

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.
image

Desktop (please complete the following information):
Edge

Additional context
Add any other context about the problem here.

API testing

  • param order
  • public functions
  • public properties

Issue with importing explainers and models

Hello,
I have issues importing explainer and models on my local machine. I have followed all the installation steps as listed in this repo.

I am trying to use the library in a jupyter notebook in VSCode (Python 3)

When I execute
from interpret.ext.blackbox import MimicExplainer
I get the following error
ImportError: cannot import name 'MimicExplainer' from 'interpret.ext.blackbox' (C:\Users<username>\AppData\Roaming\Python\Python37\site-packages\interpret\ext\blackbox\__init__.py)

The following command executes
from interpret.ext.blackbox import *
But when I try using the MimicExplainer, it throws this error
NameError: name 'MimicExplainer' is not defined

Desktop:

  • Windows 10

nb warnings: simple-feature-transformation-exp nb warning when training svm

Describe the bug
When training an SVM, a deprecation warning occurs.

To Reproduce
Steps to reproduce the behavior:

  1. run the nb
  2. train step has warning

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
Train a SVM classification model, which you want to explain:

image

Desktop (please complete the following information):
Edge

Additional context
Add any other context about the problem here.

How to enable ICE and use What-If on Databricks?

Hi!

Been trying to explore the framework and wanted to try out and further understand perturbations and what-ifs. But upon rendering the ExplanationDashboard, there's a note below stating that an operationalized model is needed to make predictions on hypothetical datapoints for what-ifs. How do we proceed from here?

Thanks!

image

functionalizty change:new need to "trust" notebook in order to run local

Describe the bug
This is a change to how it worked previously. It had not been necessary to "trust" the nb to run it.

To Reproduce
Steps to reproduce the behavior:

  1. set up env
  2. run notebook
  3. Then message about requirement to trust notebook

Desktop (please complete the following information):

  • chrome

update scipy import style

noticed something interesting while I was looking through lightgbm python code - they don't use "import scipy as sp", which at first I thought was a bad decision. Then I ran into this, which suggested that for scipy it's better to import specific modules instead of the top-level namespace:
https://docs.scipy.org/doc/scipy/reference/api.html#guidelines-for-importing-functions-from-scipy
https://stackoverflow.com/questions/36014733/official-abbreviation-for-import-scipy-as-sp-sc
rougier/python-opengl#1
Seems like it might be good to apply this suggested style to intepret-community as well.

name 'LGBMRegressor' is not defined

I am getting this error while trying to use the MimicExplainer in your advanced-feature-transformations-explain-local.ipynb notebook.

I have lightgbm and all installed, but cannot seem to get this working. The SHAP based explainers are working fine, but running

explainer = MimicExplainer(clf.steps[-1][1], 
                            x_train, 
                            LGBMExplainableModel, 
                           augment_data=True, 
                            max_num_of_augmentations=10, 
                            features=x_train.columns, 
                            transformations=transformations, 
                            allow_all_transformations=True)

gives the error

NameError                                 Traceback (most recent call last)
<ipython-input-27-abf3dd406d1c> in async-def-wrapper()
     27 
     28 
---> 29 
     30 
     31 

~/anaconda3/envs/interp/lib/python3.6/site-packages/interpret_community/dataset/decorator.py in init_wrapper(self, model, initialization_examples, *args, **kwargs)
     36         if not isinstance(initialization_examples, DatasetWrapper):
     37             initialization_examples = DatasetWrapper(initialization_examples)
---> 38         return init_func(self, model, initialization_examples, *args, **kwargs)
     39     return init_wrapper

~/anaconda3/envs/interp/lib/python3.6/site-packages/interpret_community/mimic/mimic_explainer.py in __init__(self, model, initialization_examples, explainable_model, explainable_model_args, is_function, augment_data, max_num_of_augmentations, explain_subset, features, classes, transformations, allow_all_transformations, shap_values_output, categorical_features, model_task, reset_index, **kwargs)
    302             explainable_model_args[ExplainParams.SHAP_VALUES_OUTPUT] = shap_values_output
    303         self.surrogate_model = _model_distill(self.function, explainable_model, training_data,
--> 304                                               original_training_data, explainable_model_args)
    305         self._method = self.surrogate_model._method
    306         self._original_eval_examples = None

~/anaconda3/envs/interp/lib/python3.6/site-packages/interpret_community/mimic/model_distill.py in _model_distill(teacher_model_predict_fn, uninitialized_surrogate_model, data, original_training_data, explainable_model_args)
     67                                                         **explainable_model_args)
     68     else:
---> 69         surrogate_model = uninitialized_surrogate_model(**explainable_model_args)
     70     if is_classifier and teacher_y.shape[1] == 2:
     71         # Make sure output has only 1 dimension

~/anaconda3/envs/interp/lib/python3.6/site-packages/interpret_community/mimic/models/lightgbm_model.py in __init__(self, multiclass, random_state, shap_values_output, classification, **kwargs)
     93             initializer = LGBMClassifier
     94         else:
---> 95             initializer = LGBMRegressor
     96         self._lgbm = initializer(random_state=random_state, **initializer_args)
     97         super(LGBMExplainableModel, self).__init__(**kwargs)

NameError: name 'LGBMRegressor' is not defined

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.