Skip to main content

Generalized additive models in Python.

Project description

Actions PythonVersion PyPi Black



Generalized Additive Models (GAM) are the Predictive Modeling Silver Bullet. 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.;sim&space;textup{ExponentialFamily}(mu_i,&space;phi)&space;\g(mu_i)&space;=&space;f_1(x_{i1})&space;+&space;f_2(x_{i2})&space;+&space;f_3(x_{i3},&space;x_{i4})&space;+&space;cdots

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.


Install using pip:

pip install generalized-additive-models


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 =,

# 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])


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

Some guidelines:

  • 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.



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

generalized_additive_models-0.0.0.tar.gz (37.2 kB view hashes)

Uploaded Source

Built Distribution

generalized_additive_models-0.0.0-py3-none-any.whl (41.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page