Lesson 14
ML Workflow
Nine beginner steps on four students: hold C out of the fit, the average misses 100 by 40, and the line still hits the mark.
What You Will Learn
Nine steps. Four students. The workflow is the order you touch them. Student C stays in a closed envelope until the guess is written down.
- 1. What is an ML workflow?
- 2. The stages on this class
- 3. Where each stage shows up
- 4. Where it sits among the lessons
- 5. What a finished score hides
- 6. How the held-out student decides
- 7. Key Takeaways
- 8. Mind Map
- 9. Quiz
1. What is an ML workflow?
An ML workflow is the order of decisions that turns a table into a guess you can trust.
| Student | Hours | Marks | Role on this page |
|---|---|---|---|
| A | 1 | 30 | Used to build the guess |
| B | 2 | 40 | Used to build the guess |
| C | 8 | 100 | Held out. Scored once, at the end |
| D | 9 | 110 | Used to build the guess |
The marks follow marks = 20 + 10 × hours. Check A: 20 + 10 × 1 = 30. Check D: 20 + 10 × 9 = 110. C follows the same rule, 20 + 10 × 8 = 100, and that fact stays unused until the guess is already written.
The school asked for the mark. That sentence is the first stage. Naming the column is model selection. This page is the order around that choice.
2. The stages on this class
| Stage | What happens to these four rows |
|---|---|
| Name the question | Predict marks |
| Look | Four rows, no blanks, and the marks sit on a straight line |
| Hold one student out | C's 100 stays unseen |
| Write a plain guess | Average of 30, 40 and 110 is 60 |
| Write the model the picture asks for | 20 + 10 × 8 = 100 |
| Score once | The average misses by 40. The line misses by 0 |
| Write the result down | Question, who was held out, both misses |
The picture above is that score. The amber bar is the plain guess. The purple bar is the line. The green bar is C's real mark.
3. Where each stage shows up
| What is in your hands | The stage you are in |
|---|---|
| A table, and you cannot yet say which column you would be ashamed to get wrong | Name the question |
| Hours, and a mark you must predict | Look, then model selection |
| A column you can explain from facts known before the exam, such as hours × attended | Feature engineering, before any model |
| Two guesses, and one student they were not built on | The score |
| 90 passes and 10 fails | The score itself changes. A 90 percent accuracy can miss every fail. That page is imbalanced data |
| A miss that is still falling as new students arrive | Learning curves says whether more rows will help |
4. Where it sits among the lessons
The order on this class is fixed.
- Name the column: marks.
- Keep the inputs to facts known before the exam. Here that fact is hours. A new column, when you need one, is feature engineering.
- Pick the simplest model the picture allows. A straight line is linear regression.
- Score student C, who was held out.
- If the miss is still large, the learning curve says whether more students will help the model you already picked.
A forest can also land on these four marks. The line already tells the whole story, so the forest waits. That choice is the model selection page, and it happens before the score, while C is still in the envelope.
5. What a finished score hides
Average A, B, C and D together: (30 + 40 + 100 + 110) / 4 = 70. Then pretend C is new and guess 70. The miss is 100 − 70 = 30.
The honest average, built without C, was 60, and the miss was 40. C's own 100 pulled the average up by 10, so the page looks kinder. The check is over. C helped build the number that C is being scored on.
The line still says 100 either way, because C already sits on marks = 20 + 10 × hours. A perfect line does not expose this leak. The plain average does. Freeze who is held out before you believe either miss.
A second leak is a column that copies marks. The guess can print the answer it was handed. Feature engineering keeps a new column on facts known before the exam.
6. How the held-out student decides
Training marks are 30, 40 and 110. The sum is 180. 180 / 3 = 60. That plain guess is handed to everyone, including C. C scored 100. The miss is 100 − 60 = 40.
The line is allowed to see C's hours. Hours were known before the exam. 20 + 10 × 8 = 100. The miss is 0.
The line wins on this page because 0 is smaller than 40, on a student the average never saw.
This page needs one module: pandas. It holds the table and leaves C out. NumPy is not required. scikit-learn is not required.
| Piece | What it means here |
|---|---|
import |
Load a module into this notebook |
pandas |
The table module |
as pd |
The short name. Later lines say pd |
pd.DataFrame |
Build the four rows |
students["student"] != "C" |
Keep A, B and D |
.mean() |
Average the training marks |
import pandas as pd
students = pd.DataFrame({
"student": ["A", "B", "C", "D"],
"hours": [1, 2, 8, 9],
"marks": [30, 40, 100, 110],
})
train = students[students["student"] != "C"]
print(train)
print("average guess:", train["marks"].mean())
print("line for C:", 20 + 10 * 8)import pandas as pd is the whole requirements line. The filter keeps every row whose student name is different from C. .mean() averages the marks that remain. The same idea of reading a column is in the pandas column lesson.
The printed training table:
| Student | Hours | Marks |
|---|---|---|
| A | 1 | 30 |
| B | 2 | 40 |
| D | 9 | 110 |
The next line prints 60.0. The line for C prints 100.
Score C once. If you keep editing the rule until C looks perfect, C has become a training row, and the miss of 0 is the leak from the chart above.
When the miss is already 0, copying these four students again teaches nothing new. Learning curves asks for new rows only while the miss is still falling.
If the school had asked pass or fail, C is one row and the score is right or wrong. A pile of 90 passes and 10 fails needs the catch count on imbalanced data, because a 90 percent score can miss every fail.
7. Key Takeaways
- The workflow is the order: name the mark, look, hold someone out, write a plain guess, write the model, score once, write it down.
- A, B and D have marks 30, 40 and 110. Their average is 60.
- C scored 100. The average misses by 40. The line 20 + 10 × 8 misses by 0.
- Putting C into the average changes the guess from 60 to 70 and the miss from 40 to 30. That kinder number used the answer.
- The only module required here is pandas, loaded with
import pandas as pd. - The playground prints the training rows, 60.0, and 100.
8. Mind Map
Cover the green bar. Add 30, 40 and 110, divide by 3, and subtract that average from 100. If you still get a miss of 40, and the line still lands on 100, the page is yours.
9. Quiz
The questions use this class. C is held out. Training marks are 30, 40 and 110. C's mark is 100.
Loading playground…
Check your understanding
ML Workflow Quiz
On this class, what is the first thing you write down?
1 / 6