Skip to main content

High performance Python GLMs with all the features!

Project description

glum

CI Daily runs Docs Conda-forge PypiVersion PythonVersion

Documentation

Generalized linear models (GLM) are a core statistical tool that include many common methods like least-squares regression, Poisson regression and logistic regression as special cases. At QuantCo, we have used GLMs in e-commerce pricing, insurance claims prediction and more. We have developed glum, a fast Python-first GLM library. The development was based on a fork of scikit-learn, so it has a scikit-learn-like API. We are thankful for the starting point provided by Christian Lorentzen in that PR!

The goal of glum is to be at least as feature-complete as existing GLM libraries like glmnet or h2o. It supports

  • Built-in cross validation for optimal regularization, efficiently exploiting a “regularization path”
  • L1 regularization, which produces sparse and easily interpretable solutions
  • L2 regularization, including variable matrix-valued (Tikhonov) penalties, which are useful in modeling correlated effects
  • Elastic net regularization
  • Normal, Poisson, logistic, gamma, and Tweedie distributions, plus varied and customizable link functions
  • Box constraints, linear inequality constraints, sample weights, offsets

This repo also includes tools for benchmarking GLM implementations in the glum_benchmarks module. For details on the benchmarking, see here. Although the performance of glum relative to glmnet and h2o depends on the specific problem, we find that when N >> K (there are more observations than predictors), it is consistently much faster for a wide range of problems.

Performance benchmarks Performance benchmarks

For more information on glum, including tutorials and API reference, please see the documentation.

Why did we choose the name glum? We wanted a name that had the letters GLM and wasn't easily confused with any existing implementation. And we thought glum sounded like a funny name (and not glum at all!). If you need a more professional sounding name, feel free to pronounce it as G-L-um. Or maybe it stands for "Generalized linear... ummm... modeling?"

A classic example predicting housing prices

>>> from sklearn.datasets import fetch_openml
>>> from glum import GeneralizedLinearRegressor
>>>
>>> # This dataset contains house sale prices for King County, which includes
>>> # Seattle. It includes homes sold between May 2014 and May 2015.
>>> house_data = fetch_openml(name="house_sales", version=3, as_frame=True)
>>>
>>> # Use only select features
>>> X = house_data.data[
...     [
...         "bedrooms",
...         "bathrooms",
...         "sqft_living",
...         "floors",
...         "waterfront",
...         "view",
...         "condition",
...         "grade",
...         "yr_built",
...         "yr_renovated",
...     ]
... ].copy()
>>>
>>>
>>> # Model whether a house had an above or below median price via a Binomial
>>> # distribution. We'll be doing L1-regularized logistic regression.
>>> price = house_data.target
>>> y = (price < price.median()).values.astype(int)
>>> model = GeneralizedLinearRegressor(
...     family='binomial',
...     l1_ratio=1.0,
...     alpha=0.001
... )
>>>
>>> _ = model.fit(X=X, y=y)
>>>
>>> # .report_diagnostics shows details about the steps taken by the iterative solver.
>>> diags = model.get_formatted_diagnostics(full_report=True)
>>> diags[['objective_fct']]
        objective_fct
n_iter               
0            0.693091
1            0.489500
2            0.449585
3            0.443681
4            0.443498
5            0.443497
>>>
>>> # Models can also be built with formulas from formulaic.
>>> model_formula = GeneralizedLinearRegressor(
...     family='binomial',
...     l1_ratio=1.0,
...     alpha=0.001,
...     formula="bedrooms + np.log(bathrooms + 1) + bs(sqft_living, 3) + C(waterfront)"
... )
>>> _ = model_formula.fit(X=house_data.data, y=y)

Installation

Please install the package through conda-forge:

conda install glum -c conda-forge

Performance

For optimal performance on an x86_64 architecture, we recommend using the MKL library (conda install mkl). By default, conda usually installs the openblas version, which is slower, but supported on all major architecture and OS.

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

glum-3.1.0.tar.gz (13.5 MB view details)

Uploaded Source

Built Distributions

glum-3.1.0-cp312-cp312-win_amd64.whl (540.2 kB view details)

Uploaded CPython 3.12 Windows x86-64

glum-3.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

