Question



Getting an error when running KNN algorithm on Project

Dr. Ballings,

When i run the knnx.index algorithm i get an error that says "number of columns must be the same!". I thought that the "data=" argument
should be a dataset that contains only your predictors (e.g. high, low, etc) and the "query=" argument should be only your dependent
variable? Am I wrong in that assumption? If so, what data should go in the "data" and "query" arguments?

Thanks,
John





Answers and follow-up questions





Answer or follow-up question 1

Dear John,

Whenever you're unsure about the arguments simply do ?functionname.
If that is unclear search for some example code and look at the values that are given to the
arguments (e.g., the code in the book).

?knnx.index gives you the following information:

data: an input data matrix.
query: a query data matrix.

Data is your training data and query is your test data.

In the KNN section of the book you can also run the code and look at the objects using str().
This will help you a great deal.

Hope this helps.

Michel Ballings




Sign in to be able to add an answer or mark this question as resolved.