![](https://private-user-images.githubusercontent.com/5518908/287456641-b450b5b3-fd59-41d8-a64c-fb202f492302.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM0ODc0MjgsIm5iZiI6MTcyMzQ4NzEyOCwicGF0aCI6Ii81NTE4OTA4LzI4NzQ1NjY0MS1iNDUwYjViMy1mZDU5LTQxZDgtYTY0Yy1mYjIwMmY0OTIzMDIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgxMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MTJUMTgyNTI4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9OWE0ZmQ1ZmU3ZjhmZGNiN2ZiYjhmMTRkMWFmZWJlNDFlZjBiMmQxODcwZmJjMDFmNWU1MWIxMDU4NWYwMjg4OCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.RgtUmDjHviktHcZfXs-5ZdeIMZD3m_99OYYPXQyV-_Q)
A game theory approach to measuring spatial effects from machine learning models. GeoShapley is built on Shapley value and Kernel SHAP estimator.
GeoShapley can be installed from PyPI:
$ pip install geoshapley
GeoShapley can explain any model that takes data + coordiantes as the input. Currently, coordinates need to be put as the last two columns of your pandas.DataFrame
(X_geo
).
Below shows an example on how to explain a trained NN model.
from geoshapley import GeoShapleyExplainer
from sklearn.neural_network import MLPRegressor
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X_geo, y, random_state=1)
#Fit a NN model based on training data
mlp_model = MLPRegressor().fit(X_train, y_train)
#Specify a small background data
background = X_train.sample(100).values
#Initilize a GeoShapleyExplainer
mlp_explainer = GeoShapleyExplainer(mlp_model.predict, background)
#Explain the data
mlp_rslt = mlp_explainer.explain(X_geo)
#Make a shap-style summary plot
mlp_rslt.summary_plot()
#Make partial dependence plots of the primary (non-spatial) effects
mlp_rslt.partial_dependence_plots()
#Calculate spatially varying explanations
mlp_svc = mlp_rslt.get_svc()
Li, Z. (2023). GeoShapley: A Game Theory Approach to Measuring Spatial Effects in Machine Learning Models. arXiv preprint https://doi.org/10.48550/arXiv.2312.03675