K-Nearest neighbor is a very simple supervised learning algorithm. Given a tagged training data set, select the K training samples closest to the predicted sample and use the K-sample poll to determine the Prediction sample label.
Three elements of K-Nearest neighbor Method: Distance measurement, K-Value selection and classification decision rule
In order to improve the efficiency of K nearest neighbor search, linear scan and kd tree (binary tree) are more commonly used.
KD tree structure: the characteristics of each dimension are searched in order to find a subset of the median, and the median as the node
Code:
Pass
KD Tree Search Code:
The main thing is to discard the current sibling node and the current circle does not intersect the branch, reduce the amount of search (here to determine the intersection, only need to base on the parent node partition the value of that dimension)
Code
Pass
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
K Nearest neighbor and KD tree