Skip to main content

High performance Python GLMs with all the features!

Project description

glum

CI 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.0.2.tar.gz (13.5 MB view details)

Uploaded Source

Built Distributions

glum-3.0.2-cp312-cp312-win_amd64.whl (530.2 kB view details)

Uploaded CPython 3.12 Windows x86-64

glum-3.0.2-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.0.2-cp312-cp312-macosx_11_0_arm64.whl (623.9 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

glum-3.0.2-cp312-cp312-macosx_10_13_x86_64.whl (974.3 kB view details)

Uploaded CPython 3.12 macOS 10.13+ x86-64

glum-3.0.2-cp311-cp311-win_amd64.whl (521.2 kB view details)

Uploaded CPython 3.11 Windows x86-64

glum-3.0.2-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.0.2-cp311-cp311-macosx_11_0_arm64.whl (604.5 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

glum-3.0.2-cp311-cp311-macosx_10_13_x86_64.whl (934.4 kB view details)

Uploaded CPython 3.11 macOS 10.13+ x86-64

glum-3.0.2-cp310-cp310-win_amd64.whl (520.5 kB view details)

Uploaded CPython 3.10 Windows x86-64

glum-3.0.2-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.0.2-cp310-cp310-macosx_11_0_arm64.whl (609.0 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

glum-3.0.2-cp310-cp310-macosx_10_13_x86_64.whl (934.7 kB view details)

Uploaded CPython 3.10 macOS 10.13+ x86-64

glum-3.0.2-cp39-cp39-win_amd64.whl (521.6 kB view details)

Uploaded CPython 3.9 Windows x86-64

glum-3.0.2-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.0.2-cp39-cp39-macosx_11_0_arm64.whl (610.2 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

glum-3.0.2-cp39-cp39-macosx_10_13_x86_64.whl (935.9 kB view details)

Uploaded CPython 3.9 macOS 10.13+ x86-64

File details

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

File metadata

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

File hashes

Hashes for glum-3.0.2.tar.gz
Algorithm Hash digest
SHA256 3ed52adc9520c51102fa18292de18e3399fe26b2c2270f3ead8652439fb6382d
MD5 387d71b64093fd5fc09ac00aebada925
BLAKE2b-256 8c6ce6e5a84f8a48ff5d8b055f677f29090c0eda940833290678d6895feb3348

See more details on using hashes here.

File details

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

File metadata

  • Download URL: glum-3.0.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 530.2 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for glum-3.0.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c467bd9614e2441fb6189c16ad053b347124e8161ba42bc8da77504390336144
MD5 148a33f7df310fa91ebdb1b86b2f924d
BLAKE2b-256 99508f288e884463769109800cc25c03538130072311440e2e3abd0ff18c0a4b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for glum-3.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 961bbec4d568f6d400d440771e13a9c1b8ea608404dec58c5790d9911f7dc71f
MD5 cf8d4cb910f557a3aec9ae564bf4fbcb
BLAKE2b-256 3a0692c95df66ea3b2e3c63feea52727b9f920e08cc535d8af42a5332edbcdc2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for glum-3.0.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2ebdfd25f7e5e934caab2ffd9ed05dae121c50d9f976af7eefece8fed4362f74
MD5 1442ce9868d267f072aebd0ceae6cadb
BLAKE2b-256 79a37916aaa4853f4529d1ca748be849b72edd474970f74a67900104ba0b8035

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for glum-3.0.2-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 257675e06140cac8e729143c9ea74c102aa8ff75e46d7aa1b319d2b2ac65462e
MD5 3c28d0af0f74a3b9e182c78e0459bb0e
BLAKE2b-256 b29e0a67a25f93d6693b6f9d8ef06d4a27912ba4a83344a9c88758a0729b2cd0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: glum-3.0.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 521.2 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for glum-3.0.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c275e08351650487bfcf92a52779544866e0ea92afa761f17cce863670058db9
MD5 ec97a4af7029453776e0aecafaa7378f
BLAKE2b-256 38ec56d92637017c7bed7ce30f1f478e1d902230dcff5a009a9ff308e1174e71

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for glum-3.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c248aa3fed18b036d13dd6af2afa2fd606941dfa87b2db12ad13d5b230fd7949
MD5 16aa80a17e83f575a35b235dd98a8c57
BLAKE2b-256 d5a46eefdeb19e3856e68d7251068157cd0bfb15d929395d6f96dd3dca3eec44

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for glum-3.0.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5ae171f79c2cd662d75e027e84f7f2d7bc70b153446d0d2c82c873730de9746c
MD5 fac9077a089fe392c22de2825cde6b5c
BLAKE2b-256 1358e5f54195db79d43a07aa15071eb2841564500547188df311a36efaf5c1de

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for glum-3.0.2-cp311-cp311-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 2d6b79338cb7a988e811df000da110fd398cbe136b637de6b95bb6fc69c00f94
MD5 05ab08214210d7637bf364d343bbfd25
BLAKE2b-256 f2f0f760c1e3d4973e7ec95b1a45b49218941adba3eab5b76cb65017fac665cd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: glum-3.0.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 520.5 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for glum-3.0.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 0ad67870f87d57a7a65aaee3e241e7dbc7c850866648e8d08eebf7a57c0ae9d5
MD5 1af95fbb98bd09b9b55ab5f61cd90236
BLAKE2b-256 4be573b5dc3080ed8bf89b747de42c1dd74f7dfcbffc7c7f7fc9e232e8f0b594

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for glum-3.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 18d13c00fbf6a56ebb051b333918ba1c0584a010a535f96adb531f62f5192fe9
MD5 2a8fe2a50487d5f6997f3a10fb5d2fef
BLAKE2b-256 417b22ca16f9e99b4a60a0cb26147fdc59dfe2fc11dfb0925d0c013b51802605

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for glum-3.0.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e4499f4698e0288226fd623b367b0c1e1204126a6c99f9f54743b2f21ee1e8ac
MD5 eed918c661c5ac1256c6a080a5b0b3c8
BLAKE2b-256 ef7829d9d728d676502c548114e22b42edcef7e2b0c163231d5b4a63a1ae1518

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for glum-3.0.2-cp310-cp310-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 90c86e35df57634b30cf77e536394ae7208a055666c60a9e6523245bbada0358
MD5 3eb46dfb0a1476072778cc4ab47fb3a9
BLAKE2b-256 57bcb25cc439edee21718d72fffd2f39663acd969c5a691afbc6b13b4934015d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: glum-3.0.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 521.6 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for glum-3.0.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 b1b627248c22ebef4baed8bbac6827e7c234d4cb377e4082f4bd64506f581fe5
MD5 31cd80f918198bae0eb90a7406df4d91
BLAKE2b-256 2ef9d9308b7a85e34a0a21e0cfc643122a879ebcdac38edb6ed9cd92002612cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for glum-3.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 af573e46f99e75d0c0258509d643bd0762f3fd4a2287535fc8a410a0ddbcc441
MD5 c93d10a68525525d183ee0fa9ed8680a
BLAKE2b-256 9e085f0346b83a057b04e917ebfe64856168e962fd4e93b1ba97f469dc58d0a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for glum-3.0.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 53ab88c97d266606b84732bf6fd755e51b6f33df30e895800eac0f437297a2e2
MD5 80955430238a2c784483143ec8a148e2
BLAKE2b-256 ed1acc27d5bc59a3f32ade20e3e0534718a0f5f361a10eb17e4afe70e1fae473

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for glum-3.0.2-cp39-cp39-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 6b72ee170df30cbd9a2d0e43d1e345a79faaebb61d1630527849f7c1cf26bba9
MD5 18e4425a567bda52934972da2583cee4
BLAKE2b-256 839d1e2827f969b8ad77a0b35143cacea5c7b680a6fb74712e7ab3b0a92a39ac

See more details on using hashes here.

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