Byte by Byte › Book 7: Networks, Programming and Machine Learning › Chapter 14: The AI Project Cycle
Chapter 14: The AI Project Cycle
You will learn: the difference between AI and automation, the six stages of the AI project lifecycle, how to define a problem with the 4Ws canvas, sources of data and how to collect it ethically, data cleaning, formatting and labelling, rule-based and learning-based models, training and testing, accuracy and the confusion matrix, precision and recall, deployment, monitoring and data drift, and how AI is used in India's environment, healthcare, agriculture, transport and education.
🔎 The Case
Nimo had been waiting for this chapter of the adventure for a long time, and it showed. He had arranged the whole desk like a classroom: a whiteboard, coloured pens, and a small stack of index cards with neatly written headings.
"Last year," he said, "you learned what AI is: how it sees, hears, predicts and chats. This year you're going to build one, to solve a real problem. And the first thing every AI engineer learns is that building the model is the smallest part."
He held up six cards. Define the problem. Collect data. Prepare data. Build and train. Evaluate. Deploy and monitor.
"Most AI projects that fail," he said, "fail at card one or card two. Not card four."
Vega looked at the cards. "Card one is easy. The problem is: find the fake clips."
"Is it?" said Nimo. "Find them for whom? How fast? What happens when the AI is wrong? Should it decide, or should it help a person decide?" He smiled. "Card one is never easy."
💡 The Concepts
What is an AI project? In Book 6 you learned that artificial intelligence gives machines the ability to do tasks that normally need human intelligence, such as recognising images, understanding language or making predictions, mostly by learning patterns from data. An AI project is the step-by-step process of building an AI system to solve a real-world problem. The process is called the AI project lifecycle (or AI project cycle). It is iterative: you go round it again and again, improving each time.
┌──────── 1. Define the problem ────────┐ │ ▼ 6. Monitor and maintain 2. Collect data ▲ │ │ ▼ 5. Deploy 3. Prepare data ▲ │ └── 4b. Evaluate and refine ◀── 4a. Build and train
Stage 1: Define the problem. Before anything else, decide exactly what problem you are solving, for whom, and whether AI is really needed.
AI or automation? Many problems do not need AI at all. Automation follows fixed rules written in advance: it does the same thing every time and does not learn. AI learns from data and adapts its decisions to each situation.
| Task | Automation (fixed rules) | AI (learns from data) |
|---|---|---|
| Traffic lights | Change every 30 seconds, whatever the traffic | Adjust green time to the number of vehicles a camera sees |
| Watering a garden | Water every day at 7 a.m. | Water when soil moisture and the weather forecast say it is needed |
| Car wash | Same water, soap and brush time for every car | Cameras judge the car's size and how dirty it is, and adjust |
| Spam filter | Block emails containing a fixed list of words | Learn from millions of emails which features usually mean spam |
If a few simple rules solve the problem reliably, use automation: it is cheaper, easier to explain and easier to test. Use AI when the rules are too many, too fuzzy or too changeable to write by hand, such as recognising faces, understanding speech, or spotting edited video frames.
The 4Ws problem canvas. A good way to define the problem is to answer four questions, often written as a problem statement template:
| W | Question | For the Truth Desk |
|---|---|---|
| Who | Who has the problem? Who are the stakeholders? | Truth Desk checkers; readers deciding whether to forward |
| What | What exactly is the problem? What is the evidence? | Too many new clips to check frame by frame; several are edited |
| Where | Where and when does it happen? | Clips published on the Mirror and forwarded across the Light Bridges, every day |
| Why | Why would solving it help? | Checkers could focus on the most suspicious clips first; fewer fakes spread |
The resulting problem statement: Our Truth Desk checkers have the problem of too many clips to examine by hand, every day, on the Light Bridges. An ideal solution would flag the clips most likely to be edited, so humans can check those first. Notice the solution flags clips for humans. It does not decide what is true.
Stage 2: Collect data (data acquisition). AI learns from examples, so it can only be as good as its data. Computer scientists have a saying for this: garbage in, garbage out.
| Source | Example |
|---|---|
| Sensors | Cameras, microphones, thermometers, soil-moisture and air-quality sensors |
| Surveys | Questionnaires and forms (Chapter 10) |
| Websites and APIs | Public data, news, open-data portals such as data.gov.in |
| Historical records | Past files, reports, sales or exam results |
| Observation | People recording what they see, such as birdwatchers counting species |
Collecting data raises ethical questions, which the CBSE AI curriculum stresses at every stage. Do you have permission (consent) to use it? Does it include personal data that must be protected under the DPDP Act 2023? Is it representative, including all the kinds of cases the AI will meet (Book 5)? Are you allowed to use it under its licence?
For the Truth Desk, the data is frames from video clips, each one labelled real or edited.
Stage 3: Prepare data. Raw data is almost always messy. Data scientists often spend most of a project's time on this stage.
Data exploration comes first: look at the data, count it, and draw charts (Chapter 13) to understand it. How many examples of each label are there? Are any values impossible?
Data cleaning fixes problems:
| Problem | Example | Fix |
|---|---|---|
| Missing values | A frame with no label | Find the label, or remove the row |
| Duplicates | The same frame saved twice | Remove the copies, or the model will over-learn them |
| Incorrect values | A real frame labelled edited by mistake | Check and correct |
| Irrelevant data | Frames of the Mirror's logo | Remove: they do not help with the question |
| Outliers | One frame a thousand times brighter than the rest | Check whether it is an error |
Data formatting puts everything into the same form: the same image size, the same date format, text converted to numbers where needed. Data labelling (or annotation) attaches the correct answer to each example, such as spam or not spam, plastic or paper, real or edited. Labelling is often done by people, and its quality decides the AI's quality.
Finally the data is split into two sets:
- Training data (often about 80%): used to teach the model.
- Test data (about 20%): kept completely separate, and used only to check the finished model on examples it has never seen (Book 6).
Testing on the training data is like letting students see the exam paper in advance. A model that does well on training data but badly on new data has memorised instead of learning. This is called overfitting, and you will see it again in Chapter 15.
Stage 4a: Build and train the model. A model is the part of an AI system that turns inputs into outputs (predictions). It is often compared to the brain of the system. There are two broad approaches:
- A rule-based model uses rules written by people: if a frame's edge pixels jump more than 20 pixels between frames, flag it. This is closer to automation; it is clear, but brittle.
- A learning-based model (machine learning) works out its own rules from the labelled training data. You give it thousands of labelled frames, and it finds the patterns that separate real from edited.
Learning from labelled examples is supervised learning, which you met in Book 6, along with unsupervised and reinforcement learning. Most school projects, and the Truth Desk's detector, use supervised learning. The process of the model adjusting itself to fit the training data is called training. Chapter 15 opens up two kinds of model, decision trees and neural networks, to see how training works inside.
No-code AI tools. You do not have to write code to build a model. Teachable Machine (teachablemachine.withgoogle.com, used in Books 4 and 6) and Machine Learning for Kids (machinelearningforkids.co.uk) let you collect and label examples, train a model in your browser, and test it, with a few clicks.
Stage 4b: Evaluate and refine. Evaluation tests the model on the test data and measures how well it performs.
Accuracy is the percentage of predictions that are correct:
accuracy = (correct predictions ÷ total predictions) × 100%
If a model correctly labels 87 of 100 test clips, its accuracy is 87%.
But accuracy alone can hide serious problems. Suppose 80 of the 100 test clips are real and only 20 are edited. A lazy model that always says real gets 80% accuracy, and catches none of the fakes. To see what is really going on, use a confusion matrix, a table comparing what the model predicted with what was actually true. One class is chosen as the positive class: here, edited (the thing we are looking for).
| Actually edited | Actually real |
|---|
| Predicted edited | True positive (TP): a fake correctly flagged — 15 | False positive (FP): a real clip wrongly flagged — 8 |
|---|---|---|
| Predicted real | False negative (FN): a fake that was missed — 5 | True negative (TN): a real clip correctly passed — 72 |
From these four numbers:
- Accuracy = (TP + TN) ÷ total = (15 + 72) ÷ 100 = 87%.
- Precision = TP ÷ (TP + FP) = 15 ÷ 23 = 65%. Of the clips it flagged, how many really were fakes?
- Recall = TP ÷ (TP + FN) = 15 ÷ 20 = 75%. Of all the fakes, how many did it catch?
Which mistakes matter more depends on the problem. A model that screens for a serious disease should have very high recall: missing a sick patient (a false negative) is far worse than a false alarm, which a doctor will check. A spam filter needs high precision: a real email lost in the spam folder (a false positive) can be a real problem. For the Truth Desk, a false positive means a checker wastes a few minutes; a false negative means a fake spreads. So the team wanted high recall, with humans checking everything flagged.
Refining the model when results are not good enough: collect more (and more varied) data, fix incorrect labels, balance the classes, change the model's settings, then train and test again. This loop is why the lifecycle is a cycle.
Stage 5: Deploy. Deployment means putting the model to work in the real world: inside an app, a website, a camera, a hospital system. The model receives new inputs and makes predictions for real users. It is graduation day for the AI. Examples you use daily: spam detection, face unlock, voice assistants, recommendations in shopping and video apps, and translation.
Good deployment also decides how the AI's output is used: who sees it, what happens when it is wrong, and how a person can challenge its decision. The Truth Desk shows a flag with a confidence score and the words Flagged for human checking, never FAKE.
Stage 6: Monitor and maintain. The world changes after a model is deployed. Monitoring keeps checking whether it still works. Maintenance updates it when it does not. A common reason for a model getting worse over time is data drift: the new data it meets no longer looks like the data it was trained on. Exam patterns change, new slang appears, and people trying to fool a detector change their methods. A model that was 87% accurate in testing can quietly become much worse. The fix is new data, retraining, and testing again: back round the cycle.
AI and its applications in India. The CBSE AI curriculum highlights AI that helps solve real problems. A few examples:
| Area | How AI helps | Indian examples |
|---|---|---|
| Environment | Satellite images and sensor data to spot plastic dumps, deforestation and pollution; air-quality forecasts | Satellite mapping of plastic dumps in Himachal Pradesh; Forest Survey of India monitoring forest cover; AI-based air-quality forecasting in several cities |
| Wildlife | Camera traps that recognise animals and send alerts | AI camera traps in tiger reserves |
| Healthcare | Reading medical images; predicting health risks; health chatbots | AI tools validated by ICMR that read chest X-rays to screen for tuberculosis |
| Agriculture | Crop disease detection from photos, weather and soil advice | Government crop-photo and advisory platforms for farmers in their own languages |
| Transport | Signals that adapt to traffic; detecting traffic offences; navigation | Adaptive traffic signals in cities such as Bengaluru and Delhi |
| Education | Instant feedback, personalised practice, translation of lessons | DIKSHA and SWAYAM learning platforms |
| Waste | Sorting machines that recognise plastic, metal and organic waste | AI-assisted waste sorting in cities such as Indore and Pune |
Each of these went round the same cycle: a clearly defined problem, carefully collected and cleaned data, a model, honest evaluation, careful deployment, and continuous monitoring.
Think About It: A school wants to deploy an AI that predicts which students will score below 75% in the final exam, using attendance, study hours and test marks, so teachers can offer extra help. What could go well? What could go wrong if the predictions are shown to students, or used to decide who gets into an advanced class? Who should be able to see the predictions?
Career Spotlight: Machine learning engineer and data scientist. Data scientists explore and clean data and find what it can and cannot tell us. Machine learning engineers build, evaluate, deploy and monitor models. In India, both jobs are growing fast in healthcare, agriculture, finance and government services.

