BeginnerCoder

Lesson 13 — Train / test split

Test on data the model has never seen

A model can simply memorise its training data. To find out whether it really learned, we hide part of the data: the training set is used for learning, the test set only for the final check. A common split is 80% / 20%. Python slicing makes this easy: data[:cut] is everything before position cut, data[cut:] is everything from cut on.

data = [1, 2, 3, 4, 5]
data[:4], data[4:]   # ([1, 2, 3, 4], [5])

Why it matters: a model that scores 100% on data it trained on and 50% on new data is useless. Only the test score tells the truth.

Want it another way?
Task

Compute cut (80% of the length, as an int) and slice train and test.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.