In [1]:
!pip install interpret
Collecting interpret
Downloading interpret-0.7.8-py3-none-any.whl.metadata (1.2 kB)
Collecting interpret-core==0.7.8 (from interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret)
Downloading interpret_core-0.7.8-py3-none-any.whl.metadata (2.9 kB)
Requirement already satisfied: numpy>=1.25 in /usr/local/lib/python3.12/dist-packages (from interpret-core==0.7.8->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (2.4.6)
Requirement already satisfied: pandas>=0.24 in /usr/local/lib/python3.12/dist-packages (from interpret-core==0.7.8->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (2.3.3)
Requirement already satisfied: scikit-learn>=1.6.0 in /usr/local/lib/python3.12/dist-packages (from interpret-core==0.7.8->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (1.6.1)
Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.12/dist-packages (from interpret-core==0.7.8->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (1.5.3)
Requirement already satisfied: psutil>=5.6.2 in /usr/local/lib/python3.12/dist-packages (from interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (5.9.5)
Requirement already satisfied: ipython>=5.5.0 in /usr/local/lib/python3.12/dist-packages (from interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (7.34.0)
Requirement already satisfied: plotly>=3.8.1 in /usr/local/lib/python3.12/dist-packages (from interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (5.24.1)
Collecting SALib>=1.3.3 (from interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret)
Downloading salib-1.5.2-py3-none-any.whl.metadata (11 kB)
Requirement already satisfied: shap>=0.28.5 in /usr/local/lib/python3.12/dist-packages (from interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.51.0)
Requirement already satisfied: ipywidgets>=7.4.2 in /usr/local/lib/python3.12/dist-packages (from interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (8.1.5)
Collecting aplr>=10.6.1 (from interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret)
Downloading aplr-10.23.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.metadata (1.0 kB)
Collecting dash>=2.0.0 (from interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret)
Downloading dash-4.3.0-py3-none-any.whl.metadata (11 kB)
Collecting dash-cytoscape>=0.1.1 (from interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret)
Downloading dash_cytoscape-1.0.2.tar.gz (4.0 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.0/4.0 MB 6.8 MB/s eta 0:00:00
Preparing metadata (setup.py) ... done
Requirement already satisfied: flask>=1.0.4 in /usr/local/lib/python3.12/dist-packages (from interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (3.1.3)
Collecting gevent>=1.3.6 (from interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret)
Downloading gevent-26.5.0-cp312-cp312-manylinux_2_28_x86_64.whl.metadata (14 kB)
Requirement already satisfied: requests>=2.19.0 in /usr/local/lib/python3.12/dist-packages (from interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (2.32.4)
Requirement already satisfied: Werkzeug<3.2 in /usr/local/lib/python3.12/dist-packages (from dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (3.1.8)
Requirement already satisfied: importlib-metadata in /usr/local/lib/python3.12/dist-packages (from dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (8.7.1)
Requirement already satisfied: typing_extensions>=4.1.1 in /usr/local/lib/python3.12/dist-packages (from dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (4.15.0)
Collecting retrying (from dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret)
Downloading retrying-1.4.2-py3-none-any.whl.metadata (5.5 kB)
Requirement already satisfied: nest-asyncio in /usr/local/lib/python3.12/dist-packages (from dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (1.6.0)
Requirement already satisfied: setuptools in /usr/local/lib/python3.12/dist-packages (from dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (75.2.0)
Collecting janus>=1.0.0 (from dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret)
Downloading janus-2.0.0-py3-none-any.whl.metadata (5.3 kB)
Requirement already satisfied: pydantic>=2.10 in /usr/local/lib/python3.12/dist-packages (from dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (2.12.3)
Requirement already satisfied: mcp>=1.23.0 in /usr/local/lib/python3.12/dist-packages (from dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (1.27.0)
Requirement already satisfied: blinker>=1.9.0 in /usr/local/lib/python3.12/dist-packages (from flask>=1.0.4->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (1.9.0)
Requirement already satisfied: click>=8.1.3 in /usr/local/lib/python3.12/dist-packages (from flask>=1.0.4->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (8.3.2)
Requirement already satisfied: itsdangerous>=2.2.0 in /usr/local/lib/python3.12/dist-packages (from flask>=1.0.4->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (2.2.0)
Requirement already satisfied: jinja2>=3.1.2 in /usr/local/lib/python3.12/dist-packages (from flask>=1.0.4->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (3.1.6)
Requirement already satisfied: markupsafe>=2.1.1 in /usr/local/lib/python3.12/dist-packages (from flask>=1.0.4->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (3.0.3)
Requirement already satisfied: greenlet>=3.2.2 in /usr/local/lib/python3.12/dist-packages (from gevent>=1.3.6->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (3.4.0)
Collecting zope.event (from gevent>=1.3.6->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret)
Downloading zope_event-6.2-py3-none-any.whl.metadata (5.4 kB)
Collecting zope.interface (from gevent>=1.3.6->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret)
Downloading zope_interface-8.5-cp312-cp312-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl.metadata (47 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 47.2/47.2 kB 2.3 MB/s eta 0:00:00
Requirement already satisfied: jedi>=0.16 in /usr/local/lib/python3.12/dist-packages (from ipython>=5.5.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.19.2)
Requirement already satisfied: decorator in /usr/local/lib/python3.12/dist-packages (from ipython>=5.5.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (5.3.1)
Requirement already satisfied: pickleshare in /usr/local/lib/python3.12/dist-packages (from ipython>=5.5.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.7.5)
Requirement already satisfied: traitlets>=4.2 in /usr/local/lib/python3.12/dist-packages (from ipython>=5.5.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (5.15.0)
Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /usr/local/lib/python3.12/dist-packages (from ipython>=5.5.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (3.0.52)
Requirement already satisfied: pygments in /usr/local/lib/python3.12/dist-packages (from ipython>=5.5.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (2.20.0)
Requirement already satisfied: backcall in /usr/local/lib/python3.12/dist-packages (from ipython>=5.5.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.2.0)
Requirement already satisfied: matplotlib-inline in /usr/local/lib/python3.12/dist-packages (from ipython>=5.5.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.2.1)
Requirement already satisfied: pexpect>4.3 in /usr/local/lib/python3.12/dist-packages (from ipython>=5.5.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (4.9.0)
Requirement already satisfied: comm>=0.1.3 in /usr/local/lib/python3.12/dist-packages (from ipywidgets>=7.4.2->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.2.3)
Requirement already satisfied: widgetsnbextension~=4.0.12 in /usr/local/lib/python3.12/dist-packages (from ipywidgets>=7.4.2->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (4.0.15)
Requirement already satisfied: jupyterlab-widgets~=3.0.12 in /usr/local/lib/python3.12/dist-packages (from ipywidgets>=7.4.2->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (3.0.16)
Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.12/dist-packages (from pandas>=0.24->interpret-core==0.7.8->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (2.9.0.post0)
Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.12/dist-packages (from pandas>=0.24->interpret-core==0.7.8->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (2025.2)
Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.12/dist-packages (from pandas>=0.24->interpret-core==0.7.8->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (2026.1)
Requirement already satisfied: tenacity>=6.2.0 in /usr/local/lib/python3.12/dist-packages (from plotly>=3.8.1->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (9.1.4)
Requirement already satisfied: packaging in /usr/local/lib/python3.12/dist-packages (from plotly>=3.8.1->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (26.0)
Requirement already satisfied: charset_normalizer<4,>=2 in /usr/local/lib/python3.12/dist-packages (from requests>=2.19.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (3.4.7)
Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.12/dist-packages (from requests>=2.19.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (3.11)
Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.12/dist-packages (from requests>=2.19.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (2.5.0)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.12/dist-packages (from requests>=2.19.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (2026.2.25)
Requirement already satisfied: matplotlib>=3.5 in /usr/local/lib/python3.12/dist-packages (from SALib>=1.3.3->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (3.10.0)
Requirement already satisfied: multiprocess in /usr/local/lib/python3.12/dist-packages (from SALib>=1.3.3->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.70.16)
Requirement already satisfied: scipy>=1.9.3 in /usr/local/lib/python3.12/dist-packages (from SALib>=1.3.3->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (1.16.3)
Requirement already satisfied: threadpoolctl>=3.1.0 in /usr/local/lib/python3.12/dist-packages (from scikit-learn>=1.6.0->interpret-core==0.7.8->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (3.6.0)
Requirement already satisfied: tqdm>=4.27.0 in /usr/local/lib/python3.12/dist-packages (from shap>=0.28.5->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (4.67.3)
Requirement already satisfied: slicer==0.0.8 in /usr/local/lib/python3.12/dist-packages (from shap>=0.28.5->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.0.8)
Requirement already satisfied: numba in /usr/local/lib/python3.12/dist-packages (from shap>=0.28.5->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.65.1)
Requirement already satisfied: llvmlite in /usr/local/lib/python3.12/dist-packages (from shap>=0.28.5->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.47.0)
Requirement already satisfied: cloudpickle in /usr/local/lib/python3.12/dist-packages (from shap>=0.28.5->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (3.1.2)
Requirement already satisfied: parso<0.9.0,>=0.8.4 in /usr/local/lib/python3.12/dist-packages (from jedi>=0.16->ipython>=5.5.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.8.6)
Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.5->SALib>=1.3.3->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (1.3.3)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.5->SALib>=1.3.3->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.12.1)
Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.5->SALib>=1.3.3->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (4.62.1)
Requirement already satisfied: kiwisolver>=1.3.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.5->SALib>=1.3.3->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (1.5.0)
Requirement already satisfied: pillow>=8 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.5->SALib>=1.3.3->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (11.3.0)
Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.5->SALib>=1.3.3->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (3.3.2)
Requirement already satisfied: anyio>=4.5 in /usr/local/lib/python3.12/dist-packages (from mcp>=1.23.0->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (4.13.0)
Requirement already satisfied: httpx-sse>=0.4 in /usr/local/lib/python3.12/dist-packages (from mcp>=1.23.0->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.4.3)
Requirement already satisfied: httpx>=0.27.1 in /usr/local/lib/python3.12/dist-packages (from mcp>=1.23.0->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.28.1)
Requirement already satisfied: jsonschema>=4.20.0 in /usr/local/lib/python3.12/dist-packages (from mcp>=1.23.0->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (4.26.0)
Requirement already satisfied: pydantic-settings>=2.5.2 in /usr/local/lib/python3.12/dist-packages (from mcp>=1.23.0->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (2.13.1)
Requirement already satisfied: pyjwt>=2.10.1 in /usr/local/lib/python3.12/dist-packages (from pyjwt[crypto]>=2.10.1->mcp>=1.23.0->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (2.12.1)
Requirement already satisfied: python-multipart>=0.0.9 in /usr/local/lib/python3.12/dist-packages (from mcp>=1.23.0->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.0.26)
Requirement already satisfied: sse-starlette>=1.6.1 in /usr/local/lib/python3.12/dist-packages (from mcp>=1.23.0->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (3.3.4)
Requirement already satisfied: starlette>=0.27 in /usr/local/lib/python3.12/dist-packages (from mcp>=1.23.0->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.52.1)
Requirement already satisfied: typing-inspection>=0.4.1 in /usr/local/lib/python3.12/dist-packages (from mcp>=1.23.0->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.4.2)
Requirement already satisfied: uvicorn>=0.31.1 in /usr/local/lib/python3.12/dist-packages (from mcp>=1.23.0->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.44.0)
Requirement already satisfied: ptyprocess>=0.5 in /usr/local/lib/python3.12/dist-packages (from pexpect>4.3->ipython>=5.5.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.7.0)
Requirement already satisfied: wcwidth in /usr/local/lib/python3.12/dist-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython>=5.5.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.6.0)
Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.12/dist-packages (from pydantic>=2.10->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.7.0)
Requirement already satisfied: pydantic-core==2.41.4 in /usr/local/lib/python3.12/dist-packages (from pydantic>=2.10->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (2.41.4)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.12/dist-packages (from python-dateutil>=2.8.2->pandas>=0.24->interpret-core==0.7.8->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (1.17.0)
Requirement already satisfied: zipp>=3.20 in /usr/local/lib/python3.12/dist-packages (from importlib-metadata->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (3.23.0)
Requirement already satisfied: dill>=0.3.8 in /usr/local/lib/python3.12/dist-packages (from multiprocess->SALib>=1.3.3->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.4.1)
Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.12/dist-packages (from httpx>=0.27.1->mcp>=1.23.0->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (1.0.9)
Requirement already satisfied: h11>=0.16 in /usr/local/lib/python3.12/dist-packages (from httpcore==1.*->httpx>=0.27.1->mcp>=1.23.0->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.16.0)
Requirement already satisfied: attrs>=22.2.0 in /usr/local/lib/python3.12/dist-packages (from jsonschema>=4.20.0->mcp>=1.23.0->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (26.1.0)
Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.12/dist-packages (from jsonschema>=4.20.0->mcp>=1.23.0->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (2025.9.1)
Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.12/dist-packages (from jsonschema>=4.20.0->mcp>=1.23.0->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.37.0)
Requirement already satisfied: rpds-py>=0.25.0 in /usr/local/lib/python3.12/dist-packages (from jsonschema>=4.20.0->mcp>=1.23.0->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (0.30.0)
Requirement already satisfied: python-dotenv>=0.21.0 in /usr/local/lib/python3.12/dist-packages (from pydantic-settings>=2.5.2->mcp>=1.23.0->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (1.2.2)
Requirement already satisfied: cryptography>=3.4.0 in /usr/local/lib/python3.12/dist-packages (from pyjwt[crypto]>=2.10.1->mcp>=1.23.0->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (43.0.3)
Requirement already satisfied: cffi>=1.12 in /usr/local/lib/python3.12/dist-packages (from cryptography>=3.4.0->pyjwt[crypto]>=2.10.1->mcp>=1.23.0->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (2.0.0)
Requirement already satisfied: pycparser in /usr/local/lib/python3.12/dist-packages (from cffi>=1.12->cryptography>=3.4.0->pyjwt[crypto]>=2.10.1->mcp>=1.23.0->dash>=2.0.0->interpret-core[aplr,dash,debug,linear,notebook,plotly,sensitivity,shap]==0.7.8->interpret) (3.0)
Downloading interpret-0.7.8-py3-none-any.whl (1.4 kB)
Downloading interpret_core-0.7.8-py3-none-any.whl (15.6 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 15.6/15.6 MB 13.7 MB/s eta 0:00:00
Downloading aplr-10.23.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (9.8 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 9.8/9.8 MB 26.8 MB/s eta 0:00:00
Downloading dash-4.3.0-py3-none-any.whl (8.4 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.4/8.4 MB 32.5 MB/s eta 0:00:00
Downloading gevent-26.5.0-cp312-cp312-manylinux_2_28_x86_64.whl (2.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 35.9 MB/s eta 0:00:00
Downloading salib-1.5.2-py3-none-any.whl (780 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 780.1/780.1 kB 24.6 MB/s eta 0:00:00
Downloading janus-2.0.0-py3-none-any.whl (12 kB)
Downloading retrying-1.4.2-py3-none-any.whl (10 kB)
Downloading zope_event-6.2-py3-none-any.whl (6.5 kB)
Downloading zope_interface-8.5-cp312-cp312-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl (270 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 270.7/270.7 kB 15.9 MB/s eta 0:00:00
Building wheels for collected packages: dash-cytoscape
Building wheel for dash-cytoscape (setup.py) ... done
Created wheel for dash-cytoscape: filename=dash_cytoscape-1.0.2-py3-none-any.whl size=4010717 sha256=63ab8a047645b81e24ff36bcacb01bc8d9a44dee241de13cba620ada22959d27
Stored in directory: /root/.cache/pip/wheels/0c/db/f6/9dcb225e9adf45dfef713542769556b1f508170a0759053892
Successfully built dash-cytoscape
Installing collected packages: zope.interface, zope.event, retrying, janus, gevent, SALib, interpret-core, aplr, dash, dash-cytoscape, interpret
Successfully installed SALib-1.5.2 aplr-10.23.0 dash-4.3.0 dash-cytoscape-1.0.2 gevent-26.5.0 interpret-0.7.8 interpret-core-0.7.8 janus-2.0.0 retrying-1.4.2 zope.event-6.2 zope.interface-8.5
In [2]:
!pip install interpretimport pandas as pdimport numpy as npimport warningsimport os# 彻底禁用 joblib 多进程(解决 Python 3.13 兼容问题)os.environ["JOBLIB_MULTIPROCESSING"] = "0"os.environ["LOKY_MAX_CPU_COUNT"] = "1"warnings.filterwarnings('ignore')from sklearn.preprocessing import MinMaxScaler, StandardScaler, QuantileTransformer, RobustScaler, PowerTransformerfrom sklearn.model_selection import StratifiedKFold, cross_validatefrom sklearn.linear_model import LogisticRegressionfrom sklearn.ensemble import RandomForestClassifierfrom sklearn.tree import DecisionTreeClassifierfrom xgboost import XGBClassifierfrom interpret.glassbox import ExplainableBoostingClassifier# ======================== 1. 数据加载 ========================print("="*60)print("1. 加载数据")script_dir = os.path.dirname(os.path.abspath(__file__))file_path = '/kaggle/input/datasets/songsammy/final-data-27223106/creditcard.csv'df = pd.read_csv(file_path)print(f"数据形状: {df.shape}")print(f"类别分布:\n{df['Class'].value_counts()}")print(f"欺诈比例: {df['Class'].mean():.6f}")X = df.drop('Class', axis=1)y = df['Class']# ======================== 2. 定义Scaler及最佳顺序 ========================scalers = { 'minmax': MinMaxScaler(feature_range=(0, 1)), 'standard': StandardScaler(), 'quantile': QuantileTransformer(n_quantiles=1000, output_distribution='normal'), 'robust': RobustScaler(quantile_range=(25.0, 75.0)), 'power': PowerTransformer(method='yeo-johnson')}best_seq = ('quantile', 'robust', 'power', 'minmax', 'standard')print(f"\n使用已知最优Scaler顺序: {best_seq}")def apply_scaler_sequence_full(scalers_dict, sequence, X_full): X_temp = X_full.copy() for name in sequence: scaler = scalers_dict[name] X_temp = pd.DataFrame(scaler.fit_transform(X_temp), columns=X_temp.columns) return X_tempX_best = apply_scaler_sequence_full(scalers, best_seq, X)print(f"数据已按最佳顺序变换,新形状: {X_best.shape}")# ======================== 3. 已知最优超参数 ========================best_params = { 'interactions': 10, 'max_bins': 256, 'learning_rate': 0.05, 'max_rounds': 1000}print(f"\n使用已知最优EBM超参数: {best_params}")# ======================== 4. 模型对比(全部特征) ========================print("\n" + "="*60)print("4. 模型性能对比(全部特征,5折交叉验证)")cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)def get_model(name): if name == 'LogisticRegression': return LogisticRegression(C=1, penalty='l2', class_weight={0:1, 1:10}, solver='saga', max_iter=1000) elif name == 'RandomForest': return RandomForestClassifier(max_depth=10, n_estimators=200, class_weight=None, max_features='sqrt', random_state=42) elif name == 'DecisionTree': return DecisionTreeClassifier(max_depth=5, min_samples_split=50, min_samples_leaf=20, class_weight={0:1, 1:10}, random_state=42) elif name == 'XGBoost': return XGBClassifier(learning_rate=0.1, max_depth=3, scale_pos_weight=10, subsample=1.0, eval_metric='logloss', random_state=42, n_jobs=1) elif name == 'EBM': return ExplainableBoostingClassifier( interactions=best_params['interactions'], max_bins=best_params['max_bins'], learning_rate=best_params['learning_rate'], max_rounds=best_params['max_rounds'], random_state=42, n_jobs=1 )scoring = ['precision', 'recall', 'roc_auc', 'f1']model_names = ['LogisticRegression', 'RandomForest', 'DecisionTree', 'XGBoost', 'EBM']results_df = []for name in model_names: print(f"训练 {name} ...") model = get_model(name) scores = cross_validate(model, X_best, y, cv=cv, scoring=scoring, return_train_score=False, n_jobs=1) metrics = { 'Model': name, 'Precision': f"{scores['test_precision'].mean():.3f}", 'Recall': f"{scores['test_recall'].mean():.3f}", 'ROC-AUC': f"{scores['test_roc_auc'].mean():.3f}", 'F1 Score': f"{scores['test_f1'].mean():.3f}" } results_df.append(metrics) print(f" ROC-AUC: {metrics['ROC-AUC']}")print("\n模型性能对比表(5折交叉验证,全部特征):")print(pd.DataFrame(results_df).to_string(index=False))# ======================== 5. 特征重要性分析 ========================print("\n" + "="*60)print("5. EBM特征重要性分析及Top-K特征选择")final_ebm = get_model('EBM')final_ebm.fit(X_best, y)try: if hasattr(final_ebm, 'term_importances_'): term_importances = final_ebm.term_importances_ feature_importance = term_importances[:X_best.shape[1]] feature_names = X_best.columns else: imp_df = final_ebm.global_importance() feature_importance = imp_df['scores'].values[:X_best.shape[1]] feature_names = imp_df['names'].values[:X_best.shape[1]]except Exception as e: print(f"获取特征重要性时出错: {e}") if hasattr(final_ebm, 'term_importances') and callable(final_ebm.term_importances): term_importances = final_ebm.term_importances() feature_importance = term_importances[:X_best.shape[1]] feature_names = X_best.columns else: raiseimportance_df = pd.DataFrame({'feature': feature_names, 'importance': feature_importance})importance_df = importance_df.sort_values('importance', ascending=False)print("Top 20 特征重要性:")print(importance_df.head(20))top_n = 18top_features = importance_df.head(top_n)['feature'].tolist()X_top = X_best[top_features]print(f"选择前{top_n}个特征进行重新训练和评估")# ======================== 6. 使用Top特征重新评估模型 ========================print("\n" + "="*60)print("6. 使用Top 18特征重新评估所有模型")results_top = []for name in model_names: print(f"在Top特征上训练 {name} ...") model = get_model(name) scores = cross_validate(model, X_top, y, cv=cv, scoring=scoring, return_train_score=False, n_jobs=1) metrics = { 'Model': name, 'Precision': f"{scores['test_precision'].mean():.3f}", 'Recall': f"{scores['test_recall'].mean():.3f}", 'ROC-AUC': f"{scores['test_roc_auc'].mean():.3f}", 'F1 Score': f"{scores['test_f1'].mean():.3f}" } results_top.append(metrics)print("\n使用Top 18特征后的模型性能对比:")print(pd.DataFrame(results_top).to_string(index=False))# ======================== 7. 过拟合检测 ========================print("\n" + "="*60)print("7. 过拟合检测(EBM训练集 vs 测试集)")train_scores = cross_validate(final_ebm, X_best, y, cv=cv, scoring='roc_auc', return_train_score=True, n_jobs=1)train_auc = train_scores['train_score'].mean()test_auc = train_scores['test_score'].mean()gap = train_auc - test_aucprint(f"训练集平均ROC-AUC: {train_auc:.5f}")print(f"测试集平均ROC-AUC: {test_auc:.5f}")print(f"Train-Test Gap: {gap:.5f} ({gap*100:.2f}%)")if gap < 0.1: print("结论: 模型未过拟合,泛化良好")else: print("结论: 可能存在过拟合")print("\n" + "="*60)print("复现完成!")
/bin/bash: -c: line 1: syntax error near unexpected token `('
/bin/bash: -c: line 1: `pip install interpretimport pandas as pdimport numpy as npimport warningsimport os# 彻底禁用 joblib 多进程(解决 Python 3.13 兼容问题)os.environ["JOBLIB_MULTIPROCESSING"] = "0"os.environ["LOKY_MAX_CPU_COUNT"] = "1"warnings.filterwarnings('ignore')from sklearn.preprocessing import MinMaxScaler, StandardScaler, QuantileTransformer, RobustScaler, PowerTransformerfrom sklearn.model_selection import StratifiedKFold, cross_validatefrom sklearn.linear_model import LogisticRegressionfrom sklearn.ensemble import RandomForestClassifierfrom sklearn.tree import DecisionTreeClassifierfrom xgboost import XGBClassifierfrom interpret.glassbox import ExplainableBoostingClassifier# ======================== 1. 数据加载 ========================print("="*60)print("1. 加载数据")script_dir = os.path.dirname(os.path.abspath(__file__))file_path = '/kaggle/input/datasets/songsammy/final-data-27223106/creditcard.csv'df = pd.read_csv(file_path)print(f"数据形状: {df.shape}")print(f"类别分布:\n{df['Class'].value_counts()}")print(f"欺诈比例: {df['Class'].mean():.6f}")X = df.drop('Class', axis=1)y = df['Class']# ======================== 2. 定义Scaler及最佳顺序 ========================scalers = { 'minmax': MinMaxScaler(feature_range=(0, 1)), 'standard': StandardScaler(), 'quantile': QuantileTransformer(n_quantiles=1000, output_distribution='normal'), 'robust': RobustScaler(quantile_range=(25.0, 75.0)), 'power': PowerTransformer(method='yeo-johnson')}best_seq = ('quantile', 'robust', 'power', 'minmax', 'standard')print(f"\n使用已知最优Scaler顺序: {best_seq}")def apply_scaler_sequence_full(scalers_dict, sequence, X_full): X_temp = X_full.copy() for name in sequence: scaler = scalers_dict[name] X_temp = pd.DataFrame(scaler.fit_transform(X_temp), columns=X_temp.columns) return X_tempX_best = apply_scaler_sequence_full(scalers, best_seq, X)print(f"数据已按最佳顺序变换,新形状: {X_best.shape}")# ======================== 3. 已知最优超参数 ========================best_params = { 'interactions': 10, 'max_bins': 256, 'learning_rate': 0.05, 'max_rounds': 1000}print(f"\n使用已知最优EBM超参数: {best_params}")# ======================== 4. 模型对比(全部特征) ========================print("\n" + "="*60)print("4. 模型性能对比(全部特征,5折交叉验证)")cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)def get_model(name): if name == 'LogisticRegression': return LogisticRegression(C=1, penalty='l2', class_weight={0:1, 1:10}, solver='saga', max_iter=1000) elif name == 'RandomForest': return RandomForestClassifier(max_depth=10, n_estimators=200, class_weight=None, max_features='sqrt', random_state=42) elif name == 'DecisionTree': return DecisionTreeClassifier(max_depth=5, min_samples_split=50, min_samples_leaf=20, class_weight={0:1, 1:10}, random_state=42) elif name == 'XGBoost': return XGBClassifier(learning_rate=0.1, max_depth=3, scale_pos_weight=10, subsample=1.0, eval_metric='logloss', random_state=42, n_jobs=1) elif name == 'EBM': return ExplainableBoostingClassifier( interactions=best_params['interactions'], max_bins=best_params['max_bins'], learning_rate=best_params['learning_rate'], max_rounds=best_params['max_rounds'], random_state=42, n_jobs=1 )scoring = ['precision', 'recall', 'roc_auc', 'f1']model_names = ['LogisticRegression', 'RandomForest', 'DecisionTree', 'XGBoost', 'EBM']results_df = []for name in model_names: print(f"训练 {name} ...") model = get_model(name) scores = cross_validate(model, X_best, y, cv=cv, scoring=scoring, return_train_score=False, n_jobs=1) metrics = { 'Model': name, 'Precision': f"{scores['test_precision'].mean():.3f}", 'Recall': f"{scores['test_recall'].mean():.3f}", 'ROC-AUC': f"{scores['test_roc_auc'].mean():.3f}", 'F1 Score': f"{scores['test_f1'].mean():.3f}" } results_df.append(metrics) print(f" ROC-AUC: {metrics['ROC-AUC']}")print("\n模型性能对比表(5折交叉验证,全部特征):")print(pd.DataFrame(results_df).to_string(index=False))# ======================== 5. 特征重要性分析 ========================print("\n" + "="*60)print("5. EBM特征重要性分析及Top-K特征选择")final_ebm = get_model('EBM')final_ebm.fit(X_best, y)try: if hasattr(final_ebm, 'term_importances_'): term_importances = final_ebm.term_importances_ feature_importance = term_importances[:X_best.shape[1]] feature_names = X_best.columns else: imp_df = final_ebm.global_importance() feature_importance = imp_df['scores'].values[:X_best.shape[1]] feature_names = imp_df['names'].values[:X_best.shape[1]]except Exception as e: print(f"获取特征重要性时出错: {e}") if hasattr(final_ebm, 'term_importances') and callable(final_ebm.term_importances): term_importances = final_ebm.term_importances() feature_importance = term_importances[:X_best.shape[1]] feature_names = X_best.columns else: raiseimportance_df = pd.DataFrame({'feature': feature_names, 'importance': feature_importance})importance_df = importance_df.sort_values('importance', ascending=False)print("Top 20 特征重要性:")print(importance_df.head(20))top_n = 18top_features = importance_df.head(top_n)['feature'].tolist()X_top = X_best[top_features]print(f"选择前{top_n}个特征进行重新训练和评估")# ======================== 6. 使用Top特征重新评估模型 ========================print("\n" + "="*60)print("6. 使用Top 18特征重新评估所有模型")results_top = []for name in model_names: print(f"在Top特征上训练 {name} ...") model = get_model(name) scores = cross_validate(model, X_top, y, cv=cv, scoring=scoring, return_train_score=False, n_jobs=1) metrics = { 'Model': name, 'Precision': f"{scores['test_precision'].mean():.3f}", 'Recall': f"{scores['test_recall'].mean():.3f}", 'ROC-AUC': f"{scores['test_roc_auc'].mean():.3f}", 'F1 Score': f"{scores['test_f1'].mean():.3f}" } results_top.append(metrics)print("\n使用Top 18特征后的模型性能对比:")print(pd.DataFrame(results_top).to_string(index=False))# ======================== 7. 过拟合检测 ========================print("\n" + "="*60)print("7. 过拟合检测(EBM训练集 vs 测试集)")train_scores = cross_validate(final_ebm, X_best, y, cv=cv, scoring='roc_auc', return_train_score=True, n_jobs=1)train_auc = train_scores['train_score'].mean()test_auc = train_scores['test_score'].mean()gap = train_auc - test_aucprint(f"训练集平均ROC-AUC: {train_auc:.5f}")print(f"测试集平均ROC-AUC: {test_auc:.5f}")print(f"Train-Test Gap: {gap:.5f} ({gap*100:.2f}%)")if gap < 0.1: print("结论: 模型未过拟合,泛化良好")else: print("结论: 可能存在过拟合")print("\n" + "="*60)print("复现完成!")'