pymgcv: Generalized additive models using mgcv, in Python.
Project description
pymgcv: Generalized Additive Models in Python
pymgcv provides a Pythonic interface to R's powerful mgcv library for fitting Generalized Additive Models (GAMs). It combines the flexibility and statistical rigor of mgcv with the convenience of Python's data science ecosystem.
Currently in development. As this is a multilanguage project (R and Python), we use
pixi, a package management tool which supports this (via
conda). For development, the pymgcv can be installed by installing
pixi and running:
git clone https://github.com/danielward27/pymgcv.git
cd pymgcv
pixi shell --environment=dev
Installation options
Installing the python package only includes the python package and dependencies. This means an R installation with mgcv is also required.
Conda and pixi provide two convenient options for handling both Python and R dependencies:
Using conda:
conda create --name my_env python r-base r-mgcv
conda activate my_env
uv pip install pymgcv
Using pixi:
- Install pixi
pixi init
pixi add python r-base r-mgcv
pixi add --pypi pymgcv
pixi shell
Using either method the below example should now run e.g. in the terminal after running python,
or in an IDE after selecting the pixi/conda environment.
Simple example
import pandas as pd
import numpy as np
from pymgcv.gam import GAM
from pymgcv.terms import S, T, L
from pymgcv.plot import plot_gam
import matplotlib.pyplot as plt
# Generate sample data with non-linear relationship
np.random.seed(42)
n = 100
x0 = np.random.uniform(-1, 1, n)
x1 = np.random.uniform(-1, 1, n)
y = 0.5 * x0 + np.sin(np.pi * x1) + np.random.normal(0, 0.5, n)
data = pd.DataFrame({'x0': x0, 'x1': x1, 'y': y})
# Define model: linear effect of x0, smooth function of x1
model = GAM({'y': L('x0') + S('x1')})
# Fit the model
model = model.fit(data)
plot_gam(fit=model, residuals=True)
plt.show()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pymgcv-0.0.1.tar.gz.
File metadata
- Download URL: pymgcv-0.0.1.tar.gz
- Upload date:
- Size: 348.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40ff93bfa458379519f1000a9b294e7c2163d8dcb03bb4013e15714c1754fab6
|
|
| MD5 |
bf994ce4ea3fa6d5aed18c371bf64080
|
|
| BLAKE2b-256 |
2ab25df083ca45e2bf9694efdf06011ed37aeab870000c1cb7c71f69730df0ed
|
Provenance
The following attestation bundles were made for pymgcv-0.0.1.tar.gz:
Publisher:
publish.yml on danielward27/pymgcv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pymgcv-0.0.1.tar.gz -
Subject digest:
40ff93bfa458379519f1000a9b294e7c2163d8dcb03bb4013e15714c1754fab6 - Sigstore transparency entry: 265489924
- Sigstore integration time:
-
Permalink:
danielward27/pymgcv@3fcf9e5fa9f2c7815f0f12bed37766f8e5fb98b1 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/danielward27
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3fcf9e5fa9f2c7815f0f12bed37766f8e5fb98b1 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pymgcv-0.0.1-py3-none-any.whl.
File metadata
- Download URL: pymgcv-0.0.1-py3-none-any.whl
- Upload date:
- Size: 50.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6131c712a07b45b64e9c2906c17c63e4512413ba5fb0f3c0f41f9a8c09a8050
|
|
| MD5 |
8839577db4030dcc3fc3516ac4a75f4f
|
|
| BLAKE2b-256 |
96a7791ed430a1f186148236d98a414d1213e19d76876ba3fa071d3bae8f26f5
|
Provenance
The following attestation bundles were made for pymgcv-0.0.1-py3-none-any.whl:
Publisher:
publish.yml on danielward27/pymgcv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pymgcv-0.0.1-py3-none-any.whl -
Subject digest:
b6131c712a07b45b64e9c2906c17c63e4512413ba5fb0f3c0f41f9a8c09a8050 - Sigstore transparency entry: 265489927
- Sigstore integration time:
-
Permalink:
danielward27/pymgcv@3fcf9e5fa9f2c7815f0f12bed37766f8e5fb98b1 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/danielward27
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3fcf9e5fa9f2c7815f0f12bed37766f8e5fb98b1 -
Trigger Event:
release
-
Statement type: