https://github.com/boyanangelov/exmap

exmap: Explainable Maps

https://github.com/boyanangelov/exmap

Science Score: 10.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: zenodo.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.8%) to scientific vocabulary

Keywords

machine-learning spatial-analysis
Last synced: 5 months ago · JSON representation

Repository

exmap: Explainable Maps

Basic Info
  • Host: GitHub
  • Owner: boyanangelov
  • License: mit
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 3.31 MB
Statistics
  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
machine-learning spatial-analysis
Created almost 7 years ago · Last pushed almost 7 years ago

https://github.com/boyanangelov/exmap/blob/master/

# Exmap

[![DOI](https://zenodo.org/badge/179990140.svg)](https://zenodo.org/badge/latestdoi/179990140)

## Description

Exmap is a Python package with allows users to generate maps based on an interpretable machine learning prediction. The current version of the package supports interpretation of the popular gradient boosting algorithm implementation [XGBoost](https://xgboost.readthedocs.io).

The interpretations under the hood are achieved by using [LIME](https://github.com/marcotcr/lime), and the maps are generated by using [Folium](https://github.com/python-visualization/folium) (a Python based wrapper for Leaflet.js).

Such maps help you dive deeper and explore more detailed patterns in your spatial datasets, which you would otherwise miss by just focusing on the model performance results. An individual observation might have the same predicted class or value as another one, but the results can be very different. We can use elections as a metaphor: people would vote for the same candidate, but for different reasons.

Below you can have a look at am example generated map (based on the 2016 US Elections):

![](screenshot.png)

## Installation instructions

After cloning the repository:

```bash
pip install .
```

## Generating a map

As a first step we need to train a machine learning classifier.

```python
from exmap import Exmap
import pandas as pd

voting_data = pd.read_csv("sample_data/voting_data.csv")
X = voting_data.drop('Clinton', axis=1)
y = voting_data['Clinton']
targets_limit = 10

X_test, test_coords, explainer, model = Exmap.train_model(features=X, target=y, task_type="clf")
```

After this we can compute the individual LIME explanations.

```python
explanations = Exmap.compute_lime_explanations(test_data=X_test, explainer=explainer, model=model, targets_limit=targets_limit, num_features=15, task_type="clf")
```

Then we can use those LIME explanations to create plots, stored in the `images` folder (make sure you have created this folder beforehand, otherwise you will get an error).

```python
Exmap.generate_lime_plots(explanations_list=explanations, image_prefix="voting")
```

And as a final step we use those static plots (as a `.png` format) as tooltips for the Folium map, which we export as `.html`.

```python
m = Exmap.make_map(test_coords=test_coords, targets_number=targets_limit)
m.save('voting_map.html')
```

In the end you can open this map in any browser and explore the results.

Owner

  • Name: Boyan Angelov
  • Login: boyanangelov
  • Kind: user
  • Location: Berlin, Germany

Data Strategist | Author | Researcher (Complexity, AI)

GitHub Events

Total
Last Year