2021-02-05 17:12:51 +00:00
|
|
|
{ lib
|
2020-11-30 08:33:03 +00:00
|
|
|
, buildPythonPackage
|
|
|
|
, fetchFromGitHub
|
|
|
|
, pytestCheckHook
|
2023-07-15 17:15:38 +00:00
|
|
|
, pythonOlder
|
|
|
|
, writeText
|
|
|
|
, catboost
|
|
|
|
, cloudpickle
|
|
|
|
, ipython
|
|
|
|
, lightgbm
|
|
|
|
, lime
|
|
|
|
, matplotlib
|
|
|
|
, nose
|
|
|
|
, numba
|
2020-11-30 08:33:03 +00:00
|
|
|
, numpy
|
2022-10-06 18:32:54 +00:00
|
|
|
, opencv4
|
2023-07-15 17:15:38 +00:00
|
|
|
, pandas
|
2022-10-06 18:32:54 +00:00
|
|
|
, pyspark
|
2023-07-15 17:15:38 +00:00
|
|
|
, pytest-mpl
|
|
|
|
, scikit-learn
|
|
|
|
, scipy
|
2022-10-06 18:32:54 +00:00
|
|
|
, sentencepiece
|
2023-07-15 17:15:38 +00:00
|
|
|
, setuptools
|
2020-11-30 08:33:03 +00:00
|
|
|
, slicer
|
2023-07-15 17:15:38 +00:00
|
|
|
, tqdm
|
|
|
|
, transformers
|
|
|
|
, xgboost
|
2020-11-30 08:33:03 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
buildPythonPackage rec {
|
|
|
|
pname = "shap";
|
2023-08-04 22:07:22 +00:00
|
|
|
version = "0.42.1";
|
2023-07-15 17:15:38 +00:00
|
|
|
format = "pyproject";
|
|
|
|
|
|
|
|
disabled = pythonOlder "3.7";
|
2020-11-30 08:33:03 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "slundberg";
|
2023-07-15 17:15:38 +00:00
|
|
|
repo = "shap";
|
2022-08-12 12:06:08 +00:00
|
|
|
rev = "refs/tags/v${version}";
|
2023-08-04 22:07:22 +00:00
|
|
|
hash = "sha256-Ezq6WS6QnoM5uEfo2DgDAEo1HkQ1KjmfgIyVWh3RM94=";
|
2020-11-30 08:33:03 +00:00
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
setuptools
|
|
|
|
];
|
|
|
|
|
2020-11-30 08:33:03 +00:00
|
|
|
propagatedBuildInputs = [
|
2023-07-15 17:15:38 +00:00
|
|
|
cloudpickle
|
|
|
|
numba
|
2020-11-30 08:33:03 +00:00
|
|
|
numpy
|
|
|
|
pandas
|
2023-07-15 17:15:38 +00:00
|
|
|
scikit-learn
|
|
|
|
scipy
|
2020-11-30 08:33:03 +00:00
|
|
|
slicer
|
2023-07-15 17:15:38 +00:00
|
|
|
tqdm
|
2020-11-30 08:33:03 +00:00
|
|
|
];
|
|
|
|
|
2022-10-06 18:32:54 +00:00
|
|
|
passthru.optional-dependencies = {
|
|
|
|
plots = [ matplotlib ipython ];
|
|
|
|
others = [ lime ];
|
|
|
|
};
|
|
|
|
|
|
|
|
preCheck = let
|
|
|
|
# This pytest hook mocks and catches attempts at accessing the network
|
|
|
|
# tests that try to access the network will raise, get caught, be marked as skipped and tagged as xfailed.
|
|
|
|
conftestSkipNetworkErrors = writeText "conftest.py" ''
|
|
|
|
from _pytest.runner import pytest_runtest_makereport as orig_pytest_runtest_makereport
|
2023-07-15 17:15:38 +00:00
|
|
|
import urllib, requests, transformers
|
2022-10-06 18:32:54 +00:00
|
|
|
|
|
|
|
class NetworkAccessDeniedError(RuntimeError): pass
|
|
|
|
def deny_network_access(*a, **kw):
|
|
|
|
raise NetworkAccessDeniedError
|
|
|
|
|
|
|
|
requests.head = deny_network_access
|
|
|
|
requests.get = deny_network_access
|
|
|
|
urllib.request.urlopen = deny_network_access
|
|
|
|
urllib.request.Request = deny_network_access
|
2023-07-15 17:15:38 +00:00
|
|
|
transformers.AutoTokenizer.from_pretrained = deny_network_access
|
2022-10-06 18:32:54 +00:00
|
|
|
|
|
|
|
def pytest_runtest_makereport(item, call):
|
|
|
|
tr = orig_pytest_runtest_makereport(item, call)
|
|
|
|
if call.excinfo is not None and call.excinfo.type is NetworkAccessDeniedError:
|
|
|
|
tr.outcome = 'skipped'
|
|
|
|
tr.wasxfail = "reason: Requires network access."
|
|
|
|
return tr
|
|
|
|
'';
|
|
|
|
in ''
|
2020-11-30 08:33:03 +00:00
|
|
|
export HOME=$TMPDIR
|
|
|
|
# when importing the local copy the extension is not found
|
|
|
|
rm -r shap
|
2022-10-06 18:32:54 +00:00
|
|
|
|
|
|
|
# Add pytest hook skipping tests that access network.
|
|
|
|
# These tests are marked as "Expected fail" (xfail)
|
|
|
|
cat ${conftestSkipNetworkErrors} >> tests/conftest.py
|
2020-11-30 08:33:03 +00:00
|
|
|
'';
|
2023-07-15 17:15:38 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
nativeCheckInputs = [
|
2023-07-15 17:15:38 +00:00
|
|
|
ipython
|
2022-10-06 18:32:54 +00:00
|
|
|
matplotlib
|
|
|
|
nose
|
2023-07-15 17:15:38 +00:00
|
|
|
pytest-mpl
|
|
|
|
pytestCheckHook
|
2022-10-06 18:32:54 +00:00
|
|
|
# optional dependencies, which only serve to enable more tests:
|
|
|
|
catboost
|
2023-07-15 17:15:38 +00:00
|
|
|
lightgbm
|
|
|
|
opencv4
|
2022-10-06 18:32:54 +00:00
|
|
|
pyspark
|
|
|
|
sentencepiece
|
2023-07-15 17:15:38 +00:00
|
|
|
#torch # we already skip all its tests due to slowness, adding it does nothing
|
|
|
|
transformers
|
|
|
|
xgboost
|
2022-10-06 18:32:54 +00:00
|
|
|
];
|
2023-07-15 17:15:38 +00:00
|
|
|
|
2022-10-06 18:32:54 +00:00
|
|
|
disabledTestPaths = [
|
|
|
|
# The resulting plots look sane, but does not match pixel-perfectly with the baseline.
|
|
|
|
# Likely due to a matplotlib version mismatch, different backend, or due to missing fonts.
|
|
|
|
"tests/plots/test_summary.py" # FIXME: enable
|
|
|
|
];
|
2023-07-15 17:15:38 +00:00
|
|
|
|
2020-11-30 08:33:03 +00:00
|
|
|
disabledTests = [
|
2023-07-15 17:15:38 +00:00
|
|
|
# The same reason as above test_summary.py
|
|
|
|
"test_simple_bar_with_cohorts_dict"
|
|
|
|
"test_random_summary_violin_with_data2"
|
|
|
|
"test_random_summary_layered_violin_with_data2"
|
2022-10-06 18:32:54 +00:00
|
|
|
];
|
|
|
|
|
2023-01-11 07:51:40 +00:00
|
|
|
pythonImportsCheck = [
|
2022-10-06 18:32:54 +00:00
|
|
|
"shap"
|
|
|
|
"shap.explainers"
|
|
|
|
"shap.explainers.other"
|
|
|
|
"shap.plots"
|
|
|
|
"shap.plots.colors"
|
|
|
|
"shap.benchmark"
|
|
|
|
"shap.maskers"
|
|
|
|
"shap.utils"
|
|
|
|
"shap.actions"
|
|
|
|
"shap.models"
|
2020-11-30 08:33:03 +00:00
|
|
|
];
|
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with lib; {
|
2020-11-30 08:33:03 +00:00
|
|
|
description = "A unified approach to explain the output of any machine learning model";
|
|
|
|
homepage = "https://github.com/slundberg/shap";
|
2023-03-04 12:14:45 +00:00
|
|
|
changelog = "https://github.com/slundberg/shap/releases/tag/v${version}";
|
2020-11-30 08:33:03 +00:00
|
|
|
license = licenses.mit;
|
2023-08-04 22:07:22 +00:00
|
|
|
maintainers = with maintainers; [ evax natsukium ];
|
2020-11-30 08:33:03 +00:00
|
|
|
};
|
|
|
|
}
|