Skip to main content

A python package implementing Shapley FDA value

Project description

SurvLIMEpy

This is a very initial implementation of Functional relevance based on the continuous Shapley value. There is still a lot of work to do.

Install

SurvLIMEpy can be installed from PyPI:

pip install ShapleyFDA

How to use

import numpy as np
from shapley_fda import ShapleyFda
from matplotlib import pyplot as plt

# Generate and visualise the data
step = 0.01
sample_size = 500
intercept = 0
slope = 1
abscissa_points = np.arange(0, 1 + step, step)
total_abscissa_points = abscissa_points.shape[0]
if total_abscissa_points % 2 == 0:
    middle_point = total_abscissa_points/2
else:
    middle_point = (total_abscissa_points + 1)//2
# Generate normal observations
np.random.seed(1234)
data = np.random.normal(
    size=(sample_size, total_abscissa_points),
    loc=0,
    scale=1
)
data = np.divide(data, np.sqrt(total_abscissa_points))
brownian = np.cumsum(data, axis=1)
trend = np.reshape(
    np.add(intercept, np.multiply(slope, abscissa_points)),
    newshape=(1, -1)
)
col_vector_ones_sample_size = np.ones(shape=(sample_size, 1))
trend_matrix = np.matmul(
    col_vector_ones_sample_size,
    trend
)
brownian_trend = np.add(brownian, trend_matrix)
_ = plt.plot(abscissa_points, brownian_trend.T)

def pred_fn(X):
    result = np.abs(X[:, middle_point])
    return result
target = pred_fn(brownian_trend)

# Use ShapleyFDA library
num_intervals = 10
num_permutations = 100
shapley_fda = ShapleyFda(
    X=brownian_trend,
    abscissa_points=abscissa_points,
    target=target,
    domain_range=(0, 1),
    verbose=False,
)
shapley_value = shapley_fda.compute_shapley_value(
    num_permutations=num_permutations,
    predict_fns=pred_fn,
    num_intervals=num_intervals,
    compute_mrmr_r2=False,
    compute_mrmr_distance_correlation=False,
)

Citations

Please if you use this package, do not forget to cite us:

@misc{delicado2024functionalrelevancebasedcontinuous,
    title={Functional relevance based on the continuous Shapley value}, 
    author={Pedro Delicado and Cristian Pachón-García},
    year={2024},
    eprint={2411.18575},
    archivePrefix={arXiv},
    primaryClass={stat.ML},
    url={https://arxiv.org/abs/2411.18575}, 
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shapleyfda-0.0.1.tar.gz (47.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ShapleyFDA-0.0.1-py3-none-any.whl (34.8 kB view details)

Uploaded Python 3

File details

Details for the file shapleyfda-0.0.1.tar.gz.

File metadata

  • Download URL: shapleyfda-0.0.1.tar.gz
  • Upload date:
  • Size: 47.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for shapleyfda-0.0.1.tar.gz
Algorithm Hash digest
SHA256 7beba8d5a478ddfa89e3c74b63714df0072a65525e76c903045604c096255d79
MD5 48bb124baef29d71ca1d45b02f142369
BLAKE2b-256 9e1dc32a4b7d4e22e937b8f72af6fb995fdffcd6322dbbbd76c0e6a436ed1354

See more details on using hashes here.

File details

Details for the file ShapleyFDA-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: ShapleyFDA-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 34.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for ShapleyFDA-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5cf2d8d9d4215c56ecd2e4c47b095dcde22cb8da80d67fdbb5240a509c4416c9
MD5 a9a093de42c8d3676470a3774e557feb
BLAKE2b-256 573318a3ceb3927db0f2ea53ed29e1eb5f37932b0bd7c02e9306a0f2729a112e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page