Start with a Prediction

Predict delivery times with Botie

Lesson reference and earlier work

A customer asks when their order will arrive. Build a machine that can give them an estimate, then use the deliveries to find out where it goes wrong. These are invented measurements for the project.

What carries over from your earlier work?

Find a mean from all observations

The mean time and mean position anchor the fitted line.

There is no saved attempt here yet. You can try the earlier workshop whenever you need it.

Open Statistics & Probability Primer

Interpret a slope as position change per time

The fitted coefficient describes the rate of change assumed by this straight-line approximation.

There is no saved attempt here yet. You can try the earlier workshop whenever you need it.

Open Calculus Primer
Where this fitting problem came from

Which Observation Should an Astronomer Believe?

An astronomer measuring an object's position does not get exactly the same answer every time. Instruments and observations introduce errors. If the measurements disagree, we cannot simply draw a relationship that passes through all of them and expect it to describe the underlying motion.

In 1805, Adrien-Marie Legendre published the method of least squares in an appendix to his work on determining comet orbits. The problem was how to reconcile more observations than could be satisfied exactly. Squaring the remaining discrepancies and adding them gave a definite criterion for choosing among possible fits.

For our first regression, the possible fits are straight lines. Each line predicts a value at each observed input. We measure the vertical gaps, square them so opposing errors cannot cancel, and choose the line with the smallest total. The astronomical problem is much larger, but the principle is the same: use all the observations to find a relationship that compromises between their disagreements.

Build the historical fitting calculation

Here you can return to the astronomers' measurement problem and construct the fitting calculation from the lesson. Close this reference panel to return to the delivery missions.

BOTIE

How can we predict a position when the observations disagree? Fit a least-squares line to the supplied times and positions, then predict at the requested time. Use departures from both means to find the slope, and measure the requested time from the mean time.
Ready to test
0 passed · 0 failed · 3 not run

An empty floor. Start with the information your machine needs.

Received result

Your answer will arrive here.

Examples, experiments and workspace controls
Live values

Connect a tool's inputs to see what it produces. You can try a branch before connecting it to Result.

Try your own inputs

Use a copy of the example to try your own data. Keep the problem's assumptions in mind, and predict the effect of a change before checking the output. You can also add another branch to compare two ways of doing the calculation.

Start at an output arrow, then click or drag to an input. Drag empty space to pan. Delete removes a selection. Ctrl/Cmd+Z undoes a change.
Context for this challenge

How can we predict a position when the observations disagree? Fit a least-squares line to the supplied times and positions, then predict at the requested time. Use departures from both means to find the slope, and measure the requested time from the mean time.

Let's return to the astronomer's conflicting measurements. Our invented observations describe an object's position along one direction at several times. They do not lie exactly on a straight line. We want to use all of them to fit a line, then estimate where the object will be at another time. This is a small model of the measurement problem, not an orbit calculation.

Examples and results
Observation times
  1. 00
  2. 11
  3. 22
  4. 33
Observed positions
  1. 01
  2. 14
  3. 25
  4. 38
Time to predict
4
Required result
10
Observation times
  1. 00
  2. 11
  3. 22
  4. 33
Observed positions
  1. 01
  2. 14
  3. 25
  4. 38
Time to predict
5
Required result
12.2
Observation times
  1. 00
  2. 11
  3. 22
Observed positions
  1. 02
  2. 12
  3. 25
Time to predict
3
Required result
6
Stuck? Inspect a worked construction

The tools below form one possible solution. You can assemble it, follow its signals, and undo that change to return to your own construction.

Assumptions and test precision

The times and positions are invented and use arbitrary units. The observations have nonzero time variation. A straight-line approximation over a short interval does not describe a complete astronomical orbit. Numerical tests allow a difference of 0.001. Lists and structures must also have the right shape.

An unobserved time between uneven readings

BOTIE

The observation times are unevenly spaced. Fit their line and predict the position at time 3, which lies between supplied observations.
Observation times
  1. 01
  2. 12
  3. 24
Observed positions
  1. 03
  2. 15
  3. 29
Time to predict
3

Use a number, text, or an array matching the requested result. For a matrix, put each row in brackets. Saving your prediction runs your current construction on these inputs and checks the earlier examples too.

Build a construction in the workspace above first. This case will test those pieces.

How long should we tell the customer?

BOTIE

A rider needs roughly 2 minutes for each kilometre. Preparing the order takes about 6 minutes, even for a customer next door. Where does each amount belong? Choose your pieces and connect the estimate to Result. You can send out these invented deliveries before the construction passes its checks. Their arrival times might help you find what is missing.
Ready to test
0 passed · 0 failed · 4 not run

An empty floor. Start with the information your machine needs.

Received result

Your answer will arrive here.

Examples, experiments and workspace controls
Live values

Connect a tool's inputs to see what it produces. You can try a branch before connecting it to Result.

Try your own inputs

Use a copy of the example to try your own data. Keep the problem's assumptions in mind, and predict the effect of a change before checking the output. You can also add another branch to compare two ways of doing the calculation.

Start at an output arrow, then click or drag to an input. Drag empty space to pan. Delete removes a selection. Ctrl/Cmd+Z undoes a change.
Examples and results
Delivery distance (km)
1
Required result
8
Delivery distance (km)
3
Required result
12
Delivery distance (km)
5
Required result
16
Delivery distance (km)
0
Required result
6
Try a fresh construction

This clears this draft, including its undo history. Earlier successful attempts stay recorded. Build again without opening hints to record an independent attempt.

Stuck? Inspect a worked construction

The tools below form one possible solution. You can assemble it, follow its signals, and undo that change to return to your own construction.

Assumptions and test precision

This is a manually specified rule. Passing its construction checks does not train a model or establish its accuracy on deliveries. The project measurements are invented. Numerical tests allow a difference of 0.001. Lists and structures must also have the right shape.

Name this dispatch machine

The waiting orders

All orders start at minute zero. Select a delivery after the run to follow its estimate back through your machine.

6 orders are waiting for an estimate.