Testing Your AICode with Python
In scikit-learn, KFold cuts the data into folds and cross_val_score trains and scores one model per fold. To fit a curve of degree 2 we give LinearRegression two columns for every farm, x and x²; the "straight line" through both is then a parabola. scikit-learn always treats a bigger score as better, so it reports errors as negative numbers — hence the minus signs. Run it, then try another k.
The Fold Loop, by Hand
Without scikit-learn, cross-validation is one loop: for each fold, train on the other farms and score on this one. np.array_split cuts the farm numbers 0 to 19 into k folds, and np.setdiff1d finds every farm that is not in the fold. Run it and compare with the output above.