Skip to content

Simple Linear Regression

Problem Formulation

Given \(n\) paired samples of a single scalar covariate \(x \in \mathbb{R}^n\) and a response \(y \in \mathbb{R}^n\), fit the line

\[y \approx \text{slope} \cdot x + \text{intercept}.\]

The estimand is the pair \((\text{slope}, \text{intercept})\) — the intercept is part of the output, not dropped. The problem is structurally one-dimensional, so the metadata carries no dim field (only n_samples and optional x/y domain bounds). The privacy boundary protects \((x, y)\); the model form is public.

This is the smallest regression task, useful as a first benchmark and for algorithms whose behaviour is easiest to reason about in one covariate.

Relationship to Linear Regression

simple_linear_regression is a child of the Linear Regression task. Any linear-regression algorithm runs here for free: the framework promotes the scalar covariate \(x\) to a two-column design matrix \([x, 1]\) — the constant column lets the parent fit recover an intercept — runs the algorithm to estimate the two coefficients, and reads them back as \((\text{slope}, \text{intercept})\). Both directions share a fixed column order, so slope and intercept never swap.

Because the reference fit here is OLS with an intercept, a dataset converted to simple_linear_regression and the same dataset converted to linear_regression (a through-origin \(d=1\) fit) are different benchmark instances, not two scorings of the same fit.

API Reference

Types, algorithms (lifted from linear regression), instance generators, and metrics are documented from the source docstrings on the Simple Linear Regression API Reference page.

Usage Example

from dp_testing_platform import ApproxDPBudget
from dp_testing_platform.tasks.simple_linear_regression.instance_generators import (
    GaussianSimpleLinearRegression,
)
from dp_testing_platform.tasks.simple_linear_regression.algorithms import (
    OLSSLR,
    VanillaSSPSLR,
)

# A synthetic scalar-covariate instance: y = 2*x + 1 + Gaussian noise.
gen = GaussianSimpleLinearRegression(
    n_samples=500, slope=2.0, intercept=1.0, metric="l2_error_to_ols"
)
metadata, input_data, metric = gen.generate(seed=0)

# Non-private baseline: the OLS fit lifted onto the simple-LR task.
baseline = OLSSLR()
budget = ApproxDPBudget(1.0, 1e-5)
base_out = baseline.run(metadata, input_data, budget, seed=0)
print(f"OLS:  slope={base_out.slope:.3f}  intercept={base_out.intercept:.3f}")

# DP sufficient-statistics perturbation (any linear-regression algorithm lifts here).
ssp = VanillaSSPSLR(C_x_clip=1.0, C_y_clip=1.0)
dp_out = ssp.run(metadata, input_data, budget, seed=0)
print(f"DP:   slope={dp_out.slope:.3f}  intercept={dp_out.intercept:.3f}")
print(f"L2 error to OLS: {metric(dp_out):.4f}")