Two URLs for Problem 2.7 and 2.8, obesity and election 2004 (also available here).
In Problem 2.7, use obseity rates and election results in 2004 as the training set, and obseity rates and election results in 2000 as the test set.
The knnrule() and knnclass() in STPRTool package might be useful for Problem 2.7 and 2.8.
See also the example.
Or use knnclassify() in Matlab Statistical Learning Toolbox.
For Problem 2.11 and 2.12, generate 10 data points according to the description in textbook Example 1.4, pp. 16–17.
You would need the Linear Regression Toolbox for these problems.
See also the example.