Mctaba Labs logo
BootcampData ScienceThe WhiteboardProjectsEventsMasterclassesWebinarsLearn
Book CallApply

500+ developers already in the community

Get answers, find accountability partners, and stay ahead

Join Discord →
Mctaba Labs logo

Educating 1 million students in tech by 2030.

Programs

  • Coding Bootcamp in Nairobi
  • Data Science to AI Engineering
  • HighSchool Graduates Launchpad
  • AI & Business Automation
  • Corporate Training
  • Kids & Teens
  • McTaba Story & Mission
  • Full-Stack Curriculum
  • Course Pricing & Plans
  • Frequently Asked Questions

Resources

  • Join Discord Community
  • Tech Events in Nairobi
  • Masterclasses
  • Free Resources
  • Learn
  • Data Science Guides
  • African Payments Reference
  • Campus
  • Africa Tech Talent Report
  • Partner With Us
  • Start a Project
  • Software & AI Studio
  • Our Work
  • Outcomes

Contact Us

  • 124 Manyani East Road, Lavington, Nairobi
  • +254727795603
  • Book a Discovery Call

Office Hours:

Mon-Fri: 9am - 2pm EAT

Sat: 10am - 12pm EAT

© 2026 Mctaba Labs - A product of Edtech Industries. All rights reserved.

Privacy PolicyTerms of ServiceRefund Policy
  1. Learn
  2. Data Science in Kenya
  3. Machine Learning Explained with a Matatu Route
Bonaventure OgetoBy Bonaventure Ogeto|Updated November 3, 2026

Last checked 3 November 2026

Machine Learning Explained with a Matatu Route

Machine learning means showing a program many past examples so it finds the pattern itself. Here, you give it past matatu trips (hour, day, rain, minutes taken). It learns that rain at 5 PM means slow trips, predicts new ones, you measure its error, and you retrain as roads change.

In this article

  1. 1. Start at the stage, not the code
  2. 2. Step 1: decide what to predict and what to feed it
  3. 3. Step 2: train on some trips, keep some hidden
  4. 4. Step 3: measure how wrong it is
  5. 5. Step 4: retrain when the road changes
  6. 6. What to do with this

Start at the stage, not the code

McTaba runs coding and data bootcamps in Kenya. This guide is written to be useful whether or not you ever join one.

It is 5 PM at the Thika Road stage. A conductor tells you, "Forty minutes to town." It is raining. He is wrong, and you both know it. On a dry Sunday morning the same trip takes twenty.

That conductor is already doing prediction. He has seen hundreds of trips and carries a rough rule in his head: later hours, weekdays and rain make the trip slower. Machine learning is a way to write that rule down from data, instead of keeping it in one person's memory.

Everything below uses made-up numbers. They show the method. They are not real travel times. If you are choosing a career, the data science career guide for Kenya shows where this skill leads.

Step 1: decide what to predict and what to feed it

Every machine learning problem has two parts. The label is the thing you want to predict. The features are the facts you give the model to predict it.

For example, imagine you ride the same route for a month and note each trip. Your label is the minutes taken. Your features are the hour of departure, the day of the week and whether it was raining. Three small features, one label.

Imagine the first rows of your notebook look like this. These numbers are invented for the example.

HourDayRainMinutes (label)
7MondayNo45
7MondayYes62
13WednesdayNo25
17FridayYes75
10SundayNo20

Real work would use hundreds or thousands of rows. Choosing good features is half the job. If you forget to record "schoolchildren on holiday", the model cannot learn from it.

If you want to practise this kind of table-building on real Kenyan data, our Data Science programme in Nairobi starts from Python and pandas and works up to models like this one.

Get weekly developer tips

Join 25,000+ developers. Practical guides, job tips, and new content — straight to your inbox.

No spam. Unsubscribe anytime.

Step 2: train on some trips, keep some hidden

Training means letting the program look at the rows and adjust itself until its guesses come close to the real minutes. The simplest model draws a line: each extra hour toward the evening adds some minutes, and rain adds some more.

Imagine you have 200 trips. You train on 160 and hide 40. The hidden 40 are your test set. The model never sees their minutes while learning. This is like a student who practises on past papers and then sits a paper she has not seen.

Without the hidden set you would fool yourself. A model can memorise its training rows, scoring perfectly on trips it has already seen, and still fail the first morning it meets a new one.

In code, this takes about six lines with a library called scikit-learn. You do not need to follow the code to follow the idea: split the data, fit a model on the larger part, check it on the smaller part. A gentle start on the tools is in the Python for data science guide.

Step 3: measure how wrong it is

