Data and Train/Test Splits
The previous lesson split data into training and test sets without explaining why, this lesson makes that explicit: it's arguably the single most important habit in applied machine learning.
Why you can't evaluate on training data
If you show a model its own training data and ask "how'd you do?", a sufficiently flexible model can simply memorize every example, scoring perfectly, while having learned nothing that generalizes to new data. The only honest way to measure "did this model actually learn something useful?" is to test it on examples it never saw during training.
Looking at the data with pandas
load_iris(as_frame=True) returns the dataset as a pandas DataFrame, a table with named columns, instead of plain numpy arrays, much easier to read and explore. df.head() prints the first 5 rows, df.shape gives (rows, columns), both standard first steps when looking at any new dataset.
Splitting properly
test_size=0.2holds back 20% of the data for testing, 80% for training, a common default, though the right split depends on how much data you have overall.random_state=42seeds the random shuffle used to pick which rows go where. Without it, you'd get a different split every run, making results hard to compare or reproduce, setting a fixed seed is standard practice any time you want a repeatable experiment.
WARNING
Never look at your test set while choosing features, tuning models, or making any decision that shapes your final model, if test-set performance influences your choices, it stops being an honest measure of generalization. It should be touched exactly once, at the very end, to report a final number.