A python package implementing Shapley FDA value
Project description
ShyapleyFDA
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
ShapleyFDA 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,
)
# Plot the Shapley value function
shapley_fda.plot()
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
Release history Release notifications | RSS feed
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.2.tar.gz
(47.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shapleyfda-0.0.2.tar.gz.
File metadata
- Download URL: shapleyfda-0.0.2.tar.gz
- Upload date:
- Size: 47.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4838cb66fe7f8fabc095e16f205d352e2388ad9d5ce48e402c8eae74482f5fca
|
|
| MD5 |
c21cc149dbc044ab81037b768ed41fc7
|
|
| BLAKE2b-256 |
fb5d1526b9697a8c94d0a510d2d284de0439e0b35108f8c3e83450673fdbbf45
|
File details
Details for the file ShapleyFDA-0.0.2-py3-none-any.whl.
File metadata
- Download URL: ShapleyFDA-0.0.2-py3-none-any.whl
- Upload date:
- Size: 34.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aacb85efbfed451959367716a2b89495a4614c8568829708bb64358727da0d31
|
|
| MD5 |
338f24b5c943fb76347d5fe138ad5450
|
|
| BLAKE2b-256 |
cba3794c0dc07608ea3a34d1ec647ff73f5dbba1d2bcc2a55661f9640a0cf233
|