February 2018
Intermediate to advanced
378 pages
10h 14m
English
The KNN classifier works with virtually any type of data since you define distance metric for your data points. That's why we define it as a generic structure parameterized with types for features and labels. Labels should conform to a Hashable protocol, as we're going to use them for dictionary keys:
struct kNN<X, Y> where Y: Hashable { ... }
KNN has two hyperparameters: k—the number of neighbors var k: Int, and distance metric. We'll define it elsewhere, and pass during the initialization. Metric is a function, ...
Read now
Unlock full access