glum-3.1.0-cp312-cp312-macosx_11_0_arm64.whl (690.5 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

glum-3.1.0-cp312-cp312-macosx_10_13_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.12 macOS 10.13+ x86-64

glum-3.1.0-cp311-cp311-win_amd64.whl (530.4 kB view details)

Uploaded CPython 3.11 Windows x86-64

glum-3.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

glum-3.1.0-cp311-cp311-macosx_11_0_arm64.whl (635.0 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

glum-3.1.0-cp311-cp311-macosx_10_13_x86_64.whl (973.6 kB view details)

Uploaded CPython 3.11 macOS 10.13+ x86-64

glum-3.1.0-cp310-cp310-win_amd64.whl (531.7 kB view details)

Uploaded CPython 3.10 Windows x86-64

glum-3.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

glum-3.1.0-cp310-cp310-macosx_11_0_arm64.whl (638.8 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

glum-3.1.0-cp310-cp310-macosx_10_13_x86_64.whl (977.6 kB view details)

Uploaded CPython 3.10 macOS 10.13+ x86-64

glum-3.1.0-cp39-cp39-win_amd64.whl (532.8 kB view details)

Uploaded CPython 3.9 Windows x86-64

glum-3.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

glum-3.1.0-cp39-cp39-macosx_11_0_arm64.whl (639.7 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

glum-3.1.0-cp39-cp39-macosx_10_13_x86_64.whl (978.6 kB view details)

Uploaded CPython 3.9 macOS 10.13+ x86-64

File details

Details for the file glum-3.1.0.tar.gz.

File metadata

  • Download URL: glum-3.1.0.tar.gz
  • Upload date:
  • Size: 13.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for glum-3.1.0.tar.gz
Algorithm Hash digest
SHA256 64d99f78578ae04ca5e6141c46f252398e710858826617a3dfc992433f00f197
MD5 16a5d88cf17ea73c90b5c4607b758a14
BLAKE2b-256 b2b9b348798328f760dac9b7a64326533668b2e3a54df5ef0bef7e4c19916e18

See more details on using hashes here.

Provenance

The following attestation bundles were made for glum-3.1.0.tar.gz:

Publisher: build_wheels.yml on Quantco/glum

Attestations:

File details

Details for the file glum-3.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: glum-3.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 540.2 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for glum-3.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9f3363cc36636f7b33c728de1ecaaa6bbcfe55516a91215c99faf0c16c5e8693
MD5 1151f3785c90666efc3444ff12589150
BLAKE2b-256 057a02b6452b1d1921f21cfaad319449a6b3d8eeaa1eaa8358feb58955e59c89

See more details on using hashes here.

Provenance

The following attestation bundles were made for glum-3.1.0-cp312-cp312-win_amd64.whl:

Publisher: build_wheels.yml on Quantco/glum

Attestations:

File details

Details for the file glum-3.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for glum-3.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9c634230bcfab062f1a2fe5313ba7f62c254b6706a0f9c354fe58e9a4edb933b
MD5 112154cff5fada386273bb4a0e961abc
BLAKE2b-256 128b197d8f95c5f5ee5570ee0880b0b54acd443b625b7854f4ea0a5966b57da3

See more details on using hashes here.

Provenance

The following attestation bundles were made for glum-3.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_wheels.yml on Quantco/glum

Attestations:

File details

Details for the file glum-3.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for glum-3.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1298f48edda80c14c8c0834f05f2e1bb67af3441bb41e1d246e4811b60b08680
MD5 bfd9abffe8ff044aaad804e25e549896
BLAKE2b-256 7b148b2cf4332ef011bc49cc2f3dccb334ac253d45a6a2a217672ca7d12726e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for glum-3.1.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: build_wheels.yml on Quantco/glum

Attestations:

File details

Details for the file glum-3.1.0-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for glum-3.1.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 7976f44dc7a552f992df4d63f752ec9ec2a704b6466b1f69cd7b18421b59df81
MD5 7068c57cca7b4a227790a457a96dc9dc
BLAKE2b-256 b48a16c105b137aa3ecb468d62935697f5b59518dc48c7588d910f45b14107e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for glum-3.1.0-cp312-cp312-macosx_10_13_x86_64.whl:

Publisher: build_wheels.yml on Quantco/glum

Attestations:

File details

Details for the file glum-3.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: glum-3.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 530.4 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for glum-3.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9b3c59539b1ec96adca4b04d3bdafaf9934d302141c57a068b1d2c2388bf70c1
MD5 a7577d0fd04f19eb68e24951744f583c
BLAKE2b-256 92b6f1d0700e88cac1ccf8711fd1147ec7d47d0eedb3ca0a273cda9570022d5f

See more details on using hashes here.

Provenance

The following attestation bundles were made for glum-3.1.0-cp311-cp311-win_amd64.whl:

Publisher: build_wheels.yml on Quantco/glum

Attestations:

File details

Details for the file glum-3.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for glum-3.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cc570c990c76fe6154b614f80242a7778a04cac084852268098b77db8ebd1bcf
MD5 a299be5240f7ccc9e5dd32c2cc24015b
BLAKE2b-256 8fa709b2f6e5f9d0505be470ba8a81bc05fc77de6756dd80166b8c57dd97fc76

See more details on using hashes here.

Provenance

The following attestation bundles were made for glum-3.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_wheels.yml on Quantco/glum

Attestations:

File details

Details for the file glum-3.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for glum-3.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1a6cc78a239e5c24ad65ec77ee7fc005d1300499b135353104a0b5f806385731
MD5 89e2254d5b868df0dda03f5158560102
BLAKE2b-256 7479156ae7911bcb2fcfee17a537c8b860f6bb450d7861e2f9aeeb490b9958cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for glum-3.1.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: build_wheels.yml on Quantco/glum

Attestations:

File details

Details for the file glum-3.1.0-cp311-cp311-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for glum-3.1.0-cp311-cp311-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 a335bbece43223d602b40faf0aa1a449f5bc715d9e13b9a99a89fb1dab3095a5
MD5 78760c8e521727568c609e6908837714
BLAKE2b-256 3e344e7a0e39bff4c6f6391508a6ba75cc5dd8a338cb83fc3a03aaa89d544b17

See more details on using hashes here.

Provenance

The following attestation bundles were made for glum-3.1.0-cp311-cp311-macosx_10_13_x86_64.whl:

Publisher: build_wheels.yml on Quantco/glum

Attestations:

File details

Details for the file glum-3.1.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: glum-3.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 531.7 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for glum-3.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 772babe6aa68eb56eb11d4b60bd7cfcc0ad47fe11569030f16c296fb8a58b5b7
MD5 bb8e2dc683e3ca7891455316bd8066c3
BLAKE2b-256 4fecf5b279d2dd0394176b418aefa5a7e70fe13e6e92be566113248059fa335e

See more details on using hashes here.

Provenance

The following attestation bundles were made for glum-3.1.0-cp310-cp310-win_amd64.whl:

Publisher: build_wheels.yml on Quantco/glum

Attestations:

File details

Details for the file glum-3.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for glum-3.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b0d5f234c48c8bf6f329459b750fcb873f21903701e152f4b18575ca7dc6cfcc
MD5 7fcd15cdc71ce1faf35a68000991d646
BLAKE2b-256 a410755ed09cb4e0f71aba2b39894b82e2ae4e4c85b6039f8f128b3532e377e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for glum-3.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_wheels.yml on Quantco/glum

Attestations:

File details

Details for the file glum-3.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for glum-3.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d43786b174a6d24c3097036158bb6e58750177b4abc5f473967251a70e9bdb97
MD5 589be011c372b5d0cfb374a245fff69c
BLAKE2b-256 d1a18a06dd38c97aaafea66c375b98b5efaf7465687abd29de8a69a53afac5b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for glum-3.1.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: build_wheels.yml on Quantco/glum

Attestations:

File details

Details for the file glum-3.1.0-cp310-cp310-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for glum-3.1.0-cp310-cp310-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 6fc5db8abd24fdd6ea223bc47900d2bb464d3c846ae4eabc0dbfb07b17ac9d62
MD5 c062695a42b01f72c102695126be996e
BLAKE2b-256 d38cc47603619b68a21af0a8bfc1f13710d3339f6da80a95ed68b676a9bd23c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for glum-3.1.0-cp310-cp310-macosx_10_13_x86_64.whl:

Publisher: build_wheels.yml on Quantco/glum

Attestations:

File details

Details for the file glum-3.1.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: glum-3.1.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 532.8 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for glum-3.1.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 8196acaa94bb080e2bd559f39ec2530cbb7f0891c6c7cc937fecc3811654c2a5
MD5 5639c60f7268e96b11ad18540169e174
BLAKE2b-256 8650278dd587e195c29962c801488f8f33f1834e263010674ed75dc25ebb87df

See more details on using hashes here.

Provenance

The following attestation bundles were made for glum-3.1.0-cp39-cp39-win_amd64.whl:

Publisher: build_wheels.yml on Quantco/glum

Attestations:

File details

Details for the file glum-3.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for glum-3.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 593645671b72525428640e4a340c743f14949db323e7314dac1b261ec6485b68
MD5 653ff2fd6576b94a201e88b89e81982a
BLAKE2b-256 f0fbc1106858512f670d521e9505c2d223593e68c85307d35b5b9e5f8980e075

See more details on using hashes here.

Provenance

The following attestation bundles were made for glum-3.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_wheels.yml on Quantco/glum

Attestations:

File details

Details for the file glum-3.1.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for glum-3.1.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 603b71ddeb84118654a9bf68e1cb90280434101d6c34cc7718eaf10b4dd3ccb9
MD5 bba809db9569085897044d989d93e158
BLAKE2b-256 16aba2e02f4029bf6c4e4c31b553e52088219de678eba71e3d44b781a9504695

See more details on using hashes here.

Provenance

The following attestation bundles were made for glum-3.1.0-cp39-cp39-macosx_11_0_arm64.whl:

Publisher: build_wheels.yml on Quantco/glum

Attestations:

File details

Details for the file glum-3.1.0-cp39-cp39-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for glum-3.1.0-cp39-cp39-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 81c9dff6dafb9c73af1a2ba7e979b58a79118125edd16949cded239bd375a63a
MD5 69cab9e36c3035686adad2cb8bd44538
BLAKE2b-256 60491efc8827c74783d49aa103f6c2822ed14193417986854e55dcd7d52a71fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for glum-3.1.0-cp39-cp39-macosx_10_13_x86_64.whl:

Publisher: build_wheels.yml on Quantco/glum

Attestations:

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