Guess, check, nudge, a thousand times. The result: a 12 km delivery takes about 40.1 minutes.
python3 --version.git clone https://github.com/DayanEbrar0X/data-anatomy.ai.git cd data-anatomy.ai
python3 -m venv .venv source .venv/bin/activate
cd machine-learning/07-linear-regression-no-libraries python3 src/delivery.py
km = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
mins = [8, 9, 15, 15, 20, 20, 26, 27, 31, 35]
w, b = 0.0, 0.0
for step in range(1000):
for x, y in zip(km, mins):
err = w * x + b - y
w -= 0.002 * err * x
b -= 0.002 * err
print(f"12 km: {w * 12 + b:.1f} min")This loop is how machines learn. Nine lines, no libraries. Say we're predicting delivery times. Ten trips: kilometers, minutes.
The model: a line, w and b, starting flat. A thousand times, for every trip, it guesses, and checks the error, then nudges w and b against it. Like a shower knob, bit by bit. Result: a 12 km trip, about 40 minutes.
Guess, check, nudge. That's how machines learn.
Read the lesson on GitHub →