Computer ScienceFoundation18 min read

Data Science and Data Gathering

Turning raw numbers into something worth acting on

This topic appears in:

01

Data, information, knowledge

These three words are used loosely in conversation and precisely in this chapter. Data is raw, unprocessed facts — 37, 41, 39, 40 means nothing on its own. Information is data given context: those are the maximum daily temperatures in Lahore last week. Knowledge is what you conclude and can act on: it is unusually hot for the season, so schools should reschedule sports.

Data science is the discipline of moving along that chain reliably, and it has a fixed set of stages.

  • Define the question. A vague question produces unusable data; deciding what you want to know comes before collecting anything.
  • Collect the data — from surveys, sensors, existing records or public datasets.
  • Clean it: remove duplicates, fix errors, decide what to do about missing values.
  • Analyse it: averages, spread, trends, correlations.
  • Present it: the chart that makes the finding visible to someone who has not seen the data.

Cleaning is most of the work

Real datasets contain the same person entered twice with different spellings, dates written three different ways, temperatures recorded as 400 instead of 40, and blank fields. Analysing dirty data produces confident, wrong answers — which is worse than no answer at all. This stage takes longer than the analysis and is where exam questions about "reliability" are pointing.

02

Primary and secondary data

Primary data is collected by you, for your question — a survey you ran, readings from a sensor you set up. It fits your purpose exactly and you know how it was gathered, but it costs time and effort and your sample may be small.

Secondary data already exists — government statistics, published research, a company's records. It is quick and often far larger, but it was collected for someone else's purpose, may be out of date, and you cannot check how carefully it was gathered.

MethodGood forWatch out for
Questionnaireopinions from many people cheaplyleading questions; low response rates
Interviewdepth and follow-upslow; interviewer influence
Observationwhat people do rather than saypeople behave differently when watched
Sensors / automatic logginglarge volumes, no human errorfaulty sensors log plausible nonsense
Existing recordshistory you could not collect nowcollected for another purpose
03

Sampling, and how it goes wrong

You rarely measure everyone. A sample stands in for the whole population, and the conclusions are only as good as the sample is representative.

A random sample gives every member an equal chance of selection. A systematic sample takes every nth member. A stratified sample divides the population into groups — year groups, districts — and samples each in proportion, which is the safest when the groups differ.

Bias is anything that makes the sample unrepresentative. Surveying only students who own smartphones about internet use will overstate access; the people excluded are exactly the ones who would have changed the answer.

A larger sample does not fix bias

Increasing a biased sample from 100 to 10 000 gives you a more precise measurement of the wrong thing. Bias is a fault in who is being asked, not in how many. This distinction is worth a mark whenever a question describes a survey conducted in one place or among one group.

04

Presenting the finding

The chart is not decoration — it is the argument. Choosing the wrong type hides the very thing you are trying to show, and choosing a misleading scale is how statistics get a bad name.

ChartUse it forDo not use it for
Bar chartcomparing separate categoriescontinuous data
Histogramthe distribution of continuous dataunrelated categories
Line graphchange over timeunordered categories
Pie chartparts of one wholecomparing two different totals
Scatter plotrelationship between two variablesa single variable

The same numbers shown three ways. The bar chart and histogram hold identical data, but only the histogram is honest about the classes being continuous — which is why the bars touch.

Correlation is not causation

Ice cream sales and drowning deaths rise together every summer. Neither causes the other — hot weather causes both. When a question asks what a scatter plot shows, the safe answer names the relationship and then says that a further investigation would be needed to establish a cause.

Before you leave this chapter

  1. Data → information (context) → knowledge (something you can act on).
  2. Primary data fits your question exactly; secondary data is faster and larger but was gathered for someone else.
  3. Cleaning takes longer than analysis, and skipping it produces confident wrong answers.
  4. Bias is about who you asked; a bigger sample does not cure it.
  5. Bar chart for categories, histogram for continuous data, line for time, pie for parts of a whole, scatter for relationships.
06

Describing a dataset before drawing conclusions

Before any chart, a few numbers summarise what the data looks like. Quoting them is what turns "the results were good" into a statement someone can check.

The mean is the arithmetic average and uses every value, so one extreme figure distorts it. The median is the middle value when sorted and ignores extremes entirely. The mode is the most common value and is the only one that works for categories such as favourite subject. The range and standard deviation describe how spread out the values are.

Worked example

A shop records daily sales of 40, 42, 38, 41, 39 and 400 items. Which average describes a typical day, and why?

  1. The mean is (40+42+38+41+39+400)/6 = 100 items.Every value contributes, including the 400.
  2. Sorted, the values are 38, 39, 40, 41, 42, 400, so the median is (40+41)/2 = 40.5.Only the position of the middle values matters, not their size.
  3. On five of the six days sales were between 38 and 42, so 100 describes no day at all.The mean has been dragged upward by a single unusual day.
  4. The median is the honest summary here, and the 400 should be investigated separately.An outlier is not noise to be deleted without thought — it may be a bulk order worth knowing about.

