Skip to main content

A package implementing fast generalized additive models

Project description

Fastgam

Fastgam is a Python package for constructing fast additive models.

Installation

You can install the package via pip:

pip install fastgam

Minimal example

In this example, we try to learn an additive model with $d = 5$ effects, with a regularity $s = 2$. The data satisfies

  • $Y = f(X_1, \dots, X_5) + \varepsilon$,
  • $f(x_1, \dots, x_5) = \sum_{j=1}^5 (\exp(x_j/(j+1))-1)$,
  • $\varepsilon \sim \mathcal N(0, 1)$.
import numpy as np
from fastgam import FastGAM

d = 5
s = 2
N = 10**2
N_val = 1000

lambda_N_list = [10**(-i/3) for i in range(10)]

x_train = np.random.uniform(size=(d, N))
f_train = np.zeros(N)
for i in range(d):
    f_train += np.exp(x_train[i]/(i+1)) - 1
y_train =  (f_train + np.random.normal(size=N)).astype(np.complex128)

x_val = np.random.uniform(size=(d, N_val))
f_val = np.zeros(N_val)
for i in range(d):
    f_val += np.exp(x_val[i]/(i+1)) - 1
y_val =  (f_val + np.random.normal(size=N_val)).astype(np.complex128)


lambda_n=N**(-(2*s)/(2*s+1))
m = 1+ int(N**(1/(2*s+1))/d)
threshold = lambda_n/10

model = FastGAM(d)
model.fit_grid(x_train, y_train, x_val, y_val,lambda_N_list, m, threshold)

N_test = 10**4
x_test = np.random.uniform(size=(d, N_test))
f_test = np.zeros(N_test)

for i in range(d):
    f_test += np.exp(x_test[i]/(i+1)) - 1
y_test =  f_test.astype(np.complex128)

model.predict(x_test)
model.mse(y_test)

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

fastgam-1.0.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

fastgam-1.0.2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file fastgam-1.0.2.tar.gz.

File metadata

  • Download URL: fastgam-1.0.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fastgam-1.0.2.tar.gz
Algorithm Hash digest
SHA256 2583fbbdb87bf3e4efa45b6b93bd8decf85f1e55907cba4ab52db45f65d3eb51
MD5 0ec1ffcf5b38cef412faff95f2cd8c40
BLAKE2b-256 a90f96eea77b83d64ed8000bf0a53f8559d6ba83b6d71923fbba6676fe8bc149

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastgam-1.0.2.tar.gz:

Publisher: publish.yml on NathanDoumeche/fastgam

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastgam-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: fastgam-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fastgam-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 16aae27c7360be8847cf55e65b074316f4fd266ac9f1b591ead2a22cd5c9100c
MD5 f86402d10cdaafc7efec42b6f301fc4a
BLAKE2b-256 1ed16451ae54a91a3ffa0a611a0de8144bb5edaae72f7538b2158928e6c9f40d

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastgam-1.0.2-py3-none-any.whl:

Publisher: publish.yml on NathanDoumeche/fastgam

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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