Skip to main content

Geographically Weighted Machine Learning in Python

Project description

PyGWML (Geographically Weighted Machine Learning in Python)

Python 3 Based Implementation of Geographically Weighted Machine Learning Models such as:

  • GXGB (Geographically Weighted XGBoost).
  • GWMLP (Geographically Weighted Multi-layer Perceptrons).
  • GWRNN (Geographically Weighted RNN).

Installation

You can directly install it with the command:

$ pip install pygwml

Potential issues and solutions

  • Pygwml requires the pacakge esda as a dependency for computing Moran's Index. We recommend users to install esda 2.5, and then Pygwml can be used smoothly with any additional action. If you use the latest version of esda 2.6, you will need to install matplotlib manually in order to import Pygwml successfully.
  • Libpysal is used specifically for the Incremental Spatial Autocorrelation (ISA) analysis to help find the optimal spatial bandwidth (ISA_op_bw function). libpysal >= 4.4.0 is needed to be installed for this.

Example 1: Implementation GXGB Model

Below shows an example on how to fit a GXGB model and use it to make predictions.

from pygwml import GXGB
from sklearn.model_selection import train_test_split
from sklearn.metrics import r2_score

#Instantiate GXGB model with chosen parameters
model = GXGB(band_width=32, kernel="fixed", n_estimators=100, learning_rate=0.1)

#Fit model on training data
model.fit(X_train, y_train, coords_train)

#Predict on test data
local_weight = 0.5  # blend local and global predictions (adjust as needed)
y_pred, y_pred_global, y_pred_local = model.predict(X_test, coords_test, local_weight=local_weight)

#Evaluate performance
print("R2 score (combined):", r2_score(y_test, y_pred))
print("R2 score (global only):", r2_score(y_test, y_pred_global))
print("R2 score (local only):", r2_score(y_test, y_pred_local))

#(Optional) #Get Feature Importances
local_feature_importance=model.get_local_feature_importance()
local_feature_importance=model.global_model.feature_importances_
globally_enhanced_local_feature_importances=model.get_globally_enhanced_local_feature_importances()

Parameters

If you want to learn more about the major parameters in this package, please refer to the Description of Parameters(https://github.com/moin-t/PyGWML/Description_Parameters).

Authors

Project URL:

https://github.com/moin-t/PyGWML

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

pygwml-0.0.1.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

pygwml-0.0.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pygwml-0.0.1.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for pygwml-0.0.1.tar.gz
Algorithm Hash digest
SHA256 1c62fc133b9fb9bd643e65a420dc9872b55aa54961c1ed6e13bf302ca7142e3e
MD5 06bd5287cff4ed691dbc0a2c2ed13699
BLAKE2b-256 d494240721dac074592c094720efd3d4cbb059f02ca8bf4c06074c222cf167ff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygwml-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for pygwml-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 38c1a9a215632f875da6e96009373abd8a1f01f3641fba3a177d9ff562489b03
MD5 e896a3249ec86c702cbc5e0bebdbf51f
BLAKE2b-256 f689db1538124d690b8d0419a11848fe4243d373bae694adff894748afdbc045

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