Assuming the features are stored as a matrix with n samples and d features, and the known classes are stored as a categorical array with n elements, the following code should fit a K-Nearest Neighbors model (with K=3) to the data:
main.m60 chars2 lines
This creates a knnmodel
object that stores the information learned from the data, and can be used to make predictions on new data using the predict
method. Note that the NumNeighbors
parameter sets the number of nearest neighbors to consider when making predictions. You can adjust this value to see if it improves the performance of the model.
gistlibby LogSnag