Skip to main content

Utilities for fitting GLMs.

Project description

GLM utilities

Installation

conda install scikit-learn
pip install git+http://github.com/janclemenslab/glm_utils

Usage

Check out the wiki.

Example code

from tempfile import TemporaryDirectory

from sklearn.linear_model import BayesianRidge
from sklearn.preprocessing import FunctionTransformer, PolynomialFeatures
from sklearn.pipeline import Pipeline

from glm_utils.preprocessing import time_delay_embedding

# Generate dummy data.
x = np.random.random((1000, 1))
y = np.random.random((1000,))

# Manipulations regarding X *and* y
X, y = time_delay_embedding(x, y, window_size=100)

# Transformations that only change X are included in the pipeline.
steps = [('quad_exp', PolynomialFeatures(degree=2, interaction_only=False, include_bias=True)),
         ('ridge', BayesianRidge())]

with TemporaryDirectory() as tempdir:
    model = Pipeline(steps, memory=tempdir)
    model.fit(X, y)
    y_pred, y_pred_std = model.predict(X, return_std=True)
    print(f'r2={model.score(X, y):1.2}')

Notes

Processing steps that require manipulations of X and y - such as time delay embedding, balancing, test-train split - are currently not supported by sklearn pipelines (see here). These steps should be performed before the pipeline using functions that implement the following signature: X, y = func(X, y=None, **kwargs)

Processing steps that only affect X - feature normalization or scaling, basis function projections, PCA, polynomial expansions - should be included in the pipeline. Custom functions should follow this signature: X = func(X, **kwargs) and can be integrated into a pipeline with the FunctionTransformer. Alternatively, a custom class implementing the Transformer interface can be used. Custom classes have the advantage of providing access to parameters of the transform - e.g. the basis vectors used in a basis function projection.

Useful extensions

TODO:

need-to_haves:

  • make basis and project onto basis functions
  • reconstruct time-domain filter from basis functions and weights
  • balancing
  • add example code for standard pipelines

nice-to-haves:

  • deal with multi-feature fits (need to adjust basis functions and time delay embedding accordinly)
  • deal with subsets (avoid computations on data we don't use anyways)

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

glm-utils-0.4.tar.gz (2.6 MB view details)

Uploaded Source

Built Distribution

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

glm_utils-0.4-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file glm-utils-0.4.tar.gz.

File metadata

  • Download URL: glm-utils-0.4.tar.gz
  • Upload date:
  • Size: 2.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.23.0

File hashes

Hashes for glm-utils-0.4.tar.gz
Algorithm Hash digest
SHA256 98a02764287d06db32ffb0a42ccb3180a003e7f8d4721ed13ac91aca360b637e
MD5 d3b891bf7241720f610451113e25c9b3
BLAKE2b-256 7be4eb4b9577cc90692b92241e58099c25cdfbbbd07d3a6724aa607e7badd9ab

See more details on using hashes here.

File details

Details for the file glm_utils-0.4-py3-none-any.whl.

File metadata

  • Download URL: glm_utils-0.4-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.23.0

File hashes

Hashes for glm_utils-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e3a326b395915c8bf309c0f9fee2124fc843c1c72fe9c2ffcbcdff4d1f5b4e8a
MD5 0946981b03a2c0e087f890d4bfffe4d6
BLAKE2b-256 d887b4390fc47aa6c060b81f7abb591fdf14897eba4139e8d1bd38f81dd2069b

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