{"id":9018,"library":"glum","title":"GLUM - High Performance Generalized Linear Models","description":"glum is a Python library providing high-performance implementations of Generalized Linear Models (GLMs), including various distributions and link functions. It focuses on speed and feature richness, supporting regularized fitting (L1, L2, ElasticNet) and cross-validation. The current version is 3.3.0, and it maintains an active release cadence with multiple updates throughout the year.","status":"active","version":"3.3.0","language":"en","source_language":"en","source_url":"https://github.com/Quantco/glum","tags":["glm","generalized linear model","machine learning","statistics","regularization","scikit-learn-compatible"],"install":[{"cmd":"pip install glum","lang":"bash","label":"Install stable release"}],"dependencies":[],"imports":[{"symbol":"GeneralizedLinearRegressor","correct":"from glum import GeneralizedLinearRegressor"},{"symbol":"GeneralizedLinearRegressorCV","correct":"from glum import GeneralizedLinearRegressorCV"},{"symbol":"PoissonDistribution","correct":"from glum import PoissonDistribution"},{"symbol":"GammaDistribution","correct":"from glum import GammaDistribution"},{"symbol":"LogLink","correct":"from glum import LogLink"}],"quickstart":{"code":"import numpy as np\nimport pandas as pd\nfrom glum import GeneralizedLinearRegressor, PoissonDistribution, LogLink\n\n# Generate some synthetic data\nnp.random.seed(42)\nn_samples = 100\nX = pd.DataFrame({\n    'feature_1': np.random.rand(n_samples) * 10,\n    'feature_2': np.random.rand(n_samples) * 5\n})\n\n# True coefficients\nbeta_0 = 1.0\nbeta_1 = 0.5\nbeta_2 = 0.2\n\n# Generate Poisson-distributed target variable using a log link\nlinear_predictor = beta_0 + beta_1 * X['feature_1'] + beta_2 * X['feature_2']\nmu = np.exp(linear_predictor)\ny = np.random.poisson(mu)\n\n# Create and fit the GLM\nglm = GeneralizedLinearRegressor(\n    distribution=PoissonDistribution(), \n    link=LogLink(),\n    fit_intercept=True\n)\nglm.fit(X, y)\n\nprint(f\"Intercept: {glm.intercept_:.4f}\")\nprint(f\"Coefficients: {glm.coef_}\")\nprint(f\"Deviance: {glm.deviance_:.4f}\")\nprint(\"Predictions (first 5 samples):\\n\", glm.predict(X.head()).round(2))\n","lang":"python","description":"This quickstart demonstrates how to fit a Poisson GLM with a log link using `glum.GeneralizedLinearRegressor`. It generates synthetic data, then initializes and fits the model, finally printing the intercept, coefficients, deviance, and predictions for the first few samples."},"warnings":[{"fix":"If exact reproducibility with older versions is critical, explicitly set `solver_params={'hess': '2-point'}` when initializing `GeneralizedLinearRegressor` or `GeneralizedLinearRegressorCV` if using `solver='trust-constr'`, though `SR1()` is generally superior.","message":"In v3.3.0, the `trust-constr` solver's default Hessian calculation changed from `hess=\"2-point\"` (finite-difference) to `SR1()` (quasi-Newton). While improving performance, this might lead to slightly different numerical results for models that previously relied on the finite-difference Hessian.","severity":"breaking","affected_versions":">=3.3.0"},{"fix":"Upgrade to `glum>=3.2.3` to ensure correct calculations for the `InverseGaussianDistribution`.","message":"Prior to v3.2.3, `InverseGaussianDistribution.log_likelihood` contained an incorrect call, causing it to always return NaN. Models using `InverseGaussianDistribution` would fail or produce invalid results.","severity":"gotcha","affected_versions":"<3.2.3"},{"fix":"Upgrade to `glum>=3.2.1` to resolve prediction issues when working with categorical features and L1/ElasticNet regularization (`alpha_search`).","message":"Versions before 3.2.1 had an error when predicting at a specific `alpha` with categorical features, potentially leading to incorrect or failed predictions.","severity":"gotcha","affected_versions":"<3.2.1"},{"fix":"Upgrade to `glum>=3.1.3` for correct `deviance_path_` values in cross-validation.","message":"In `GeneralizedLinearRegressorCV`, the `deviance_path_` attribute was incorrectly scaled by `n_folds` in versions prior to 3.1.3, leading to misinterpretation of cross-validation deviance values.","severity":"gotcha","affected_versions":"<3.1.3"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Upgrade your `glum` installation to version 3.2.3 or newer: `pip install --upgrade glum`.","cause":"Using `InverseGaussianDistribution` with `glum` versions prior to 3.2.3 would cause `log_likelihood` to return NaN, propagating through the model fitting process.","error":"ValueError: Input contains NaN, infinity or a value too large for dtype('float64')."},{"fix":"Upgrade `glum` to version 3.1.3 or later: `pip install --upgrade glum`.","cause":"In `glum` versions before 3.1.3, the `theta` setter for `NegativeBinomialDistribution` incorrectly rejected `numpy.number` types, leading to errors when attempting to assign a `theta` value derived from NumPy operations.","error":"TypeError: 'numpy.float64' object cannot be interpreted as an integer"},{"fix":"Ensure you are using `glum` version 3.2.1 or newer. Upgrade using `pip install --upgrade glum`.","cause":"A bug in `glum` versions prior to 3.2.1 caused incorrect predictions when specifying a particular `alpha` value after fitting with `alpha_search=True` and having categorical features in the dataset.","error":"Predictions are inconsistent or incorrect when using alpha_search with categorical features."},{"fix":"Upgrade your `glum` library to version 3.1.3 or newer to get correctly scaled `deviance_path_`: `pip install --upgrade glum`.","cause":"Before version 3.1.3, `deviance_path_` was incorrectly scaled down by a factor of `n_folds`, leading to underestimated deviance values.","error":"The `deviance_path_` attribute in `GeneralizedLinearRegressorCV` shows unexpectedly low values."}]}