Linear Regression
Problem Formulation
Given a dataset of \(n\) samples with features \(X \in \mathbb{R}^{n \times d}\) and responses \(y \in \mathbb{R}^n\), find coefficients \(\beta \in \mathbb{R}^d\) that minimize the squared error:
The ordinary least squares (OLS) solution is:
Under differential privacy constraints, we want algorithms that satisfy \((\varepsilon, \delta)\)-DP while achieving low estimation error compared to the non-private OLS solution or ground truth.
API Reference
Types, algorithms (with their privacy arguments + hyperparameter defaults), instance generators, and metrics are documented from the source docstrings on the Linear Regression API Reference page.
Inherited Algorithms
Linear regression is a child of the M-Estimation task, so all M-estimation algorithms are available via task inheritance. See the M-Estimation task page.
Usage Example
from dp_testing_platform import ApproxDPBudget
from dp_testing_platform.tasks.linear_regression import LinearRegression
from dp_testing_platform.tasks.linear_regression.algorithms import VanillaSSP, OLS
import numpy as np
# Create synthetic data
np.random.seed(42)
n, d = 100, 5
X = np.random.randn(n, d)
beta_true = np.random.randn(d)
y = X @ beta_true + 0.1 * np.random.randn(n)
# Set up task
metadata = LinearRegression.Metadata(dim=d, n_samples=n)
input_data = LinearRegression.Input(X=X, y=y)
# Run non-private baseline
ols = OLS()
ols_output = ols.run(metadata, input_data, ApproxDPBudget(1.0, 1e-5), seed=42)
# Run DP algorithm
ssp = VanillaSSP(C_x_clip=1.0, C_y_clip=1.0)
dp_output = ssp.run(metadata, input_data, ApproxDPBudget(1.0, 1e-5), seed=42)
# Compare results
print(f"OLS error: {np.linalg.norm(ols_output.beta - beta_true):.4f}")
print(f"SSP error: {np.linalg.norm(dp_output.beta - beta_true):.4f}")