GenerateRandomSearch

Regression Dataset Generator

Testing anything that fits a line needs data whose answer you already know. This builds points from a slope and intercept you choose, adds as much noise as you want, and then fits the line back out — so you can see directly how far the estimate lands from the truth, and how much noise it takes before R-squared stops looking convincing.

What this generator does

Draws x values uniformly, computes y from your slope and intercept, adds Gaussian noise, then runs ordinary least squares over the result. Both the true parameters and the recovered ones are shown, because the gap between them is what estimating from a finite sample actually looks like.

How to use this tool

  1. Set the slope and intercept the data should be built from.
  2. Add noise to scatter the points away from the line.
  3. Generate, then compare the fitted slope against the true one.
  4. Copy the CSV into whatever you are testing.

Understanding the controls

True slope and intercept
The relationship the data is generated from. With zero noise the fit recovers them almost exactly — almost, because values are rounded to two decimals for display and that alone shifts the answer slightly.
Noise
How far points scatter from the line. This is the control worth playing with: it changes R-squared dramatically while leaving the underlying relationship completely intact.
How many rows
Between 10 and 1,000. Small samples give visibly worse estimates, which is the point.
Seed
Unless the generator has changed since, any word reproduces the same dataset, which a committed test fixture needs.

Worked examples

Slope 2, intercept 10, noise 8, seeded "demo"
Ten rows, the fewest the page takes, fitted back give a slope of 1.987 and an intercept of 8.82 against the true 2 and 10 — close, not exact — with an R-squared of 0.976. The gap between 1.987 and 2 is exactly what estimating a known relationship from a finite noisy sample looks like.

Common use cases

  • Testing a regression implementation against data whose answer is known
  • Showing why R-squared measures scatter rather than whether a relationship exists
  • Producing scatter-plot data with a deliberate trend for a chart component
  • Teaching least squares from data rather than algebra
  • Checking how many points an estimate needs before it settles

How this generator works

Ordinary least squares is computed directly from the generated rows rather than remembered from the construction, so the reported fit is a genuine measurement of the data you are given. R-squared is the squared correlation between x and y.

Randomness and fairness

The x values and the noise are random, so two runs differ. The slope you specify does not. Seeded runs are reproducible and therefore explicitly not cryptographically secure; unseeded runs use the browser's cryptographically secure generator.

For how randomness is produced across the whole site, see how Generate Random works.

Limitations and good to know

  • One predictor only. Multiple regression, interactions and non-linear terms are not covered.
  • Noise is Gaussian and constant across the range. Real data often has noise that grows with x, which breaks a key regression assumption this cannot demonstrate.
  • Values are rounded to two decimals for display, so a perfect fit is very slightly imperfect.
  • Datasets are not saved; seed anything a test asserts against.

Privacy and your data

The dataset is generated in your browser. No seed or generated row is transmitted or kept after you close the page; of the parameters, only the number of rows is measured, along with the fact that a dataset was made.

Frequently asked questions

Why doesn't the fitted slope exactly match the slope I set?
Because noise was added to every point, and least squares can only estimate the underlying relationship from a finite, noisy sample — it can't see through the noise to the exact original parameters. Set noise to 0 and the fit recovers the slope almost exactly (bar a small rounding effect from displaying values to two decimals); any noise above that leaves an unavoidable gap between the true and fitted values.
Why does R-squared drop when the relationship itself hasn't changed?
R-squared measures how tightly points cluster around the fitted line, not whether a linear relationship exists. Raising the noise scatters the same underlying relationship further from the line, which lowers R-squared even though the true slope and intercept you set are completely unchanged — a distinction worth seeing directly before treating R-squared as a stand-in for "is there a relationship."