k-nearest neighbors
Moving on from logistic regression, let's try our first non-regression model, k-nearest neighbors (kNN). kNN is also a simple classification model, and it's one of the easiest model algorithms to grasp. It follows on from the basic premise that if I want to classify a record, I should consider other similar records.
kNN is implemented in multiple existing Go packages including github.com/sjwhitworth/golearn
, github.com/rikonor/go-ann
, github.com/akreal/knn
, and github.com/cdipaolo/goml
. We will be using the github.com/sjwhitworth/golearn
implementation, which will serve as a great introduction to using github.com/sjwhitworth/golearn
in general.
Overview of kNN
As mentioned, kNN operates on the principle that we should classify records according to similar records. There are some details to be dealt with in defining similar. However, kNN does not have the complexity of parameters and options that come with many models.
Imagine again that we have two classes A and B. This time...