Noisy Linear Data

Noisy linear data has a simple signal plus random variation.

y = slope * x + noise

The signal is the line. The noise makes the data more realistic.

Create the data

Make noisy linear data

Runs locally with Python in your browser.

Ready to run.

The seed makes the random noise repeatable. The shape check confirms that each x value has one y value.

Why use synthetic data?

Synthetic data lets you know the hidden truth. Here, the true slope is 2.0. That gives you a way to judge whether the fitting procedure is reasonable.

Synthetic data is not a replacement for real data. It is a safe first test.

This example deliberately assumes that the line passes through the origin, so the signal has no intercept term. Later models may learn both a slope and an intercept.

Exercise: Signal plus noise

In this chapter's data, what is the non-random signal?

Answer it first, then check.

Hint

Remove the random-noise term from y = slope * x + noise.

Solution

The non-random signal is slope * x. In the code, that is config.true_slope * x; the random noise is added afterward.