py-geodetector
A simple and efficient Python package for the Geographical Detector (GeoDetector).
Features
- Four Detectors: Factor, Interaction, Risk, and Ecological detectors.
- High Performance: Vectorized calculations using Pandas and NumPy for large-scale datasets.
- Flexible API: Supports both batch processing and interactive exploratory analysis.
- Auto Detection: Automatically identifies discrete/categorical variables as factors.
- Visualization: Built-in heatmap for interaction results with statistical significance markers.
Install
pip install py-geodetector
Usage
1. Data Preparation
- Format: pandas DataFrame.
- Y (Dependent Variable): Numerical/Continuous.
- X (Independent Variable): Categorical/Discrete. If your $X$ is continuous, you must discretize it first (e.g., using
pd.qcutor Jenks natural breaks).
2. Quick Start
from geodetector import load_example_data, GeoDetector
# Load example disease dataset
df = load_example_data()
# Initialize: Automatically detects discrete columns as factors if 'factors' is not provided
gd = GeoDetector(df, y='incidence')
print(f"Detected factors: {gd.factors}")
# 1. Factor Detector
# Batch detection for all factors
factor_df = gd.factor_detector()
# Single factor detection: returns (q_value, p_value)
q, p = gd.factor_detector('type')
# 2. Interaction Detector
# Full matrix calculation
interaction_df = gd.interaction_detector()
# Pairwise detection with relationship description
q_inter, relationship = gd.interaction_detector('type', 'region', relationship=True)
# 3. Ecological Detector
# Determine if the impact of two factors are significantly different
eco_df = gd.ecological_detector()
# 4. Risk Detector
# Compare average Y between sub-groups of a factor
risk_result = gd.risk_detector('type')
print(risk_result['risk']) # Mean values for each stratum
# 5. Visualization
# Plot interaction heatmap (red markers indicate significant ecological difference)
gd.plot(factors=['type', 'region', 'level'])
3. Visualization Result
The plot() method generates a heatmap of the interaction $q$-statistics. Red text indicates that the ecological detector shows a significant difference ($p < 0.05$) between those factors.
References
@article{wang2010geographical,
title={Geographical detectors-based health risk assessment and its application in the neural tube defects study of the Heshun Region, China},
author={Wang, Jin-Feng and Li, Xin-Hu and Christakos, George and Liao, Yi-Lan and Zhang, Tin and Gu, Xue and Zheng, Xiao-Ying},
journal={International Journal of Geographical Information Science},
volume={24},
number={1},
pages={107-127},
year={2010},
publisher={Taylor \& Francis}
}
Metadata
Release files for py-geodetector 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| py_geodetector-0.2.1.tar.gz | 6.8 kB | Without provenance | Details for py_geodetector-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py_geodetector-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for py_geodetector-0.2.1-py3-none-any.whl |
Total release size: 14.2 kB
Release files / py_geodetector-0.2.1.tar.gz
| Download URL | py_geodetector-0.2.1.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1fa5f00fdc29ba31a50413a9949ff9f393f23563e0a30e83a78cb5c88d5a7f08
|
|
BLAKE2b-256 checksum How to use checksums |
137a679172849602a63313c6047771d51b18b3d4bd694360f0f49a921207dc8a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / py_geodetector-0.2.1-py3-none-any.whl
| Download URL | py_geodetector-0.2.1-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f8398417cab723c0608d43b9a4a1585f544a7c73566b0228d9298bfe1418836a
|
|
BLAKE2b-256 checksum How to use checksums |
58a07147f5886022449c1abd4b239a3e310f916d3f81e0028544e5cf01ba2f16
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for py-geodetector 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.