Chapter 18: Data Modelling and Evaluation
Every morning before the first bell, the canteen in Meera’s school has to decide one thing: how many bottles of chilled buttermilk to prepare. Get it wrong in one direction and the bottles sit unsold till evening. Get it wrong in the other and the queue at lunch goes away empty-handed.
The canteen in-charge keeps a small notebook. For each day she writes down two things — the highest temperature that day, and how many bottles were sold. After a few weeks the notebook has a story in it. On cool days the number is small. On hot days it is large. Nobody wrote a rule saying so. The pattern was simply there, waiting in the numbers.
Now the useful question. Tomorrow’s forecast says it will be hot. Can those old numbers tell her how many bottles to prepare — for a day that has not happened yet?
That is what this chapter is about: turning collected data into something that can answer a question about the future.
Diagram
Fig. 18.0-1 – a school canteen counter on one side and an open notebook on the other; the notebook page shows two columns headed “Temperature” and “Bottles sold” with a few rows filled in, and a dotted arrow leads from the notebook to a question mark above the next day’s empty row
Each of these five questions is answered somewhere in this chapter, at the point where the idea behind it has been explained.
18.1 Why a Computer Needs a Model
Think about the globe kept in your school library. It is not the Earth. It is much smaller, it is made of plastic, and it leaves out almost everything. Yet you can use it to work out which countries the equator passes through. A small, simplified stand-in has answered a question about the real thing.
Computers work the same way. When we want a computer to answer a question about the real world, we do not hand it the real world. We hand it a simplified stand-in built from numbers.
Data alone does not answer a question
By the end of Class 9 you had already met the idea of data — the raw facts and figures collected about something, such as temperatures, marks, or the number of items sold. Collecting data is where every project starts. But a table of collected data is only a record of things that have already happened.
Look back at the canteen notebook from the start of this chapter. It faithfully records what happened on every past day. It does not contain a row for tomorrow, because tomorrow has not happened. No amount of reading the old rows will produce that missing row.
So the notebook is not enough on its own. What is needed is something built from those rows that can take a fresh piece of information — tomorrow’s expected temperature — and turn it into an answer.
The stand-in we build from data
That something is called a model. A model is a simplified description of a pattern found in data, built so that it can be given a new input and produce an output.
Two ordinary words are worth pinning down here. An input is whatever you feed into the model — a temperature, a photograph, a set of marks. An output is what it gives back — a number, a label, or a group.
What a model is not
A model does not know anything, and it does not understand the situation. It carries out a calculation that was fitted to past data, and nothing more. A model built only from summer readings has never seen a cold day, and it will still confidently produce a number if you ask it about one.
This is the honest limitation to keep in mind through the whole chapter. A model is only as trustworthy as the data it was built from, and it has no way of telling you when it has been pushed beyond what it has seen.
18.2 What Data Modelling Means
A tailor does not begin by cutting cloth. He first takes measurements, decides which measurement matters for which part of the garment, and then makes a paper pattern. The paper pattern is not the shirt, but every shirt he stitches afterwards comes out of it.
Building a model works in much the same order. The step in which the pattern is chosen and fitted to the collected data has its own name.
Data modelling is the process of choosing a suitable method and fitting it to collected data, so that the result can be used to answer a question about a new case.
Notice that the word describes an activity, not a thing. The activity is data modelling. The thing it produces is the model.
18.2.1 From Raw Data to a Working Model
In earlier chapters you scoped a problem, acquired data, and explored it with graphs. Modelling is the step that follows. It takes the tidy, explored data and turns it into something that can produce answers.
The first job is to decide which columns of the data do which work. Suppose a farmer near Bharatpur has recorded, for each of his fields, the amount of rainfall that season, the amount of fertiliser used, and the weight of the crop harvested.
Two of those columns describe the conditions. One of them is the thing he actually wants to know in advance. A feature is an input column, one of the facts we already have about a case. The target is the output column, the thing the model is meant to produce. Here rainfall and fertiliser are the features, and the weight of the crop is the target.
Once features and target are fixed, modelling has three parts. See Fig. 18.2-1.
Diagram
Fig. 18.2-1 – a left-to-right flow with four labelled blocks: “Explored data” → “Choose features and target” → “Fit a method to the data” → “Model”; below the last block a small side arrow labelled “new input” enters it and an arrow labelled “output” leaves it
First, a method is chosen — a straight line, a set of rules, or a learning algorithm. Second, the method is fitted, which means its adjustable parts are set to the values that match the collected data most closely. Third, the fitted method is kept and used on new inputs.
18.2.2 The Three Ways of Building a Model
There is no single way to build a model. The approach depends on what kind of answer is wanted and on how much reliable data is available.
Three approaches are used in artificial intelligence, and this chapter takes them one at a time. Fig. 18.2-2 shows them together.
Diagram
Fig. 18.2-2 – a single box labelled “Data modelling” at the top, with three arrows branching down to three boxes labelled “Predictive approach”, “Rule based approach” and “Learning based approach”; under each box a one-line caption reads “predicts a number”, “follows written rules” and “finds the pattern itself”
The predictive approach uses past data to work out a value that is not yet known, such as a quantity or a price. Its most common method is linear regression, which you meet in the next section.
The rule based approach does not search the data for a pattern at all. A person who knows the subject writes the rules, and the computer follows them exactly as written.
The learning based approach is the opposite. Nobody writes the rules. The method is shown a large amount of past data and adjusts itself until it matches that data, and the pattern it settles on is whatever the data suggested.
18.3 Prediction – Linear Regression
Some questions ask for a label: is this fruit an apple or a pineapple? Other questions ask for a quantity: how many bottles, how many rupees, how many kilograms? The predictive approach is used when the answer wanted is a quantity.
The simplest and most widely used method for this is linear regression. It answers a quantity question by finding a straight line that runs through past data, and then reading the answer off that line.
The name is worth unpacking once. “Linear” means the pattern is described by a straight line. “Regression” is the old statistical word for working out how one quantity moves with another.
18.3.1 Spotting a Straight-Line Relationship
Before fitting any line, you have to be sure a line is a sensible shape for the data. Otherwise you are forcing a shape onto numbers that do not have it.
Here is the canteen’s record, tidied up into a table. Each row is one day. Table 18.1 shows the highest temperature recorded that day and the number of bottles sold.
Reading the rows top to bottom, the second column climbs steadily as the first column climbs. That steady climb is the clue. Plotting the rows as points makes it obvious — see Fig. 18.3-1.
Diagram
Fig. 18.3-1 – a scatter plot with “Highest temperature (°C)” on the x-axis marked from 22 to 40 and “Bottles sold” on the y-axis marked from 40 to 140; the eight rows of Table 18.1 shown as dots, which lie close to but not exactly on a straight rising line
The dots do not sit on one perfect line. Real records never do, because plenty of other things affect sales. But they lie close enough to a rising line for a line to be a fair description of the pattern.
Here the feature is the temperature and the target is the number of bottles. The temperature is known the evening before, from the forecast. The bottle count is not, which is exactly why it is worth predicting.
18.3.2 Slope, Intercept and the Line of Best Fit
Any straight line can be written with just two numbers:
\[y = mx + b\]
Here \(x\) is the feature, \(y\) is the predicted value of the target, \(m\) is the slope and \(b\) is the intercept. The slope says how much \(y\) changes when \(x\) goes up by one. The intercept says where the line would cut the vertical axis, that is, the value of \(y\) when \(x\) is zero.
Change either number and you get a different line. So fitting a line to data means choosing the pair of numbers that places the line as close as possible to all the recorded points at once.
How “as close as possible” is measured
For any candidate line, take each recorded point and measure the gap between the actual value and the value the line gives. Those gaps are the errors. The line that makes the errors smallest overall is kept, and it is called the line of best fit.
Software does this arithmetic. For the eight rows of Table 18.1, the best-fitting line comes out as
\[y = 6x - 100\]
That is, a slope of 6 bottles per °C and an intercept of −100 bottles.
The slope is the useful half. It says that one degree of extra heat goes with about six more bottles sold. Table 18.2 checks the line against the record it came from.
The line is never exactly right, and it is never far wrong either. Being off by two bottles on a day when about a hundred are sold is a small enough error for the canteen to work with.
18.3.3 Using the Line to Predict
Once the slope and intercept are fixed, prediction is just substitution. The model is asked a question by putting a new value of \(x\) into the equation.
The canteen in-charge would not prepare exactly 134. She would round to a convenient number and keep a small margin, because Table 18.2 already showed the line runs about two bottles off either way.
Where the line stops being trustworthy
Substitution will happily give you an answer for any number you put in. Ask the model about 55 °C and it returns 230 bottles without hesitating.
But no day in Table 18.1 was anywhere near 55 °C. The model has no evidence that the same steady climb continues that far, and in reality it would not — the school itself would be shut. Using a fitted line outside the range of the data it was built from is the commonest way to get a confident, useless number.
18.4 Rule Based Approach
Not every question needs data to answer it. Think of how your school turns marks into a grade. Anyone above ninety gets the top grade, anyone between eighty and ninety gets the next one, and so on down the list. No pattern has to be discovered here, because the pattern was decided by people and written down before any student sat the exam.
Whenever the correct answer is already known and can be stated in words, there is no sense in making a computer search for it. You simply write the rules and let the computer follow them.
18.4.1 Writing the Rules
Every rule in such a system has the same shape: a condition, and an action to take when that condition holds. This is usually called an if-then rule, and you have already written many of them in Python without calling them that.
Consider a stationery shop near a school that gives a discount on larger bills. The owner decides the policy herself. Bills of ₹1000 or more get ten per cent off, bills of ₹500 or more get five per cent off, and smaller bills get nothing.
The order of checking matters more than it looks. A bill of ₹1200 satisfies both the first condition and the second one. Because the larger condition is tested first, it gets the ten per cent it should.
Who writes the rules
The rules come from someone who knows the subject well — the shop owner here, a bank officer in a bank, an engineer in a factory. That knowledge is then written into conditions the computer can test. The computer supplies no judgement of its own; it supplies speed and consistency.
Because of this, a rule based system is deterministic, which means the same input always produces the same output, every single time. Run the ₹1200 bill through it a thousand times and you get ₹1080 a thousand times.
What rules cannot do
A rule based system only knows what somebody thought to write down. It handles a situation nobody anticipated by doing nothing sensible at all.
There is a second limit. Rules are easy to manage while there are ten of them. A system with several thousand rules, written by different people over several years, becomes very hard to change safely, because no one can be sure which other rule a small edit will disturb.
18.4.2 Where Rule Based Systems Are Used
Rule based systems suit any setting where the policy is fixed, the reasoning must be open to inspection, and there is little or no past data to learn from.
Fraud detection. Banks flag transactions that break conditions known to be suspicious — for example, a card used for several large withdrawals in different cities within a few minutes. Nothing about that has to be learned. It is written as a rule and the transaction is held for checking.
Business process automation. Routine office decisions that follow a fixed policy can be handed to a rule based system — checking whether an application carries every required document, or whether a claim falls within the limits of a policy.
Recommendation. A simple online store can suggest related items with plain rules: someone buying a laptop is shown laptop bags, someone buying a printer is shown ink cartridges. The suggestions are sensible without any pattern having been learned from customers.
18.5 Learning Based Approach
Try to write down, in words, the rule you use to tell a ripe mango from an unripe one. You will get as far as colour and firmness, and then run out. Some ripe mangoes stay green. Some unripe ones look yellow in the right light. You can do it in half a second, and you cannot explain how.
This is where the rule based approach runs out of road. The rule cannot be written because nobody can state it. But there is another way in: you can easily collect a thousand mangoes and say which ones are ripe.
That is the shift the learning based approach makes. Instead of supplying the rule, you supply the examples, and the pattern is worked out from them.
18.5.1 How a Model Learns from Data
The word “learning” is doing a lot of quiet work here, so it is worth saying exactly what happens. Nothing is understood. Numbers are adjusted.
The process is called training, and it repeats one small loop many thousands of times. The model is given a past example whose correct answer is known. It produces its own answer. The two are compared, and the gap between them is the error. The model’s internal numbers are then nudged in the direction that would have made that error smaller.
One pass over one example changes very little. Millions of passes over thousands of examples settle the numbers into values that work across the whole collection.
You have already seen this in Section 18.3. Fitting a slope and an intercept by making the total error as small as possible is the same idea, with only two numbers to adjust instead of thousands.
The point of all this is not to get the training examples right. It is to generalise — to give sensible answers on new cases the model has never been shown. A model that gets the training examples right and new cases wrong has learned nothing useful.
The honest limitation of the whole approach follows from how it works. A learning based model needs a large amount of good past data, and it cannot tell you which rule it settled on. You can see what it outputs, not why.
There are three main kinds of learning based approach, and they differ in what the past data contains.
18.5.2 Supervised Learning
Go back to the mangoes. Suppose a fruit trader photographs a thousand mangoes and, for each photograph, writes down “ripe” or “unripe” after checking it himself.
That written answer attached to each example is called a label, and a collection of examples that carries labels is a labelled dataset. Training a model on such a dataset is called supervised learning. The name comes from the labels acting like a teacher: for every example, the correct answer is available for comparison.
Training works exactly as described in 18.5.1, with the label supplying the correct answer at step 4. Fig. 18.5-1 shows the two stages.
Diagram
Fig. 18.5-1 – two stacked panels. Upper panel labelled “Training”: a stack of mango photographs, each tagged “ripe” or “unripe”, feeding into a box marked “model”, with a return arrow labelled “adjust to reduce error”. Lower panel labelled “Use”: a single new untagged photograph entering the same box, now marked “trained model”, with one arrow out carrying the output “ripe”
When the label is one of a fixed set of categories, the task is called classification, and the model’s job is to put each new case into the right category. Ripe or unripe, spam or not spam, and the digit written in a box on a form are all classification tasks.
When the label is a quantity instead of a category, the task is prediction of a number — which is what linear regression does. This is why linear regression counts as supervised learning too: every day in Table 18.1 came with its correct bottle count attached.
18.5.3 Unsupervised Learning
Labels are not always available. A shop’s billing counter records what every customer bought, but no one has ever written down what kind of customer each one is. There are no categories, because nobody has decided what the categories should be.
Unsupervised learning is used when the data carries no labels at all. The model is given the input data on its own and asked to find whatever structure is already in it.
The commonest form is clustering, in which the model groups examples that resemble one another and separates those that do not. Fig. 18.5-2 shows the idea.
Diagram
Fig. 18.5-2 – on the left, a scattered mix of unlabelled shapes; an arrow through a box marked “clustering” leads to the right, where the same shapes now sit inside three circles, each circle holding shapes that are similar to one another
Run this on the shop’s billing records and three groups might emerge — customers who buy only stationery, customers who buy mostly snacks, and customers who buy a little of everything. The model does not name these groups. It reports that three distinct patterns of buying exist and which customer belongs to which. Naming them, and deciding what to do about them, is the shopkeeper’s job.
18.5.4 Reinforcement Learning
There is a third situation, different from both. Think of learning to ride a cycle. Nobody labelled each movement as correct or wrong. You tried things, and staying upright was its own signal.
Reinforcement learning works this way. The learner, called the agent, acts inside an environment, and after each action it receives a reward — a number saying how well that turned out. Over many attempts it settles on the actions that earn the most reward in the long run.
The loop is shown in Fig. 18.5-3.
Diagram
Fig. 18.5-3 – a closed loop between two boxes labelled “Agent” and “Environment”; an arrow from agent to environment labelled “action”, and two arrows back from environment to agent labelled “state” and “reward”
Reinforcement learning suits problems where the answer is a sequence of decisions rather than a single output, and where the effect of a decision only shows up much later.
18.5.5 Rule Based and Learning Based Compared
Neither approach is better in general. Each fits a different kind of problem, and the choice is made by looking at what you have and what you need.
18.6 Evaluating the Model
A model that has just finished training is not yet a model anybody should use. It is a candidate. Before it is allowed to decide anything, somebody has to find out how often it is right, and how wrong it is when it is wrong.
That checking step is called evaluation, and it is the last part of the AI project framework.
18.6.1 Training Data and Testing Data
Suppose a teacher gives the class twenty questions to practise, and then sets exactly those twenty questions in the test. Everyone scores well. Nobody learns anything about who understood the subject.
Testing a model on the same data it was trained on has the same flaw. The model was adjusted, example by example, until it matched that data. Of course it matches it. That score tells you nothing about a case it has never met.
So the collected data is split into two parts before training begins. The training data is the portion used to fit the model. The testing data is a portion set aside, never shown during training, and used only at the end to measure performance. Fig. 18.6-1 shows the split.
Diagram
Fig. 18.6-1 – a single long bar labelled “All collected data” divided into a large left part labelled “Training data” and a smaller right part labelled “Testing data”; an arrow from the left part leads to a box marked “training”, and an arrow from the right part leads to a separate box marked “evaluation”, with a dashed line and a cross showing that testing data never enters the training box
Most of the data goes into training, because more examples make for a better fit. A useful working split is around four-fifths for training and one-fifth for testing, though the exact proportion varies with the size of the dataset.
18.6.2 Measuring How Well a Model Works
What counts as “well” depends on what the model produces. A model that outputs a category is measured differently from one that outputs a quantity.
Measuring a model that outputs a category
For classification the natural measure is accuracy — the share of test cases the model got right, usually written as a percentage.
\[\text{accuracy} = \frac{\text{number of correct predictions}}{\text{total number of predictions}} \times 100\]
Table 18.5 shows the trader’s ripeness model run on ten photographs it had never seen during training.
Measuring a model that outputs a quantity
Accuracy makes no sense for a quantity, because a prediction of 134 bottles against an actual 133 is not simply “wrong”. What matters is the size of the gap.
So the errors themselves are measured. Take the gap between predicted and actual for each test case, ignore whether it is above or below, and average them. For the eight days checked in Table 18.2, every gap was 2 bottles in size, so the average gap is 2 bottles. Whether that is good enough is a decision for the canteen, not for the mathematics.
Why one number is never the whole story
A high accuracy figure can hide a useless model. Imagine a factory where 95 out of every 100 parts are fine and 5 are faulty. A model that simply answers “fine” every single time, without looking at anything, is right 95 times out of 100. Its accuracy is 95 per cent, and it catches not one faulty part.
So accuracy has to be read alongside what the test set contained. When one category is far commoner than the other, a good score on the common category can drown out complete failure on the rare one — and the rare one is usually the case you built the model to catch.
18.6.3 Overfitting and Underfitting
When a model does poorly, there are two opposite ways it can have gone wrong, and the cures are opposite too.
Overfitting happens when a model matches its training data very closely but performs poorly on new data. It has fitted the accidental details of those particular examples — the noise — instead of the pattern underneath. The tell-tale sign is a very high score on training data and a much lower one on testing data.
Underfitting is the reverse. The model is too simple to capture the pattern at all, so it performs poorly on both the training data and the testing data. Fitting a straight line to data that clearly curves would underfit it.
Fig. 18.6-2 shows all three cases on the same set of points.
Diagram
Fig. 18.6-2 – three small scatter plots side by side, each showing the same set of dots. In the first, labelled “Underfitting”, a flat straight line misses most of the dots. In the second, labelled “Good fit”, a gently curving line passes near all of them. In the third, labelled “Overfitting”, a wildly wiggly line passes exactly through every dot
Once the model has been evaluated and the scores are acceptable, it can be put to use. If they are not, the work goes back a step — to a different method, a better set of features, or more data — and the whole cycle runs again.
18.7 Summary
- A record of past data only describes what has already happened. To answer a question about a new case, a model is needed — a simplified description of the pattern in the data that turns an input into an output.
- Data modelling is the activity of organising data and fitting a method to it. The model is what that activity produces.
- Within the data, a feature is an input column and the target is the output column the model is meant to produce.
- Three approaches are used: the predictive approach, the rule based approach and the learning based approach.
- Linear regression is the commonest predictive method. It fits a straight line, written as \(y = mx + b\), where the slope \(m\) says how much the target changes for a one-unit change in the feature, and the intercept \(b\) positions the line.
- The line of best fit is the one that leaves the smallest total error across all the recorded points. A prediction is made by substituting a new feature value into the equation.
- A fitted line should not be used outside the range of the data it was built from, and the intercept has a real meaning only if a feature value of zero is covered by that data.
- In the rule based approach, a person who knows the subject writes if-then rules and the computer applies them exactly as written. Such systems are deterministic, easy to inspect, and need little data.
- Rule based systems cannot handle a situation nobody wrote a rule for, and become hard to manage once the rules run into thousands. They are used for fraud alerts, routine office decisions and simple recommendations.
- In the learning based approach nobody writes the rule. Training repeats a loop of predicting, measuring the error and adjusting the model’s internal numbers, until the error over the whole set stops falling.
- The aim of training is to generalise — to work on new cases, not merely to match the training examples.
- Supervised learning trains on a labelled dataset, where every example carries its correct output. Classification is the supervised task of placing a case into one of a fixed set of categories.
- Unsupervised learning works on data with no labels and looks for structure already present, most often by clustering similar examples together. It does not name the groups it finds.
- Reinforcement learning has an agent act inside an environment and receive a reward after each action, so that actions leading to better rewards become more likely.
- Data is split before training into training data, used to fit the model, and testing data, kept back and used once at the end to measure performance.
- Accuracy — the share of test cases the model gets right — measures a model that outputs a category. A model that outputs a quantity is measured by the average size of its errors.
- A single score can mislead. When one category is far commoner than the other, a high accuracy can hide complete failure on the rare category.
- Overfitting means the model matches its training data closely but does poorly on new data. Underfitting means the model is too simple and does poorly on both. The gap between the training score and the testing score is what tells them apart.
18.8 Key Terms
Accuracy – the share of test cases a model gets right, usually written as a percentage.
Agent – in reinforcement learning, the learner that acts inside an environment and receives rewards.
Classification – a supervised task in which the model places each case into one of a fixed set of categories.
Clustering – grouping examples that resemble one another, without being told what the groups are.
Data – the raw facts and figures collected about something.
Data modelling – the process of organising data and fitting a method to it, so the pattern can produce an output for a new input.
Deterministic – always producing the same output for the same input.
Feature – an input column of the data, a fact already known about a case.
Generalise – to give sensible answers on new cases the model was never trained on.
Input – whatever is fed into a model.
Intercept – the number \(b\) in a straight line, giving the value of \(y\) where the line crosses the vertical axis.
Label – the correct output written against a training example.
Labelled dataset – a collection of examples in which every example carries its correct output.
Learning based approach – building a model by letting a method work the pattern out from past data instead of being told it.
Line of best fit – the straight line that leaves the smallest total error across all the recorded points.
Linear regression – a modelling method that fits a straight line to past data so a target can be predicted from a feature.
Model – a simplified representation of the pattern in a set of data, which turns a new input into an output.
Output – what a model gives back for a given input.
Overfitting – matching the training data closely while performing poorly on new data.
Predictive approach – using past data to work out a quantity that is not yet known.
Reinforcement learning – a learning based approach in which an agent improves by acting and receiving rewards.
Reward – the number an agent receives after an action, saying how well that action turned out.
Rule based approach – building a model from conditions written by people, which the computer applies exactly as written.
Slope – the number \(m\) in a straight line, giving the change in \(y\) for a one-unit rise in \(x\).
Supervised learning – training a model on a labelled dataset, where the correct output is available for every example.
Target – the output column of the data, the thing the model is meant to produce.
Testing data – the portion of the data kept back from training and used at the end to measure performance.
Training – the repeated process of predicting, measuring the error and adjusting a model’s internal numbers.
Training data – the portion of the data used to fit the model.
Underfitting – being too simple to capture the pattern, so performing poorly on both training and testing data.
Unsupervised learning – finding structure in data that carries no labels.
18.9 Objective Questions
Fill in the blanks: An input column of a dataset is called a ____________, while the column the model is meant to produce is called the ____________.
Choose the correct option. In the equation \(y = mx + b\), the number that tells you how much \(y\) changes when \(x\) rises by one is the
- intercept
- slope
- target
- label
State whether true or false: Testing a model on the same data it was trained on gives an honest measure of how it will perform on new cases.
Choose the correct option. Which of these can be built without any past data at all?
- supervised learning
- unsupervised learning
- a rule based system
- linear regression
Fill in the blank: A model that matches its training data closely but performs poorly on new data is said to be ____________.
Match each term in Column A with its correct description in Column B.
| Column A | Column B |
|---|---|
| a. Clustering | i. placing a case into one of a fixed set of categories |
| b. Classification | ii. the signal an agent receives after an action |
| c. Reward | iii. the portion of data kept back until the end |
| d. Testing data | iv. grouping similar examples that carry no labels |
- A model has been fitted as \(y = 4x + 12\). State the value it predicts when \(x = 7\).
18.10 Concept Questions
Define a model. Explain why a table of past records, on its own, cannot answer a question about a new case.
Give one reason why a rule based system may be preferred for a task even when a large amount of past data is available.
Differentiate between supervised learning and unsupervised learning, giving one example of a task suited to each.
A canteen’s sales model has been fitted as \(y = 5x - 60\), where \(x\) is the day’s highest temperature in °C and \(y\) is the number of bottles sold. Work out the number of bottles the model predicts for a day with a highest temperature of 32 °C, and state in one sentence what the slope tells the canteen.
State the difference between overfitting and underfitting. Explain how holding back a portion of the data makes it possible to tell one from the other.
In a test set of 200 items, 190 belong to one category and 10 to the other. A model that answers with the commoner category every time, without examining the item at all, is right 190 times. Work out its accuracy and explain why that figure does not show the model to be useful.
18.11 Case-Based Questions
- A teacher at a coaching centre in Kota records, for five students, the number of hours each spent practising before a class test and the marks each scored out of 80.
| Hours of practice | Marks scored |
|---|---|
| 1 | 28 |
| 2 | 36 |
| 3 | 44 |
| 4 | 52 |
| 5 | 60 |
Answer the following. a. Looking at the two columns, state whether a straight line is a fair description of this data, and give the reason for your answer. b. Write the equation of the line that fits this data, in the form \(y = mx + b\), and state what the slope means here. c. Use your equation to predict the marks for a student who practises for 6 hours. Then give one reason why the real result may not match that prediction.
- A small workshop wants to catch faulty parts before they are packed. A supervisor photographs 500 parts and marks each photograph as “fine” or “faulty”. Of the 500, 470 are fine and 30 are faulty.
Answer the following. a. Name the learning based approach that suits this data, and give the reason for your choice. b. Explain how the 500 photographs should be divided before training begins, and why they should not all be used for training. c. The trained model reports an accuracy of 94 per cent on the test set. Explain why the workshop should not accept this figure as proof that the model is working.