Simple Linear Regression — API Reference
Auto-generated from the source docstrings. For the problem formulation and a usage example, see the Simple Linear Regression task page.
Types
dp_testing_platform.tasks.simple_linear_regression.types
SimpleLinearRegressionMetadata
dataclass
Metadata for simple (scalar-covariate) linear regression.
The covariate is a single scalar, so the problem is structurally
one-dimensional and there is no dim field (mirrors the M-estimation
children, whose dimension is implied by the task). The model is
y = slope * x + intercept; the intercept is part of the estimand.
Attributes:
| Name | Type | Description |
|---|---|---|
n_samples |
int
|
Number of samples in the dataset. |
x_domain |
Domain | None
|
Domain constraint for the scalar covariate x. If None, x is unbounded. |
y_domain |
Domain | None
|
Domain constraint for the response y. If None, y is unbounded. |
SimpleLinearRegressionInput
dataclass
Input for simple linear regression.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
Array1D
|
Scalar covariate vector, shape (n_samples,). |
y |
Array1D
|
Response vector, shape (n_samples,). |
SimpleLinearRegressionOutput
dataclass
Output for simple linear regression: y ~= slope * x + intercept.
Attributes:
| Name | Type | Description |
|---|---|---|
slope |
float
|
Estimated slope coefficient (covariate weight). |
intercept |
float
|
Estimated intercept (constant term). |
Algorithms
Every algorithm on this task is a linear_regression algorithm presented as a
native simple-LR algorithm (the scalar covariate is promoted to a [x, 1] design
matrix, so the fitted beta is (slope, intercept)).
dp_testing_platform.tasks.simple_linear_regression.algorithms.lifted
Linear-regression algorithms lifted onto the simple-linear-regression task.
Each class presents a native linear_regression algorithm as a native
simple_linear_regression algorithm. The scalar-covariate task is lifted to
the parent (general d-dimensional) linear_regression task by promoting the
scalar covariate x to a 2-column design matrix [x, 1]: the constant
column makes the parent's through-origin fit estimate an intercept, so the
parent's beta is (slope, intercept).
The classic pitfall here is an inconsistent column order between lift_input
(which builds the design matrix) and push_output (which reads the fitted
coefficients back). Both directions go through the module-level SLOPE_COLUMN
/ INTERCEPT_COLUMN constants so they stay in lockstep. lift_input is
per-row (row i maps to row i), so the inner algorithm's
(eps, delta)-DP guarantee transfers verbatim.
Instance generators
dp_testing_platform.tasks.simple_linear_regression.instance_generators.gaussian_instance_generator
GaussianSimpleLinearRegression
Bases: InstanceGenerator
Synthetic scalar-x linear regression generator.
Generates y = slope * x + intercept + noise with Gaussian covariate x
and Gaussian response noise.
Metrics
dp_testing_platform.tasks.simple_linear_regression.metrics
Metric registry for the simple_linear_regression task.
The reference fit here is OLS with an intercept (y = slope * x +
intercept), recomputed on the instance's own (x, y) and scored in child
output space (slope, intercept). This differs numerically from the parent
linear_regression task's through-origin d=1 reference: a dataset converted to
simple_linear_regression and the same dataset converted to
linear_regression are different benchmark instances, not two scorings of
the same fit.
l2_error
L2 error between (slope, intercept) and a reference 2-vector.
The reference is ordered [slope, intercept] (ground truth or OLS).
key_l2_error_to_ols
key_l2_error_to_ols(output: SimpleLinearRegressionOutput, evaluation_input: SimpleLinearRegressionInput) -> float
L2 distance from (slope, intercept) to the intercept-OLS of (x, y).
Recomputes the with-intercept OLS fit from the instance's own (x, y)
(so the value is recomputable post-hoc) and returns the L2 distance to it.