Skip to main content

glassy

glassy explores predictive multiplicity in linear regression: how much model coefficients and predictions can vary while training error stays close to a reference model's error. For squared-error loss, it computes exact ranges over this set of models.

Install

Install from PyPI:

python -m pip install glassy

Quick start

Prism and Spec are separate objects. Prism analyzes the model set; Spec builds concrete models. Initialize both with a fitted linear regressor and the training data:

import numpy as np
from sklearn.linear_model import LinearRegression
from glassy import Prism, Spec

rng = np.random.default_rng(7)
X = rng.normal(size=(100, 3))
y = 2 * X[:, 0] - X[:, 1] + rng.normal(scale=0.5, size=100)

model = LinearRegression().fit(X, y)

# Include models with training MSE up to 5% above the reference model's MSE.
prism = Prism(model, X, y, r=5.0, units="percent")
spec = Spec(model, X, y)

print(prism.coef_bounds())
predictions = prism.disagreement(X)
print(predictions["min"], predictions["optimal"], predictions["max"])
print(prism.query_droppable("feature_2"))

candidate = spec.sans_features("feature_2")
print(candidate.predict(X)[:5])

Prism.from_data(X, y, r=..., units=...) is a convenience constructor that fits an ordinary least squares reference model for you. Radius units are "percent" (relative to the reference model's training MSE) or "raw" (an additive MSE increase).

API overview

  • prism.coef_bounds(...) returns coefficient intervals. Set magnitude=True for ranges of absolute coefficient values. mode can be "both", "min", or "max"; features limits the result to selected names.
  • prism.disagreement(X=None) returns min, optimal, and max prediction arrays; it uses the training data when X is omitted.
  • prism.query_droppable(features) checks whether features can be removed within the loss limit. prism.droppable(max_terms=1) lists removable subsets up to that size; use max_terms=None to search all subset sizes.
  • prism.update_r(r, units=None) changes the radius.
  • spec = Spec(model, X, y, feature_names=None) creates a model-building object independently of Prism. spec.sans_features(features) returns a fitted sklearn model with the named coefficients fixed at zero and the others refit.
  • spec.from_coefs({"feature_0": value}) returns a fitted model with the specified coefficients fixed and the others refit to minimize training MSE.
  • spec.mse(model=None, X=None, y=None) computes training or supplied-data MSE; omitted arguments default to the model and data held by spec.
  • prism.spec() is an optional convenience method that creates a Spec from the reference model and data already held by that Prism.

For NumPy arrays, feature names default to feature_0, feature_1, and so on. DataFrame column names are preserved.

Scope and requirements

glassy currently supports numeric linear-regression features, an intercept, and squared-error loss. The feature matrix must have full column rank; redundant or constant columns make the model set unbounded and are rejected. Runtime dependencies are NumPy and scikit-learn.

Development

python -m pip install -r requirements.txt
python -m pytest -q

Example notebooks are in demos/.

Metadata

Release files for glassy 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for glassy 0.1.0
File Size Uploaded
glassy-0.1.0.tar.gz 19.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for glassy 0.1.0
File Interpreter ABI Platform
glassy-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.1 kB

Release files / glassy-0.1.0.tar.gz

Download URL glassy-0.1.0.tar.gz
Size 19.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e62c3e2ad361849753e3733349d9274e42fe1077ff3dca7f214ea24a03e1d0f2
BLAKE2b-256 checksum
How to use checksums
e6aaade0db42848c91a9627d01c085b762fbab71dd0ea8038542c4b100ce1645
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / glassy-0.1.0-py3-none-any.whl

Download URL glassy-0.1.0-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b14d401aaed739cb23c9f36d9a06cc8d8c578c0815679283f55179441eed6520
BLAKE2b-256 checksum
How to use checksums
a7271d97d93b5012704437f7105470dca23d54e86e0591a57d1bedebe58174a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page