Skip to main content

Actions PythonVersion PyPi Black ReadtheDocs

generalized-additive-models

Generalized Additive Models (GAMs) in Python.

About

GAMs are uniquely placed on the interpretability vs. precitive power continuum. In many applications they perform almost as well as more complex models, but are extremely interpretable.

  • GAMs extend linear regression by allowing non-linear relationships between features and the target.

  • The model is still additive, but link functions and multivariate splines facilitate a broad class of models.

  • While GAMs are likely outperformed by non-additive models (e.g. boosted trees), GAMs are extremely interpretable.

Read more about GAMs:

A GAM is a statistical model in which the target variable depends on unknown smooth functions of the features, and interest focuses on inference about these smooth functions.

An exponential family distribution is specified for the target Y (.e.g Normal, Binomial or Poisson) along with a link function g (for example the identity or log functions) relating the expected value of Y to the predictor variables.

Installation

Install using pip:

pip install generalized-additive-models

Example

from sklearn.datasets import load_diabetes
from sklearn.model_selection import cross_val_score
from generalized_additive_models import GAM, Spline, Categorical

# Load data
data = load_diabetes(as_frame=True)
df, y = data.data, data.target

# Create model
terms = Spline("bp") + Spline("bmi", constraint="increasing") + Categorical("sex")
gam = GAM(terms)

# Cross validate
scores = cross_val_score(gam, df, y, scoring="r2")
print(scores) # array([0.26, 0.4 , 0.41, 0.35, 0.42])

Go to Read the Docs to see full documentation.

Contributing and development

Contributions are very welcome. You can correct spelling mistakes, write documentation, clean up code, implement new features, etc.

Some guidelines for development:

  • Code must comply with the standard. See the GitHub action pipeline for more information.

  • If possible, use existing algorithms from numpy, scipy and scikit-learn.

  • Write tests, especically regression tests if a bug is fixed.

  • Take backward compatibility seriously. API changes require good reason.

Installation for local development:

pip install -e '.[dev,lint,doc]'

Create documentation locally:

sudo apt install pandoc
sphinx-build docs _built_docs/html -W -a -E --keep-going
sphinx-autobuild docs _built_docs/html -v -j "auto" --watch generalized_additive_models

Once the version has been incremented, the commit must be tagged and pushed in order to publish to PyPi:

git tag -a v0.1.0 -m "Version 0.1.0" b22724c
git push origin v0.1.0

Citing

TODO

Metadata

Release files for generalized-additive-models 0.4.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for generalized-additive-models 0.4.3
File Size Uploaded
generalized_additive_models-0.4.3.tar.gz 296.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for generalized-additive-models 0.4.3
File Interpreter ABI Platform
generalized_additive_models-0.4.3-py3-none-any.whl Python 3 none any Details

Total release size: 614.3 kB

Release files / generalized_additive_models-0.4.3.tar.gz

Download URL generalized_additive_models-0.4.3.tar.gz
Size 296.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5e0a83ec0f1a8002642cd7de7a333430fd947679c552c94f9192410cc7ab5588
BLAKE2b-256 checksum
How to use checksums
8f430dbe10747287d0b565169d99d55179243c8a92f6037b01c240c6810345a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / generalized_additive_models-0.4.3-py3-none-any.whl

Download URL generalized_additive_models-0.4.3-py3-none-any.whl
Size 318.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b40695403ebebc8370da4e4e8b16d45dbed02a47c97b5fe7a2e53fb451b08fcc
BLAKE2b-256 checksum
How to use checksums
c3a73c97c5e2adba35b7c66539ca2df2bfc9b568c6bc7abbe9e7e8431ffb67c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.4.3 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page