The median, 40.5 — the mean of 100 is distorted by one exceptional day.

Practice questions

6 questions · 20 marks · full working on every one

Try each one on paper first, then open the working. The marks are shown where they are actually awarded, because that is where they are actually lost.

Short questions

3 · 6 marks

Two marks each, in the style of the short-question section of the paper. Answer in two or three lines.

SQ1[2 marks]
Differentiate between data and information, with an example.
Model answer

Data is raw unprocessed facts with no context, such as the numbers 45, 62, 71. Information is data that has been given meaning — those are three students' marks out of 100 in a physics test.

Examiner tip. The example carries a mark. Use the same numbers for both halves so the difference is context, not content.

SQ2[2 marks]
State one advantage and one disadvantage of secondary data.
Model answer

Advantage: it already exists, so it is quick and cheap to obtain and often covers a far larger population than you could survey. Disadvantage: it was collected for a different purpose, so it may be out of date or may not exactly answer your question, and you cannot verify how carefully it was gathered.

Examiner tip. Answer both halves explicitly and label them. A single paragraph mixing the two often loses one mark.

SQ3[2 marks]
What is meant by bias in a sample?
Model answer

Bias occurs when the sample is not representative of the population, so certain groups are over- or under-represented and the results are systematically wrong. For example, surveying only smartphone owners about internet access excludes exactly the people whose answers would differ.

Examiner tip. The word "representative" is the mark. Adding an example of how a sample becomes biased usually secures the second.

Solved numericals

2 · 8 marks

Full working, one step per line, with the marks shown where they are awarded.

N1[4 marks]
Describe the stages of the data science process.
Full working
  1. Define the question or problem to be answeredcollecting before deciding what you want to know produces unusable data[1]
  2. Collect the data from appropriate primary or secondary sources[1]
  3. Clean it — remove duplicates, correct errors and handle missing valuesthe stage most often omitted[1]
  4. Analyse it, then present the findings in a suitable visual form[1]

Define the question, collect, clean, analyse, present.

Examiner tip. Cleaning is the stage students leave out, and it is almost always one of the four marks. Name it explicitly.

N2[4 marks]
A school surveys students about canteen food by asking the first 30 students to arrive one morning.
  1. Explain why this sample may be biased.
  2. Suggest a better sampling method and justify it.
Full working
  1. The first students to arrive are not typical — they may live nearby, travel by a particular route, or be in certain year groups[1]
  2. Their views on the canteen may differ systematically from those of students who arrive later, so the sample is unrepresentativethe link to unrepresentativeness is the mark[1]
  3. A stratified sample would divide students by year group and sample each in proportion to its sizeaccept random sampling from the full roll[1]
  4. This ensures every year group is represented in the correct proportion, so the results reflect the whole schoolthe justification is required[1]

(a) early arrivals are not typical of the school (b) stratified sampling by year group, so each is represented proportionally

Examiner tip. When criticising a sample, say who is being missed. "It is biased" without naming the excluded group rarely scores.

Long questions

1 · 6 marks

Theory and numerical together, as they appear in the long-question section.

LQ1[6 marks]
A researcher collects daily temperature readings from an automatic sensor for one year.
  1. Give two advantages of using a sensor rather than manual readings.
  2. The dataset contains three days recorded as 400 °C and eleven days with no reading at all. Describe how you would handle each.
  3. Suggest the most suitable chart for showing how temperature varied over the year, and justify your choice.
Mark scheme
  1. A sensor records continuously and automatically, so no readings are forgotten and none are affected by human error in reading a scale[1]
  2. It can record far more frequently than a person could, and at times when nobody is present[1]
  3. The 400 °C values are clearly impossible and are sensor errors, so they should be removed or marked as invalid rather than analysedidentifying them as outliers or errors[1]
  4. The missing days should be recorded as missing, not as zero — entering 0 °C would drag the mean down and invent a cold spell that never happenedthis is the key insight[1]
  5. A line graph, with date on the horizontal axis and temperature on the vertical[1]
  6. Because the data is continuous and ordered in time, a line graph shows the trend and the seasonal pattern that separate bars would obscurethe justification is the mark[1]

(a) continuous automatic recording, no human error (b) discard the impossible values; mark the gaps as missing, never as zero (c) a line graph, because the data is continuous over time

Examiner tip. Replacing a missing value with zero is the trap in part (b). Zero is a real temperature, so the software cannot tell it apart from a genuine reading — and the mean is then wrong.