Skip to main content

PyLWL: A Python Framework for Locally Weighted Learning

Project description

PyLWL: A Python Framework for Locally Weighted Learning

GitHub release PyPI version PyPI - Python Version PyPI - Downloads Downloads Tests & Publishes to PyPI Documentation Status Chat DOI License: GPL v3


📌 Overview

PyLWL is an open-source Python library that provides a unified, extensible, and user-friendly implementation of Locally Weighted Learning (LWL) algorithms for supervised learning. It implements differentiable and gradient-descent-based local models for both classification and regression tasks.

Features

  • 📌 GdLwClassifier: Local weighted classifier using logistic regression with support for binary and multiclass classification.
  • 📌 GdLwRegressor: Local weighted regressor using linear regression optimized with MSE loss.
  • 📌 LwClassifier and LwRegressor: Local weighted classifier/regressor with a fixed kernel.
  • 🧠 Supports any differentiable kernel function (e.g., Gaussian, Epanechnikov).
  • ⚙️ Built with PyTorch, and fully compatible with Scikit-Learn pipeline and metrics.
  • 🔧 Configurable optimizer (Adam, SGD, etc.) and hyperparameters.
  • 🔍 Built-in support for model evaluation and scoring.

📦 Installation

You can install the library using pip (once published to PyPI):

pip install pylwl

After installation, you can import PyLWL as any other Python module:

$ python
>>> import pylwl
>>> pylwl.__version__

🚀 Quick Start

Classification

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from pylwl import LwClassifier

# Load data
X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)

# Train LVQ1 model
model = LwClassifier(kernel="gaussian", tau=1.0)
model.fit(X_train, y_train)

# Evaluate
y_pred = model.predict(X_test)
print("Accuracy:", model.score(X_test, y_test))

Regression

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
from pylwl import LwRegressor

X, y = fetch_california_housing(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)

reg = LwRegressor(kernel='gaussian', tau=1.0)
reg.fit(X_train, y_train)
print("R2 score:", reg.score(X_test, y_test))

Please read the examples folder for more use cases.

📚 Documentation

Documentation is available at: 👉 https://pylwl.readthedocs.io

You can build the documentation locally:

cd docs
make html

🧪 Testing

You can run unit tests using:

pytest tests/

🤝 Contributing

We welcome contributions to PyLWL! If you have suggestions, improvements, or bug fixes, feel free to fork the repository, create a pull request, or open an issue.

📄 License

This project is licensed under the GPLv3 License. See the LICENSE file for more details.

Citation Request

Please include these citations if you plan to use this library:

@software{thieu20250517PyLWL,
  author       = {Nguyen Van Thieu},
  title        = {PyLWL: A Python Framework for Locally Weighted Learning},
  month        = may,
  year         = 2025,
  doi         = {10.6084/m9.figshare.29089784},
  url          = {https://github.com/thieu1995/PyLWL}
}

Official Links


Developed by: Thieu @ 2025

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

pylwl-0.1.0.tar.gz (34.8 kB view details)

Uploaded Source

Built Distribution

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

pylwl-0.1.0-py3-none-any.whl (33.2 kB view details)

Uploaded Python 3

File details

Details for the file pylwl-0.1.0.tar.gz.

File metadata

  • Download URL: pylwl-0.1.0.tar.gz
  • Upload date:
  • Size: 34.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pylwl-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7a79db8383b43a6c4f8eebff2e52fc58602dffdfb54ef81554dca117f8db0ce5
MD5 7bd394272d05cf98713a02e464969183
BLAKE2b-256 c12308c43a14bc5f7240b1087676d3e154c48d5e7f70ccb717f43c90a3c6fb79

See more details on using hashes here.

File details

Details for the file pylwl-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pylwl-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 33.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pylwl-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 47691bb5b459a951ba94317945bbd6b9a844cad62b0b003231e97ec8ef2c1246
MD5 8da6536850a4b14f13b9863a872aea2e
BLAKE2b-256 cc42ccbdf8b1c2f21a3d10a130651278f54ffabc17dcff032b6b0357dff58b9f

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