Now ask the model to predict the 40 hidden trips and compare with what happened. For example, imagine it said 50 minutes for a Tuesday 8 AM trip that actually took 58. The error is 8 minutes.

Average the size of those errors across all 40 trips. If the average is, say, 9 minutes, you can tell a passenger, "My prediction is usually within about 9 minutes." That sentence is honest and useful. The model need not be perfect to beat the conductor's guess.

Always compare with a dumb baseline. The baseline might be "always say the overall average trip". If your model's error is not clearly below that, the model has learned nothing.

Look at where the errors cluster. Perhaps the model is badly wrong on the day a matatu strike blocks the road, because no feature tells it about strikes. That is not a failure of mathematics. It is a missing feature, and it shows you what to collect next.

Step 4: retrain when the road changes

Roads change. A new bypass opens, a stage moves, a fare war empties the route. A model trained in March describes March. By November it may be off by twice as much.

So you keep a simple routine. Each week, record new trips. Each month, check the model's error on the latest trips. When error creeps up, retrain on fresh data, including recent months, and test again. Teams call this monitoring, and it matters as much as the first model.

This loop (collect, train, test, watch, retrain) is the same whether the model predicts a trip time, a fraud alert on M-Pesa or a customer's chance of repaying a loan. The data and the cost of a wrong guess change. The loop does not.

To see how the same idea applies to money, read mobile money fraud detection with machine learning. To see how the parent field fits together, read AI vs machine learning vs data science.

What to do with this

Try it with paper first. Write 20 of your own trips in a notebook with hour, day, weather and minutes. Guess the next five trips from your own table, then compare. You have just done the whole loop by hand.

When you are ready for the real thing, you need Python, a little statistics and projects with Kenyan data. A first project can be as simple as this one. Our Data Science programme in Nairobi teaches the Machine Learning phase after the data handling and statistics that come before it, then ships a model behind an API or dashboard.

If statistics worries you, statistics for data science explains what you actually need.

Key Takeaways

  • ✓Machine learning learns a pattern from past examples instead of following hand-written rules.
  • ✓Features are the inputs; the label is the answer you predict.
  • ✓Hold back a test set and compare with a simple baseline.
  • ✓Models age, so monitor error and retrain on fresh data.

Frequently Asked Questions

What is a simple example of machine learning?
Predicting a matatu trip time from the hour, day and rain. You give the program past trips, it finds the pattern, and it predicts new trips. You then measure its error.
What are features and labels?
Features are the facts you give the model, such as hour and rain. The label is the answer you want it to predict, such as minutes taken.
Why hold back some data for testing?
To check the model on trips it has never seen. Without a test set you cannot tell whether it learned a pattern or just memorised the rows.
Does a model ever stop being right?
Yes. Roads, prices and customer habits change, so a model needs fresh data and regular checks. Retraining is a normal part of the work.

Learn data science on African data

KES 140,000

Data Science to AI Engineering: 5 months full time or 8 months part time, hybrid in Nairobi. Fraud, credit and M-Pesa data from Week 1, and every model deployed. Starts 11 January 2027.

See the Data Science programme

Related guides

  • Deploy a Machine Learning Model as an API with FastAPI
  • Data Science Interview Questions for Kenya, With Model Answers
  • Best Data Science Courses in Kenya (2026): Fees, Length, Who Each Suits

Keep reading

AI vs Machine Learning vs Data Science: The Difference

Three terms people use as if they mean one thing. Here is what each means, how the jobs differ, and which one a beginner in Kenya should learn first.

Read more

Python for Data Science: Your First 30 Days

Thirty days, four weeks, one small script a week. Learn only the parts of Python that data work uses, with examples on made-up Kenyan shop data.

Read more

The Statistics You Actually Need for Data Science

Five statistics ideas do most of the work in data jobs. Each one comes with a small worked example you can check on paper.

Read more

Catching Mobile Money Fraud with Machine Learning

A fraud model on the public PaySim dataset, judged in shillings lost and wasted alarms rather than a single accuracy score.

Read more

Explore related topics

Breaking Into Tech

Practical, no-nonsense guides for anyone looking to start or change their career in tech. From choosing your first language to acing interviews.

Tech Salary Data

Transparent salary data for tech roles in Africa and worldwide, updated regularly with real market research.

AI Skills & Tools

Practical AI knowledge for developers. Build your first agent, get good at RAG, and pick the right AI coding tools for real work.

Bonaventure Ogeto

Bonaventure Ogeto

Founder and CEO, Mctaba Labs

Software engineer for 8+ years. He runs a Nairobi studio that ships products on M-Pesa, WhatsApp and AI, and teaches what the studio ships. He holds a BSc in Mathematics and Computer Science.

More about the author