I have put together an analytical piece on the Cleveland Heart Disease dataset and have built a number of ML solutions.
One of those solutions is KNN (K-Nearest Neighbours) and this works fine. However, when I attempt to visualise the solution, the following error is thrown:
Error in knn(train = train[, -14], test = grid_set, cl = train[, 14], :
dims of 'test' and 'train' differ
The error is self-explanatory, so I go back through the code and check it line-by-line and, sure enough, the dimensions of train
and test
are indeed different.
The trouble is that I am using visualisation code that I have from a ML course that I took several years ago and am following that example, but no matter what I try, I can't seem to get it to work.
Once again, the solution itself, which I built, works fine, but I really want to understand what the code that I have from the other source is actually doing so that I can fully understand what is going wrong.
The full code is quite lengthy, so I won't post it here as it may take up too much space, although I think it is useful to see how the datasets are constructed and mutated which is why I would like the whole piece to be visible.
As such, it can be found on this Hastebin.
Any suggestions and/or explanations as to what the visualisation code is doing (especially around variables X1
, X2
and subsequently grid_set
) would be most welcomed.