🛠️ Build It
Activity 1: AI or automation? Sort these into automation (fixed rules are enough) and AI (learning from data is needed), and give a reason for each: a lift that stops at the floor you press; a phone that unlocks when it recognises your face; an alarm clock; an app that suggests the next word as you type; a washing machine with a fixed timer; a system that reads number plates at a toll booth; a streetlight that turns on at 6 p.m.; a system that predicts tomorrow's air quality.
Activity 2: Your problem canvas. Choose a real problem in your school or neighbourhood that AI might help with (for example: sorting school waste, predicting when the canteen will run out of food, recognising bird species in the school garden, identifying unhealthy plant leaves). Fill in the 4Ws table and write a one-sentence problem statement. Then answer: could simple automation solve it instead?
Activity 3: Build a waste classifier in Teachable Machine. This follows the CBSE Class 8 activity.
- Define: we want a model that recognises plastic, paper and organic waste from a camera image.
- Collect: with a grown-up's permission, take 20 to 30 photos of each type (bottles and wrappers; newspapers, notebooks and cardboard; fruit peels, vegetable scraps and dry leaves). Vary the background, lighting and angle.
- Prepare: delete blurry, duplicate or mislabelled photos. Keep 5 of each type aside in a separate folder as your test set; do not use them for training.
- Build: open teachablemachine.withgoogle.com, click Get Started → Image Project → Standard image model. Rename the classes
Plastic,PaperandOrganic, and click Upload on each class to add its training photos. Click Train Model and wait. - Evaluate: in the Preview panel, switch the input to File and upload each of your 15 test photos one at a time. Record each prediction and its confidence in a table. Then build a 3 × 3 confusion matrix (actual class down the side, predicted class across the top) and calculate the accuracy.
- Refine: which class was confused most? Add more varied photos of that class, retrain and test again. Did the accuracy improve?
- Reflect: what happens when you show it something that is none of the three, such as your hand? Why? (The model must always choose one of the classes it knows.)
Activity 4: Calculate evaluation measures in Python. Save as evaluate.py :
def evaluate(actual, predicted, positive="fake"):
"""Compare two lists of labels and return a dictionary of results."""
tp = fp = fn = tn = 0
for a, p in zip(actual, predicted):
if p == positive and a == positive:
tp = tp + 1
elif p == positive and a != positive:
fp = fp + 1
elif p != positive and a == positive:
fn = fn + 1
else:
tn = tn + 1
total = tp + fp + fn + tn
return {
"TP": tp, "FP": fp, "FN": fn, "TN": tn,
"accuracy": (tp + tn) / total,
"precision": tp / (tp + fp) if tp + fp > 0 else 0,
"recall": tp / (tp + fn) if tp + fn > 0 else 0,
}
actual = ["fake", "real", "real", "fake", "real", "fake", "real", "real", "fake", "real"] predicted = ["fake", "real", "fake", "real", "real", "fake", "real", "real", "fake", "real"]
results = evaluate(actual, predicted)
for key, value in results.items():
if isinstance(value, float):
print(f"{key}: {value:.0%}")
else:
print(f"{key}: {value}")
Output:
TP: 3 FP: 1 FN: 1 TN: 5 accuracy: 80% precision: 75% recall: 75%
( zip() walks through two lists side by side, pairing their items. tp = fp = fn = tn = 0 sets all four to 0 at once. {value:.0%} shows a decimal as a percentage with no decimal places. isinstance(value, float) checks whether a value is a decimal number.)
Now test the lazy model: print(evaluate(actual, ["real"] * len(actual))) . What are its accuracy and recall? What does this tell you about using accuracy alone?
Activity 5: Deployment plan. For your Activity 2 problem, write a short deployment and monitoring plan: who will use the AI, where its prediction will appear, what a user should do if it is wrong, how you will check each month that it still works, and what would make you switch it off.
Unplugged: Human classifier. One person is the "model". Show them 10 "training" picture cards of two kinds of leaf, each labelled. Then show 10 unlabelled "test" cards and record their guesses. Fill in a confusion matrix and calculate the accuracy. Then repeat with a new person, but give them training cards of only one kind of leaf plus two of the other. What happens to their recall for the rare kind? This is the effect of unbalanced data.
✅ Case Closed
They went round the cycle together. Nimo made them write the problem canvas twice, until it said flag for humans instead of find fakes. Frost and Ribbit gathered 6,000 frames: from the Mirror's clips, and from real recordings of Simbha that the palace and the Times had filmed over the years, with permission. Beautine took charge of cleaning, with terrifying efficiency: she deleted 214 duplicates, sent 37 frames with missing labels back for checking, and discovered that 90 "real" frames had been mislabelled, because they came from a clip the Times had itself once edited for length.
The first model, trained on Teachable Machine, scored 91% accuracy on the test set. Pip wanted to celebrate. Memoon drew the confusion matrix first.
Its recall was only 40%. There were far more real frames than edited ones in the data, and the model had learned that guessing real was usually right. It was catching fewer than half of the fakes.
They balanced the data, gathering more edited examples, and retrained. Accuracy dropped slightly, to 88%. Recall rose to 83%. "A model that is less accurate," said Vega, "and much more useful. I'd never have believed it."
The detector, which Pip insisted on calling Mirror Catcher, went live on the Truth Desk the next morning. Every new clip from the Mirror was scored, and the most suspicious ones went to the front of the checkers' queue.
For two days it worked beautifully. On the third day, its flags dropped almost to nothing. Five new clips came out of the Mirror, and Mirror Catcher passed every one as real.
Memoon looked at them frame by frame. The flicker in the mane was gone. The edges were clean. The voices were smoother. Whoever was making the clips had improved their method.
"Data drift," said Nimo quietly. "Or rather, someone is drifting it on purpose. They know they're being watched."
Memoon stared at the screen. "Then we need to understand what our model is actually looking at, inside," she said. "And we need to understand how their model makes a lion talk."
❓ Test Yourself
- What is the difference between AI and automation? Give an example of each from your home.
- Name the six stages of the AI project lifecycle in order. Why is it called a cycle?
- What are the 4Ws of the problem canvas? Fill them in for an AI that predicts when a school's water tank will run dry.
- Name four sources of data. Give two ethical questions to ask before collecting data.
- What do data cleaning, data formatting and data labelling mean? Give an example of each.
- Why must test data be kept separate from training data?
- What is the difference between a rule-based model and a learning-based model?
- A model tested on 50 emails gets 44 right. What is its accuracy?
- In a confusion matrix for a disease-screening AI, what are a false positive and a false negative? Which is more dangerous, and why?
- A detector has TP = 12, FP = 3, FN = 8, TN = 77. Calculate its accuracy, precision and recall.
- Why can a model with 90% accuracy still be a bad model?
- What is data drift? Give an example.
- Give one example each of AI being used in India for the environment, healthcare and agriculture.
- Challenge: Plan a complete AI project for one problem in your community, following all six stages. For each stage, write what you would do, what could go wrong, and one ethical check.
📚 Key Terms
- AI project lifecycle: the six iterative stages of building an AI system.
- Automation: a system that follows fixed rules and does not learn.
- Problem statement: a clear description of the problem an AI project will solve.
- 4Ws canvas: Who, What, Where and Why questions for defining a problem.
- Stakeholder: anyone affected by a project.
- Data acquisition: collecting the data a project needs.
- Consent: permission to collect or use someone's data.
- Representative data: data that includes all the kinds of cases the AI will meet.
- Data exploration: examining data to understand it before using it.
- Data cleaning: fixing missing, duplicate, incorrect and irrelevant data.
- Data labelling (annotation): attaching the correct answer to each example.
- Training data / test data: data used to teach a model / data kept back to check it.
- Model: the part of an AI system that turns inputs into predictions.
- Rule-based / learning-based model: a model using human-written rules / rules learned from data.
- Training: the process of a model adjusting itself to fit the training data.
- Overfitting: memorising the training data instead of learning general patterns.
- Accuracy: the percentage of predictions that are correct.
- Confusion matrix: a table comparing predictions with actual results.
- True / false positive, true / false negative: the four kinds of result in a confusion matrix.
- Precision: of the items flagged, the fraction that were really positive.
- Recall: of all the real positives, the fraction that were found.
- Deployment: putting a model to use in the real world.
- Monitoring and maintenance: checking and updating a deployed model.
- Data drift: changes in real-world data that make a model less accurate over time.
Keep learning with Byte by Byte
Explore Book 7: Networks, Programming and Machine Learning. Find the ebook, purchase details and teaching slides on MemuniCity.
Comments
Post a Comment