Synthetic two-input regression dataset
y depends on two different inputs: x1 is uniform on −3 to 3, x2 is normal with mean 0 and standard deviation 1.2, and the clean output is 0.9x1 − 1.3x2 + 0.35 x1 x2. Gaussian noise of standard deviation 0.45 and seed 21 complete the table.
What this page generates
A single scatter of y against x1 cannot be a thin curve, because x2 is still free. The page colors points by x2 so the interaction is visible as a change of slope. When x2 is high, the coefficient of x1 is 0.9 + 0.35 x2, steeper than 0.9. When x2 is negative, the slope in x1 flattens or reverses. That is the whole point of the product term. A model with only main effects misses it.
The two inputs are drawn independently. x1 is a bounded uniform design. x2 is an unbounded normal, so a few rows sit far out and have high leverage on the interaction. There is no correlation between x1 and x2 in the generator. Sample correlation will be small but not zero. Do not treat a nonzero sample correlation as a bug.
The chart uses the measured y, noise included. The clean column is still in the table for anyone who wants the surface without the 0.45 noise. Fitting both and comparing coefficients with 0.9, −1.3, and 0.35 is the direct check. Centering the inputs changes the main-effect numbers and should leave the interaction coefficient alone.
Generating rule
Surface
y = 0.9*x1 - 1.3*x2 + 0.35*x1*x2
Check values
Worked numbers
Seed 21 has 220 rows and four columns: x1, x2, y_clean, y. The sample correlation between x1 and measured y is 0.619. It is not 0.9, because x2 and the product term and the noise all move y as well. The coefficient 0.9 is the partial effect in the formula.
Parameters and defaults
| Parameter | Default | Range | Effect |
|---|---|---|---|
| x1 | uniform [−3, 3] | finite interval | First regressor, also the horizontal axis of the chart. |
| x2 | normal(0, 1.2) | any mean and std ≥ 0 | Second regressor. Color on the chart encodes it. |
| samples | 220 | 2 to 20,000 | Rows in the design. |
| Gaussian std | 0.45 | ≥ 0 | Noise on y only. The inputs are not noised again. |
| seed | 21 | unsigned 32-bit | Repeats both inputs and the noise, in that order. |
Python for this seed
Full script with mulberry32() & box_muller() available via Copy Python above
# SYNTHETIC DATA - generated by MockDataLab (mockdatalab.com)
# This file is synthetic and must not be presented as real measurements, clinical data, or results from a physical instrument.
# generator: function-relation
# seed: 21
# formula: y = 0.9*x1 - 1.3*x2 + 0.35*x1*x2
# samples: 220
# mulberry32() and box_muller() are included when you copy the full script.
SEED = 21
N = 220
rng = mulberry32(SEED)
x1 = np.empty(N, dtype=np.float64)
x2 = np.empty(N, dtype=np.float64)
y_clean = np.empty(N, dtype=np.float64)
y = np.empty(N, dtype=np.float64)
for i in range(N):
x1[i] = (-3.0) + ((3.0) - (-3.0)) * rng()
x2[i] = (0.0) + (1.2) * box_muller(rng)
y_clean[i] = (((0.9 * x1[i]) - (1.3 * x2[i])) + ((0.35 * x1[i]) * x2[i]))
noise = 0.0
noise += (0.45) * box_muller(rng)
y[i] = y_clean[i] + noise
columns = ["x1","x2","y_clean","y"]
data = np.column_stack([x1, x2, y_clean, y])
Exercises
- EXERCISE 01Fit a model with and without the product term and compare coefficients with 0.9, −1.3, and 0.35.
- EXERCISE 02Explain why a 2-D scatter looks like a cloud even though the mean is deterministic.
- EXERCISE 03Test a feature pipeline that must keep x1 and x2 aligned with y in the same row.
Questions
Why is the chart not a line?
Two inputs remain after you pick an x1 axis. Color is the second input. The table holds both.
Does normal noise on x2 get clipped?
No. Standard deviation 0 produces the mean exactly and does not draw a normal variate. The default 1.2 is unclipped.
Is the interaction optional?
In the generator it is part of the formula. Delete the product in the custom editor if you want main effects only.
Related
- one-input line with a known slope
- labeled clusters in the same two-axis plane
- write a different two-input formula
- CSV with x1, x2, and y
- Static CSV for seed 21
SYNTHETIC DATA - generated by MockDataLab (mockdatalab.com). Do not present the download as a real measurement.