WeCodeAcademy

Training and Test Data

A model must be judged on examples it has not seen, just as a student is tested on new questions. So we set some data aside: the training set teaches the model and the test set checks it. train_test_split does the split. random_state makes the shuffle repeatable.

Examplepython
Open in editor »
Quick check

Why keep a test set apart from the training data?

Your turn: write the code

Split the 10 examples with test_size=0.5 and print how many are in the test set.

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.