Synthetic polynomial dataset
The clean column is the cubic 0.18x³ − 1.05x² + 0.4x + 2 on x uniform from −1 to 6, with Gaussian noise of standard deviation 0.7 and seed 11. A straight line through these points is the wrong model on purpose.
What this page generates
Polynomial regression exercises fail in a useful way when the mean bends. This cubic falls through the middle of the interval and rises again toward x = 6. The leading coefficient 0.18 is small, so the bend is gentle rather than a sharp hook. Noise of 0.7 blurs the bend without erasing it. One hundred forty rows are enough to prefer a cubic over a line if the comparison uses held-out error or a simple residual plot.
There is no extra outlier process. Every deviation from the cubic is one normal draw. If a residual plot still shows a smile after a quadratic fit, the cubic term is what remains. If a student centers x before fitting, the coefficients change and the fitted curve should not. That distinction is easier to teach when the generating polynomial is written on the page.
The sample of x is random, so bin means are the honest way to see the bend. The generator does not bin for you. Average y inside intervals of x and you should recover a shape close to the cubic, with more jitter in bins that happened to receive fewer draws.
Generating rule
Generating polynomial
y = 0.18*x^3 - 1.05*x^2 + 0.4*x + 2
Check values
Worked numbers
Seed 11 yields 140 rows. The root-mean-square gap between measured y and the cubic column is 0.761, next to the requested Gaussian standard deviation 0.7. A straight-line fit is the wrong target: the clean column is the cubic written above, not a line.
Parameters and defaults
| Parameter | Default | Range | Effect |
|---|---|---|---|
| x | uniform [−1, 6] | finite interval | Covers the dip and the later rise of this cubic. |
| samples | 140 | 2 to 20,000 | Stabilizes bin means and polynomial fits. |
| Gaussian std | 0.7 | ≥ 0 | Vertical scatter around the cubic. |
| seed | 11 | unsigned 32-bit | Locks x 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: 11
# formula: y = 0.18*x^3 - 1.05*x^2 + 0.4*x + 2
# samples: 140
# mulberry32() and box_muller() are included when you copy the full script.
SEED = 11
N = 140
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) + ((6.0) - (-1.0)) * rng()
y_clean[i] = ((((0.18 * (x[i] ** 3.0)) - (1.05 * (x[i] ** 2.0))) + (0.4 * x[i])) + 2.0)
noise = 0.0
noise += (0.7) * box_muller(rng)
y[i] = y_clean[i] + noise
columns = ["x","y_clean","y"]
data = np.column_stack([x, y_clean, y])
Exercises
- EXERCISE 01Ask a model-selection lab to choose among degrees 1, 2, and 3.
- EXERCISE 02Plot residuals from a linear fit and look for remaining curvature.
- EXERCISE 03Check a numerical pipeline that expands x, x², and x³ without looking at the clean column.
Questions
Is the cubic monic?
No. The x³ coefficient is 0.18, not 1. A monic cubic would be much steeper on this interval.
Why not space x evenly?
Even spacing is a designed experiment. This page imitates a random sample. Switch the distribution in the editor if you want a grid.
Will degree 4 fit better?
In-sample, a higher degree can always wiggle toward noise. The clean column is only degree 3, so extra degrees are fitting the Gaussian draws.
Related
- the straight-line case with a known slope
- a simpler bowl-shaped mean
- a curved mean that is not a polynomial
- type a different polynomial
- static CSV for this seed
- Static CSV for seed 11
SYNTHETIC DATA - generated by MockDataLab (mockdatalab.com). Do not present the download as a real measurement.