Synthetic linear regression dataset
Eighty points follow the straight mean y = 1.8x + 0.4. x is uniform from −1 to 5, and independent Gaussian noise of standard deviation 0.85 is added to y. Seed 7 fixes the table. Use it to check a fit against a slope you already know.
What this page generates
Linear regression homework is easier to grade when the slope is not a mystery. This generator commits to slope 1.8 and intercept 0.4 before any noise is added. The clean column is exactly that line. The measured column is the line plus a normal deviate. If a student’s fitted slope is near 1.8, the code is working. If it is near 0.4, they have swapped the coefficients.
The noise standard deviation 0.85 is about half the change in the mean across one unit of x, so residuals are visible on a scatter plot and a least-squares line is still well determined with 80 rows. There are no outlier spikes in the default. That is deliberate: this page is about ordinary residuals, not about robust loss. Add spikes in the free-form editor if the next exercise needs them.
Because x is random rather than a designed grid, leverage is uneven. Points near x = −1 and x = 5 pull the slope more than points near the middle. That is a feature for a lecture on hat values. The worked numbers below are computed from this seed, not typed in by hand, so they match the CSV byte for byte aside from rounding in the prose.
Generating rule
Mean function
y = 1.8*x + 0.4
Check values
Worked numbers
Seed 7 produced 80 rows. The first row has x = -0.9298, clean y = -1.2736, and measured y = 0.7101. A least-squares line through the measured column has slope 1.901 and intercept 0.179. The generating slope is 1.8 and the generating intercept is 0.4, so the gap is sampling noise, not a different formula.
Parameters and defaults
| Parameter | Default | Range | Effect |
|---|---|---|---|
| x | uniform [−1, 5] | finite interval | Sets the design of the regression. Wider range means more leverage. |
| samples | 80 | 2 to 20,000 | Degrees of freedom for the residual variance. |
| Gaussian std | 0.85 | ≥ 0 | Residual scale. Zero reproduces the exact line. |
| outlier fraction | 0 | 0 to 1 | Left at zero so every residual is ordinary Gaussian noise. |
| seed | 7 | unsigned 32-bit integer | Repeats both the x draws and the residuals. |
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: 7
# formula: y = 1.8*x + 0.4
# samples: 80
# mulberry32() and box_muller() are included when you copy the full script.
SEED = 7
N = 80
rng = mulberry32(SEED)
x = 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):
x[i] = (-1.0) + ((5.0) - (-1.0)) * rng()
y_clean[i] = ((1.8 * x[i]) + 0.4)
noise = 0.0
noise += (0.85) * box_muller(rng)
y[i] = y_clean[i] + noise
columns = ["x","y_clean","y"]
data = np.column_stack([x, y_clean, y])
Exercises
- EXERCISE 01Compare a library’s LinearRegression coefficients with the known 1.8 and 0.4.
- EXERCISE 02Estimate residual standard deviation and see that it lands near 0.85.
- EXERCISE 03Show that sorting the file is optional for fitting and required only for a tidy line plot.
Questions
Should the fitted slope equal 1.8 exactly?
No. Noise moves the estimate. With 80 rows and this residual scale it should be close, not identical. The clean column, not the noisy column, is exactly 1.8x + 0.4.
Is the intercept the value at the first row?
The intercept is the mean when x is 0. The first row is whatever uniform draw came first. Read y_clean at that x if you want a single check point.
Why is there a y_clean column?
So a fit can be scored against the truth and against the noisy instrument separately. Real labs do not hand you the truth; this file does, and it says so.
What license is the CSV under?
The static sample is CC BY 4.0. Attribute MockDataLab and keep the synthetic-data banner.
Related
- cubic data where a straight line is the wrong model
- two-input surface with an interaction
- parabola with outlier spikes
- edit the slope and intercept yourself
- download the seeded CSV directly
- Static CSV for seed 7
SYNTHETIC DATA - generated by MockDataLab (mockdatalab.com). Do not present the download as a real measurement.