Courses / Data Science & ML with AI
Session 1 of 8
What Is Data Science and Machine Learning? The ML Project
Notes
What Is Data Science and Machine Learning? The ML Project Lifecycle Explained
Course: Data Science & ML with AI
Before you start
You need Python 3 with pandas and scikit-learn installed (pip install pandas scikit-learn). The
examples use a small dataset that ships inside scikit-learn, so there is nothing to download, no
account and no API key. You should be able to read a few lines of Python and know what a table of
rows and columns is. No statistics or machine learning background is assumed.
Keep one question in mind while you read: if someone hands me a plan for a prediction project, how do I tell whether it is a sound plan or one that looks fine and fails later? By the end you will have a checklist of eight stages to hold any such plan against, including a plan written by an AI assistant.
Summary
Data science is the practice of using data to answer a question, and machine learning is the part of it where a program learns a pattern from example rows instead of following rules a person wrote. Supervised learning learns from rows that include the answer and predicts it for new rows, as a number (regression) or a label (classification), while unsupervised learning looks for structure, such as groups (clustering), in rows that have no answer column. A machine learning project moves through eight stages: question, data, explore and clean, features, train, evaluate, deploy and monitor, and each stage has its own typical failure. The most costly failures hide in the middle and at the end, a model scored on rows it has already seen, and a model left running after the world has changed. This chapter teaches the stages, gives you a first look at a real dataset in Python, and trains you to check an AI assistant’s project plan against them.
Key concepts
| Term | Definition |
|---|---|
| Data science | Using data to answer a question: collecting it, cleaning it, exploring it, sometimes modelling it, and explaining the result to the people who asked. |
| Machine learning (ML) | A way of building a prediction program in which the program finds the pattern itself from example rows, instead of a person writing the rules by hand. |
| Row (sample) | One record in a table, such as one patient. In scikit-learn the rows of the feature table are called samples. |
| Feature | One input column the model may use to predict, such as a patient’s age or body mass index. |
| Target | The column the model is asked to predict, also called the label or the answer. In the diabetes dataset it is a disease-progression score. |
| Supervised learning | Learning from rows that include the known target, so the model can predict the target for new rows whose target is unknown. |
| Regression | Supervised learning where the target is a number on a scale, such as a price or a score. |
| Classification | Supervised learning where the target is one label from a fixed list, such as spam or not spam. |
| Clustering | Unsupervised learning that groups rows by similarity when there is no target column to learn from. |
| ML project lifecycle | The sequence of stages a project passes through, from the question to monitoring: question, data, explore and clean, features, train, evaluate, deploy, monitor. |
| Train/test split | Dividing the rows into a training set the model learns from and a test set held back to measure it on rows it did not learn from. |
| Mean absolute error (MAE) | The average size of the gap between each prediction and its true value, ignoring whether the prediction was too high or too low. Lower is better. |
| Baseline | A deliberately simple prediction, such as predicting the training average for each row, that a real model must beat to be worth using. |
| Drift | A change in the real world after launch, so the data a deployed model receives no longer looks like the data it learned from. |
Explanations
The failure, before the explanation
An analyst builds a model to predict how far a patient’s diabetes will have progressed one year
after a check-up. She trains it on the 442 patient rows she has, then scores it on those same 442
rows. The average error comes back as 0.0. She writes “perfect model, ready to ship” in her
report, and the model goes into use. Soon the clinic notices that its predictions are
no better than reading the average off a chart.
Nothing in her code raised an error. The failure was in the plan: the model was marked on the very
rows it had learned from, and nothing told anyone when its real-world accuracy slipped. The rest of
this chapter gives you the map that makes such gaps visible before they cost anything. You will
reproduce her 0.0 yourself in the section on held-back rows.
What data science and machine learning are
Start with a rule you could write yourself. To estimate a taxi fare you might write: “start at 3.00, add 1.50 per kilometre”. That is a program in which a person chose the numbers. Now suppose you hold ten thousand past trips with their distance, time of day, weather and final fare, and you hand them to a program that works out for itself how those inputs relate to the fare. Nobody typed the numbers in; the program found them from examples. That second way of building a program is machine learning.
A second way to picture it: a new support hire can learn their job from a thick policy manual, or by reading a thousand solved tickets and noticing which replies worked. The manual is rules written by a person; the solved tickets are examples. A machine learning model learns from the tickets.
Data science is the wider job. It starts before any model, with a question and the data to answer it, and it ends after one, with an explanation of the result and a decision about what to do. Some data science involves no machine learning: a clear table of monthly sales and a well-chosen chart can answer a question on their own. One common way to draw the line, and the one this course uses, is that data science is the whole job of answering a question with data, and machine learning is the model-building part of it, used when the answer is a prediction for rows you have not seen yet.
Supervised and unsupervised learning
Supervised learning is learning with the answers in hand. The scikit-learn documentation describes the setup: a table of samples, one row per sample and one column per feature, plus a target value for each sample, which is a real number for regression and a label from a fixed set for classification. The model studies rows where the target is known and learns to predict it for rows where it is not. Two kinds are common.
Regression predicts a number on a scale. Given a flat’s floor area, district and age, predict its rent. The answer can be any value on the scale, such as 1,240.50, and a good prediction is a close one. The diabetes dataset in this chapter is a regression problem: the target is a score, and the job is to predict how large it will be.
Classification predicts one label from a fixed list. Given the text of an email, predict “spam” or “not spam”; given a scan, predict which of five conditions it shows. The answer is a category, not a position on a scale, and a prediction is either the right label or a wrong one. A classifier may also report how confident it is, which later chapters use.
Unsupervised learning works without a target. The documentation notes that for unsupervised tasks the target does not need to be specified. Clustering, the unsupervised task met in this course, takes a table of customers described by what they buy and how often, and groups customers who resemble each other, with no one having labelled the groups beforehand. Because there is no answer column, there is no row to mark right or wrong; you judge a clustering by whether the groups are useful and make sense when you inspect them.
A quick test to tell them apart: look at the table and ask “is there a column I am trying to predict?” If yes and it is a number, regression; if yes and it is a label, classification; if no, you are looking for structure, and that is unsupervised.
The ML project lifecycle
Picture a project to predict how a patient’s diabetes will progress. A manager says, “we should use machine learning on this.” Nothing can happen until someone says what to predict and for whom. Then the data has to be found, and it turns out to have gaps. Then a model is trained and checked, put somewhere people can use it, and watched afterwards. Those steps repeat from one project to the next, so they have a name: the ML project lifecycle. Here it is, with the usual way each stage goes wrong.
| Stage | What happens | What goes wrong here |
|---|---|---|
| 1. Question | Turn a vague wish into a prediction question with a target that can be measured. | The question is too vague to measure (“make patients healthier”), or it asks for a label when the data holds a number. |
| 2. Data | Find rows that contain both the inputs and the target. | The target was not recorded, the rows are too few, or they do not resemble the cases the model will meet later. |
| 3. Explore and clean | Look at shapes, ranges, missing values and oddities, and fix what is broken. | Missing values, duplicates and wrong types go unnoticed, so the model learns from errors. |
| 4. Features | Choose and prepare the input columns the model will use. | A feature leaks the answer, or one column is left on a scale that distorts the model. |
| 5. Train | Fit a model to the training rows. | The model memorises the training rows instead of learning a pattern that transfers. |
| 6. Evaluate | Measure the model on held-back rows against a baseline. | It is scored on rows it was trained on, so the score is flattering, or it is not compared with a baseline. |
| 7. Deploy | Put the model where people or programs can use it. | The inputs at launch are prepared differently from the inputs it was trained on. |
| 8. Monitor | Watch its inputs and its accuracy after launch. | Nobody watches; the world drifts and accuracy decays without any alarm. |
Two things to notice. First, the stages are a loop, not a line: a poor evaluation sends you back to
the features or the data, and a drifting model sends you back to the data again. Second, most of the
stage names are verbs for work you do with pandas and scikit-learn, and the chapters of this course
take them in this order, the way a project does. The failure in the first column of that table, an
error of 0.0 on the training rows, is stage 6 going wrong.
A first look at the diabetes dataset in Python
The best way to meet these words is on real rows. scikit-learn ships a few small datasets that need no download from an outside website, and one of them is the diabetes dataset, which this course uses for regression. Its documentation describes 442 patients, with ten baseline measurements for each (age, sex, body mass index, average blood pressure and six blood serum measurements) and, as the target, a quantitative measure of disease progression one year after baseline. Run this yourself:
import pandas as pd
from sklearn.datasets import load_diabetes
pd.set_option("display.width", 120)
pd.set_option("display.max_columns", 20)
diabetes = load_diabetes(as_frame=True)
X = diabetes.data # the ten feature columns
y = diabetes.target # the number to predict
print(X.shape)
print(y.shape)
print(list(X.columns))
print(X.head().round(3))
print(y.head())
It prints:
(442, 10)
(442,)
['age', 'sex', 'bmi', 'bp', 's1', 's2', 's3', 's4', 's5', 's6']
age sex bmi bp s1 s2 s3 s4 s5 s6
0 0.038 0.051 0.062 0.022 -0.044 -0.035 -0.043 -0.003 0.020 -0.018
1 -0.002 -0.045 -0.051 -0.026 -0.008 -0.019 0.074 -0.039 -0.068 -0.092
2 0.085 0.051 0.044 -0.006 -0.046 -0.034 -0.032 -0.003 0.003 -0.026
3 -0.089 -0.045 -0.012 -0.037 0.012 0.025 -0.036 0.034 0.023 -0.009
4 0.005 -0.045 -0.036 0.022 0.004 0.016 0.008 -0.003 -0.032 -0.047
0 151.0
1 75.0
2 141.0
3 206.0
4 135.0
Name: target, dtype: float64
Read it line by line. X.shape is (442, 10): 442 rows (patients) and 10 columns (features). The
target y has 442 values, one per patient. head() shows the first five rows by default. The
names s1 to s6 are the six blood serum measurements; the documentation expands them as total
cholesterol, low-density lipoproteins, high-density lipoproteins, the ratio of total cholesterol to
high-density lipoproteins, a possible log of serum triglycerides and blood sugar level.
Now the surprise. The feature values look nothing like an age or a body mass index: the first
patient’s age is 0.038. That is because load_diabetes has a parameter scaled that is True
by default, and with it each feature is mean-centred and rescaled so that the sum of squares of
each column is 1. The numbers are therefore not in the original units, and the documentation
describes the feature values as lying between -0.2 and 0.2. So 0.038 is not a number of years. You
can still compare patients, because larger still means larger. If you need the raw measurements,
call load_diabetes(scaled=False).
Next, three quick checks that belong to the “explore and clean” stage:
print(X.isna().sum().sum())
print(y.min(), y.max(), round(y.mean(), 1))
0
25.0 346.0 152.1
The first line counts missing values across the feature table: zero. The second says the target runs from 25 to 346, with an average of 152.1. This is a number on a scale, so the diabetes problem is regression. (It has 214 distinct values across the 442 patients, so it is not a short list of labels.) The dataset contains no “diabetic or healthy” label: a score between 25 and 346 is not that.
The scikit-learn documentation also warns that datasets like this one are often too small to be representative of real-world machine learning tasks. They exist to practise on, and 442 rows are enough to see the ideas in this chapter, but not to trust a model in a clinic.
Try it: compute the median of the target with y.median(). The answer is 140.5, lower than the
mean of 152.1. Now an independent one: count how many patients have a target above 200 with
(y > 200).sum(). Check your result against 121.
Why we hold some rows back: the train/test split
Return to the analyst. The 0.0 is easy to reproduce. First a one-sentence preview of the cure, which
a later chapter teaches properly: a train/test split divides the rows once, at random, into a
training set the model learns from and a test set it does not see until it is measured, so the score
reflects rows that are new to the model. In scikit-learn it is one call:
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
print(X_train.shape, X_test.shape)
(353, 10) (89, 10)
test_size=0.2 sets the share of rows held out for testing to 0.2 (89 of the 442 rows), and random_state=0 fixes the
shuffle so everyone who runs it gets the same split. Now fit a model that is very good at
memorising, and score it two ways. You do not need to know how a decision tree works yet; treat it
as a black box that fits a table. What matters is the comparison of the three numbers:
from sklearn.tree import DecisionTreeRegressor
from sklearn.metrics import mean_absolute_error
model = DecisionTreeRegressor(random_state=0).fit(X_train, y_train)
print("MAE on training rows:", round(mean_absolute_error(y_train, model.predict(X_train)), 1))
print("MAE on unseen rows:", round(mean_absolute_error(y_test, model.predict(X_test)), 1))
print("MAE of guessing the training average:",
round(mean_absolute_error(y_test, [y_train.mean()] * len(y_test)), 1))
MAE on training rows: 0.0
MAE on unseen rows: 70.6
MAE of guessing the training average: 59.2
This is the analyst’s 0.0. The model has memorised the 353 training rows, so scoring it on them
proves nothing. On the 89 rows it did not train on, it is off by 70.6 on average, which is worse than
the 59.2 you get by guessing the training average for everyone. That guess is a baseline: the
least a model must beat to be worth deploying. The lesson for the lifecycle: the evaluate stage
must use rows the model has not seen, and it must compare with a baseline. Exact values can differ
slightly if your library versions differ from the ones used here (scikit-learn 1.9.1, pandas 3.1.1).
With AI: check an assistant’s project plan against the lifecycle
An AI assistant is quick at drafting a plan, and a draft costs almost nothing. What it cannot do is know which of its own steps is the one that will hurt you, so the draft is a starting point you check, not a plan you adopt. Here is a draft produced for the prompt “Plan a project that predicts diabetes progression using the bundled diabetes dataset”:
Draft plan
- Goal. Classify each patient as “diabetic” or “healthy”.
- Data. Load the diabetes dataset: 442 patients, 10 baseline columns.
- Clean. Check for missing values and fill any with the column average.
- Features. Use the ten columns as they come.
- Train. Fit a decision tree regressor on the 442 rows.
- Evaluate. Report the mean absolute error of the tree on those 442 rows.
- Deploy. Wrap the tree in a function a clinic’s web form can call.
The check is the lifecycle table. Go down the plan one step at a time, put the matching stage beside it, and ask two questions: “what goes wrong at this stage?” and “can I test the draft against that, using something this chapter showed me?” The tests available to you so far:
| Check | How you run it |
|---|---|
| Does the target match the goal? | Look at y.min(), y.max() and y.nunique(): a numeric score is regression, a short list of labels is classification. |
| Are the evaluation rows new to the model? | Compare the rows used in step 5 with the rows used in step 6; the two must be different sets. |
| Do the eight stages appear? | Tick off the eight stages against the plan’s steps. |
Try it before you read on: write the eight stage names down the left, the plan’s steps down the right, and mark each step that fails its check.
Check your work. The draft has three flaws, and the section above gives you the tools to find each:
- Step 1 is the wrong kind of problem (question stage). The dataset contains no “diabetic” or “healthy” label. Its target is a score from 25 to 346 with 214 distinct values, so the project is regression. A classifier built on a made-up cut-off would answer a question nobody asked.
- Steps 5 and 6 evaluate on the training rows (evaluate stage). The tree is fitted on the 442 rows and scored on the same 442, the analyst’s mistake from the start of the chapter, and it will report an error near 0.0. A held-back test set and a baseline are missing.
- There is no monitor step (stage 8). The plan ends at deployment. Nothing watches the model’s inputs or its error once real patients use it, so drift would go unnoticed.
Step 3 is harmless here (the data has no missing values, which you checked), and step 4 is worth questioning in a later chapter but is not a lifecycle failure yet. Telling a harmless step from a harmful one is the skill; an assistant will write both with the same confidence.
Three situations you will meet, and what they mean for your work
Before the table, three situations:
- A manager writes: “Use machine learning to make our customers happier.” There is a data table, but no one has said what the model should output.
- A teammate shares a notebook whose last line prints an error of
0.0, and suggests shipping it today. - A model that predicted well at launch gives noticeably worse predictions later on, after the company changed how it records the input data.
| What you see | Lifecycle stage involved | What to do |
|---|---|---|
| A wish with no measurable output (situation 1) | Question | Rewrite it as one prediction question and name the target column before touching a model. |
| A perfect score (situation 2) | Evaluate | Ask which rows the score was measured on; re-score on held-back rows and against a baseline. |
| Accuracy decays after launch (situation 3) | Monitor | Compare current inputs and error with those at launch, then return to the data stage and retrain. |
Flashcards
Say the answer aloud before revealing it. Speaking it is what exposes the gaps that reading past a written answer hides.
How do data science and machine learning differ?
Data science is the whole job of answering a question with data, from collecting rows to explaining the result. Machine learning is the model-building part, where a program learns a pattern from example rows to predict for new ones.
What is the difference between a feature and a target?
A feature is an input column the model uses to predict, such as age or body mass index. The target is the one column it is asked to predict, such as the disease-progression score.
What makes learning supervised?
The training rows include the known answer, the target. The model learns the link between features and target and then predicts the target for new rows where it is not known.
How do regression and classification differ?
Regression predicts a number on a scale, such as a price or a score. Classification predicts one label from a fixed list, such as spam or not spam.
What is clustering, and why is there no "right answer" to mark?
Clustering groups rows by similarity with no target column. With no known answer there is nothing to score as right or wrong, so you judge the groups by inspecting them and asking whether they are useful.
Name the eight stages of the ML project lifecycle in order.
Question, data, explore and clean, features, train, evaluate, deploy, monitor. They form a loop: a weak evaluation or a drifting model sends you back to the features or the data.
What does X.shape print for the diabetes features, and what does each number mean?
It prints (442, 10): 442 rows, one per patient, and 10 columns, one per feature. The target
y is separate and holds 442 values.
Why are the diabetes feature values like 0.038 and not an age in years?
load_diabetes has scaled=True by default, so each feature is mean-centred and rescaled until the
sum of squares of each column is 1. The raw measurements come back with scaled=False.
Why must the evaluate stage use rows the model has not seen?
A model can memorise its training rows and score near-perfectly on them while predicting new rows badly. In the example, the error was 0.0 on training rows but 70.6 on unseen rows.
What is a baseline, and what did it show in the example?
A baseline is a simple prediction, such as the training average, that a real model must beat. Here it scored 59.2 on the unseen rows, better than the memorising tree’s 70.6.
What does the monitor stage watch for, and why?
It watches the model’s inputs and error after launch for drift, because the real world can change so that data the model receives no longer resembles the data it learned from, and accuracy then decays.
Model answer
The question: “Walk me through how you would run a machine learning project from a vague request to something people use.” A strong answer hits five beats, in this order:
- Question — turn the request into a prediction question with a measurable target.
- Data — confirm the rows hold the inputs and the target, then explore and clean them.
- Model — build the features and train.
- Evaluation — score on held-back rows and compare with a baseline.
- Operation — deploy, then monitor inputs and accuracy for drift.
“I would start by turning the request into a specific question with a target I can measure, and check whether it is regression or classification, because that choice follows from the target. Then I would confirm the data actually holds the inputs and the target, and explore and clean it: shapes, ranges, missing values. Next I would build the features and train a model. I would split off a test set before training and score on those unseen rows, against a baseline such as the training average, because a model scored on its own training rows can look perfect and still fail. Finally I would deploy it with the same preparation steps used in training, and monitor its inputs and error, because the world drifts and accuracy decays without any alarm. If it does, I loop back to the data.”
Missing a beat is a failure state. Without the question the project has no target to
measure. Without the data beat there is nothing to learn from. Without model there is nothing to
evaluate. Without evaluation a flattering score goes unchallenged, the analyst’s 0.0. Without
operation the model’s decay goes unnoticed, and that is the beat an examiner most often finds
missing.
Why this matters
- Scoping work. Naming the target and the problem type before touching a model is what separates a project from an experiment, and it is the first thing a reviewer asks about.
- Trusting a number. A reported score is as good as the rows it was measured on. Asking “measured on which rows, and against what baseline?” catches the most common flattering result.
- Reviewing AI-written plans. An assistant drafts plans in seconds and delivers them with equal confidence whether they are sound or not. A lifecycle checklist is how you tell the difference.
- Keeping a model useful. Deployed models decay as the world changes, so the people who run them need a monitoring habit from the first launch, not after the first complaint.
After this unit
You now have the map: eight stages, three kinds of problem, and a first look at a real table. The next chapter takes the second and third stages in hand and shows how to clean a messy table with pandas: finding missing values, duplicate rows and wrong data types, and proving with row counts and checks that the cleaning worked.
Quiz
Answers are not marked on this page yet. Work through the questions and check the written ones against the criteria printed with each question. The answer key is kept back for now.
Quiz — What Is Data Science and Machine Learning? The ML Project Lifecycle Explained
Instructions: Eight multiple-choice questions. Pick one option per question. Work closed-book, then compare your letters with the answer key, which is held separately and holds the reasons.
1. [recall] Which description fits supervised learning?
a) Grouping rows by similarity when the table has no answer column for the model to learn from b) Writing if/else rules by hand from an expert’s experience, then testing them on sample rows c) Learning from rows that include the known answer so it can predict that answer for new rows d) Cleaning and reshaping a table until it has no missing values left in any of its columns
2. [application] A team wants to predict a patient’s disease-progression score, a number between 25 and 346, from ten baseline measurements. Which kind of problem is this?
a) Regression, because the answer to predict is a number on a scale rather than a label b) Classification, because the scores fall inside one fixed range of allowed values c) Clustering, because patients with similar measurements end up grouped together d) Classification, because each patient gets one label from a fixed list of choices
3. [scenario] A manager tells an analyst: “Use machine learning to make our patients healthier.” The analyst has a table of patient records to start from. What should the analyst do first?
a) Train several models on the largest table available and keep the one with the best score b) Collect a much larger table of patient rows before deciding what the model should predict c) Deploy a rough first model so that real use shows which outcome is worth measuring d) Turn the request into one specific prediction question with a target that can be measured
4. [application] A learner runs X = load_diabetes(as_frame=True).data and then
print(X.shape). What is displayed?
a) (10, 442)
b) (442, 10)
c) (442, 11)
d) (442,)
5. [recall] A learner loads the diabetes dataset with its default settings and prints
X.head(). Which statement describes the numbers in the feature columns?
a) They are the raw clinic measurements, such as age in years and body mass index b) They are percentages that show where each patient ranks within a column c) They are raw measurements with each missing value replaced by the column average d) They are centred and rescaled values, so they are not in the original units
6. [scenario] A decision tree trained on 353 patient rows has a mean absolute error of 0.0 on those same rows and 70.6 on 89 rows it never saw. Guessing the training average for those 89 rows scores 59.2. What should the team conclude?
a) The tree memorised its training rows and does worse on new rows than a plain average guess b) The tree is accurate, because an error of 0.0 shows it found the true pattern in the data c) The 89 unseen rows are faulty, because a good model scores about the same on any rows d) The tree needs further training, because its error on unseen rows is still fairly high
7. [recall] Why does a project set aside a test set before training a model?
a) To give the model extra rows to learn from once its first round of training has ended b) To measure the model on rows it never learned from, as a stand-in for new future rows c) To drop rows with missing values so that the model is trained only on clean examples d) To check the column names and types before any features are built from the table
8. [scenario] An assistant’s plan for a prediction project lists: question, data, cleaning, features, training, evaluation on held-back rows, and deployment as a web form. It ends with the words “project complete”. Which lifecycle stage is missing?
a) Evaluation, because a plan cannot score any model until it has been put in front of real users b) Retraining, because a plan must fix a retraining schedule before the model is deployed c) Monitoring, because nothing watches the model’s inputs and accuracy once users rely on it d) Documentation, because a project only counts as complete once a written report exists
Want help building this with someone?
Tell us what you are working on and we will write back about a mentor-led cohort, live sessions or 1:1 training. It is only an enquiry: you choose whether to go further.
Ask about mentor-led trainingTechEazy Consulting training material — not affiliated with or endorsed by pandas, scikit-learn or any other project or company named in this course.