Train, Test and ValidationCode with Python
In Python, scikit-learn's train_test_split shuffles the data and cuts it in two. Calling it twice gives all three sets: first training against the rest, then the rest into validation and test. random_state=42 fixes the shuffle, so you get the same split every time you run it. Run the program, then change the number of rows or the test size.
Choosing the Degree in Code
Here is the fertiliser experiment as a loop. np.polyfit learns a curve from the training data only; the validation error decides which degree wins. Run it and compare the output with your own chart.