Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
{
"name": "Python 3",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:0-3.9",
"image": "mcr.microsoft.com/devcontainers/python:0-3.10",

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
"features": {
"ghcr.io/jsburckhardt/devcontainer-features/uv:1": {},
"ghcr.io/jsburckhardt/devcontainer-features/ruff:1": {}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
Comment thread
adamsardar marked this conversation as resolved.
"postCreateCommand": "pip3 install --user -r requirements-dev.txt; pre-commit install",
"postCreateCommand": "uv pip install --prefix ~/.local -r requirements-dev.txt && prek install",

// Configure tool-specific properties.
"customizations": {
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ body:
id: environment
attributes:
label: Environment
description: Please provide environment details that will help us reproduce the issue e.g. operating system and tubular/scikit-learn/pandas versions.
description: Please provide environment details that will help us reproduce the issue e.g. operating system and numpy/shap/xgboost-cpu versions.
validations:
required: true
- type: textarea
Expand Down
39 changes: 26 additions & 13 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

name: Python package build and test

permissions:
contents: read

on:
push:
pull_request:
Expand Down Expand Up @@ -42,9 +45,9 @@ jobs:

- name: Upload coverage pytest html test results to github
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage-html-pytest-results
name: coverage-html-pytest-results-${{ matrix.python-version }}
path: htmlcov

lint:
Expand All @@ -56,27 +59,37 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up Python 3.9
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: ${{ matrix.python-version }}

- name: Install ruff
- name: Install linters
run: |
python -m pip install uv
uv venv -p 3.9 ruff
source ruff/bin/activate
uv venv -p ${{ matrix.python-version }} $HOME/lints
source $HOME/lints/bin/activate
uv pip install -r requirements-dev.txt

- name: Lint with ruff
run: |
source ruff/bin/activate
source $HOME/lints/bin/activate
ruff --version
ruff check --output-format github .

- name: Check formatting with ruff
- name: Check for typos with codespell
run: |
source ruff/bin/activate
ruff --version
ruff format --diff .
ruff format --check .
source $HOME/lints/bin/activate
codespell --version
codespell .

- name: Check for typos with typos
run: |
source $HOME/lints/bin/activate
typos --version
typos .

- name: lint code examples in docs
run: |
source $HOME/lints/bin/activate
prek run blacken-docs --all-files
43 changes: 31 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
repos:
- repo: https://github.com/ambv/black
rev: 22.3.0
hooks:
- id: black
language_version: python3

- repo: https://github.com/pycqa/bandit
rev: 1.7.4
hooks:
- id: bandit

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.14.0
hooks:
# Run the linter.
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/MarcoGorelli/auto-walrus
rev: 0.3.4
hooks:
- id: auto-walrus
- repo: https://github.com/codespell-project/codespell
rev: 'v2.4.1'
hooks:
- id: codespell
additional_dependencies:
- tomli
- repo: https://github.com/crate-ci/typos
rev: 'v1.39.0'
hooks:
- id: typos
- repo: https://github.com/adamchainz/blacken-docs
rev: "1.20.0"
hooks:
- id: blacken-docs
args: [--skip-errors]
additional_dependencies:
- black==22.12.0
12 changes: 11 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,23 @@ Subsections for each version can be one of the following;

Each individual change should have a link to the pull request after the description of the change.

1.0.1 (unreleased)
------------------

Changed
^^^^^^^
- Reactivated CI and added PR approval guardrails (https://github.com/azukds/model_interpreter/pull/8)
- Updated CI configuration to follow tubular's python-package.yml (https://github.com/azukds/model_interpreter/pull/8)
- Switched to prek for pre-commit checks (https://github.com/azukds/model_interpreter/pull/8)
- Fixed spelling mistakes and removed stale tubular references (https://github.com/azukds/model_interpreter/pull/8)

1.0.0 (2024-08-06)
-------------------

Added
^^^^^
- Moved config to pyproject.toml approach
- Updated envs and impacted logic (e.g to accomodate new shap behaviour)
- Updated envs and impacted logic (e.g to accommodate new shap behaviour)
- Setup devcontainer config for codespaces
- Updated build pipeline

Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Contributing
============

Thanks for your interest in contributing to this package! No contibution is too small! We're hoping it can be made even better through community contributions.
Thanks for your interest in contributing to this package! No contribution is too small! We're hoping it can be made even better through community contributions.

Requests and feedback
---------------------
Expand All @@ -24,7 +24,7 @@ Then clone the fork (or this repository if internal);
git clone https://github.com/lvgig/model_interpreter.git
cd model_interpreter

Then install tubular and dependencies for development;
Then install model_interpreter and dependencies for development;

.. code::

Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ from model_interpreter.interpreter import ModelInterpreter

# generate a classification dataset
X, y = make_classification(
n_samples=1000,
n_features=4, n_informative=2,
n_redundant=0, random_state=0,
shuffle=False
n_samples=1000,
n_features=4,
n_informative=2,
n_redundant=0,
random_state=0,
shuffle=False,
)

# fit a model
Expand All @@ -45,11 +47,10 @@ model_interpreter.fit(clf)
# return feature contribution importances for a single row
single_row = X.head(1)
contribution_list = single_model_contribution.transform(
single_row, return_type="name_value_dicts"
single_row, return_type="name_value_dicts"
)

print(contribution_list)

```

Which will return the following output:
Expand Down
4 changes: 2 additions & 2 deletions examples/Random_Forest/binary_classification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"A model interpreter object is created by specifiying the feature names in the same order as used for building the model."
"A model interpreter object is created by specifying the feature names in the same order as used for building the model."
]
},
{
Expand Down Expand Up @@ -357,7 +357,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"There are also three `sorting` options avaliable:\n",
"There are also three `sorting` options available:\n",
"- `'abs'`, which is the default used in the above examples sorts by the absolute value of the feature contribution\n",
"- `'positive'`, which sorts the contributions in descending order\n",
"- `'label'`, which sorts in a descending order if `pred_label > 0`, and ascending if `pred_label = 0`\n",
Expand Down
4 changes: 2 additions & 2 deletions examples/Random_Forest/multiclass_classification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"A model interpreter object is created by specifiying the feature names in the same order as used for building the model."
"A model interpreter object is created by specifying the feature names in the same order as used for building the model."
]
},
{
Expand Down Expand Up @@ -364,7 +364,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"There are also three `sorting` options avaliable:\n",
"There are also three `sorting` options available:\n",
"- `'abs'`, which is the default used in the above examples sorts by the absolute value of the feature contribution\n",
"- `'positive'`, which sorts the contributions in descending order\n",
"- `'label'`, which sorts in a descending order if `pred_label > 0`, and ascending if `pred_label = 0`\n",
Expand Down
18 changes: 9 additions & 9 deletions examples/XGB/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"A model interpreter object is created by specifiying the feature names in the same order as used for building the model."
"A model interpreter object is created by specifying the feature names in the same order as used for building the model."
]
},
{
Expand Down Expand Up @@ -343,7 +343,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[{'Name': 'MedInc feature', 'Value': -0.7173248529}, {'Name': 'Lattitude of location', 'Value': -0.2954589427}, {'Name': 'Average occupation', 'Value': -0.2584415674}, {'Name': 'Longitude of location', 'Value': -0.194666937}, {'Name': 'Average number of rooms', 'Value': 0.0455645546}, {'Name': 'Age of house', 'Value': -0.0052499785}, {'Name': 'Average number of bedrooms', 'Value': -0.0039967196}, {'Name': 'Population feature', 'Value': -0.0015882736}]\n"
"[{'Name': 'MedInc feature', 'Value': -0.7173248529}, {'Name': 'Latitude of location', 'Value': -0.2954589427}, {'Name': 'Average occupation', 'Value': -0.2584415674}, {'Name': 'Longitude of location', 'Value': -0.194666937}, {'Name': 'Average number of rooms', 'Value': 0.0455645546}, {'Name': 'Age of house', 'Value': -0.0052499785}, {'Name': 'Average number of bedrooms', 'Value': -0.0039967196}, {'Name': 'Population feature', 'Value': -0.0015882736}]\n"
]
}
],
Expand All @@ -355,7 +355,7 @@
" \"AveBedrms\": \"Average number of bedrooms\",\n",
" \"Population\": \"Population feature\",\n",
" \"AveOccup\": \"Average occupation\",\n",
" \"Latitude\": \"Lattitude of location\",\n",
" \"Latitude\": \"Latitude of location\",\n",
" \"Longitude\": \"Longitude of location\",\n",
"}\n",
"\n",
Expand Down Expand Up @@ -412,7 +412,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"There are also three `sorting` options avaliable:\n",
"There are also three `sorting` options available:\n",
"- `'abs'`, which is the default used in the above examples sorts by the absolute value of the feature contribution\n",
"- `'positive'`, which sorts the contributions in descending order\n",
"- `'label'`, which sorts in a descending order if `pred_label > 0`, and ascending if `pred_label = 0`\n",
Expand All @@ -436,7 +436,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[{'Name': 'MedInc feature', 'Value': -0.7173248529}, {'Name': 'Lattitude of location', 'Value': -0.2954589427}, {'Name': 'Average occupation', 'Value': -0.2584415674}, {'Name': 'Longitude of location', 'Value': -0.194666937}, {'Name': 'Average number of rooms', 'Value': 0.0455645546}]\n"
"[{'Name': 'MedInc feature', 'Value': -0.7173248529}, {'Name': 'Latitude of location', 'Value': -0.2954589427}, {'Name': 'Average occupation', 'Value': -0.2584415674}, {'Name': 'Longitude of location', 'Value': -0.194666937}, {'Name': 'Average number of rooms', 'Value': 0.0455645546}]\n"
]
}
],
Expand All @@ -461,7 +461,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[{'Name': 'Average number of rooms', 'Value': 0.0455645546}, {'Name': 'Population feature', 'Value': -0.0015882736}, {'Name': 'Average number of bedrooms', 'Value': -0.0039967196}, {'Name': 'Age of house', 'Value': -0.0052499785}, {'Name': 'Longitude of location', 'Value': -0.194666937}, {'Name': 'Average occupation', 'Value': -0.2584415674}, {'Name': 'Lattitude of location', 'Value': -0.2954589427}, {'Name': 'MedInc feature', 'Value': -0.7173248529}]\n"
"[{'Name': 'Average number of rooms', 'Value': 0.0455645546}, {'Name': 'Population feature', 'Value': -0.0015882736}, {'Name': 'Average number of bedrooms', 'Value': -0.0039967196}, {'Name': 'Age of house', 'Value': -0.0052499785}, {'Name': 'Longitude of location', 'Value': -0.194666937}, {'Name': 'Average occupation', 'Value': -0.2584415674}, {'Name': 'Latitude of location', 'Value': -0.2954589427}, {'Name': 'MedInc feature', 'Value': -0.7173248529}]\n"
]
}
],
Expand All @@ -486,7 +486,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[{'Name': 'MedInc feature', 'Value': -0.7173248529}, {'Name': 'Lattitude of location', 'Value': -0.2954589427}, {'Name': 'Average occupation', 'Value': -0.2584415674}, {'Name': 'Longitude of location', 'Value': -0.194666937}, {'Name': 'Age of house', 'Value': -0.0052499785}, {'Name': 'Average number of bedrooms', 'Value': -0.0039967196}, {'Name': 'Population feature', 'Value': -0.0015882736}, {'Name': 'Average number of rooms', 'Value': 0.0455645546}]\n"
"[{'Name': 'MedInc feature', 'Value': -0.7173248529}, {'Name': 'Latitude of location', 'Value': -0.2954589427}, {'Name': 'Average occupation', 'Value': -0.2584415674}, {'Name': 'Longitude of location', 'Value': -0.194666937}, {'Name': 'Age of house', 'Value': -0.0052499785}, {'Name': 'Average number of bedrooms', 'Value': -0.0039967196}, {'Name': 'Population feature', 'Value': -0.0015882736}, {'Name': 'Average number of rooms', 'Value': 0.0455645546}]\n"
]
}
],
Expand Down Expand Up @@ -518,7 +518,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"{'MedInc feature': -0.71732485, 'Lattitude of location': -0.29545894, 'Average occupation': -0.25844157, 'Longitude of location': -0.19466694, 'Average number of rooms': 0.045564555}\n"
"{'MedInc feature': -0.71732485, 'Latitude of location': -0.29545894, 'Average occupation': -0.25844157, 'Longitude of location': -0.19466694, 'Average number of rooms': 0.045564555}\n"
]
}
],
Expand All @@ -543,7 +543,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[('MedInc feature', -0.71732485), ('Lattitude of location', -0.29545894), ('Average occupation', -0.25844157), ('Longitude of location', -0.19466694), ('Average number of rooms', 0.045564555)]\n"
"[('MedInc feature', -0.71732485), ('Latitude of location', -0.29545894), ('Average occupation', -0.25844157), ('Longitude of location', -0.19466694), ('Average number of rooms', 0.045564555)]\n"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion examples/XGB/example_ohe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@
"metadata": {},
"source": [
"\n",
"### Create catagorical variable"
"### Create categorical variable"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion examples/non_standard_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"A model interpreter object is created by specifiying the feature names in the same order as used for building the model."
"A model interpreter object is created by specifying the feature names in the same order as used for building the model."
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions model_interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ModelInterpreter:
model features, if applicable. The one hot encoded feature names are
automatically derived based on this list, otherwise they are treated
normally. eg: passing ["colour"] will aggregate the contributions
of fields with a name beggining with "colour_" and then return the
of fields with a name beginning with "colour_" and then return the
aggregated contributions for "colour"

"""
Expand Down Expand Up @@ -113,7 +113,7 @@ def _kernel_explainer_setup(self, model, X_train, is_classification, n_samples):

if is_classification is None:
raise ValueError(
f"is_classification input required to fit kernel explainer. True for a classification model, False for a regression model, recieved {is_classification}"
f"is_classification input required to fit kernel explainer. True for a classification model, False for a regression model, received {is_classification}"
)

elif (is_classification is True) and (not hasattr(model, "predict_proba")):
Expand Down Expand Up @@ -406,7 +406,7 @@ def transform(

return_precision: int, default = 16
Comment thread
adamsardar marked this conversation as resolved.
how many decimal places to round the shap values in the return
message to. Default is 16 which mantains the decimal places
message to. Default is 16 which maintains the decimal places
returned by shap explainers

Return:
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ dev = [
"pytest-mock",
"pytest-cov",
"pytest-benchmark",
"prek",
"codespell",
"typos",
"hypothesis",
"mypy",
"ruff",
Expand Down
Loading
Loading