KD-Tree Python实现

本文介绍了KD-Tree的基本概念,它是一种用于KNN分类的平衡二叉树。详细展示了如何用Python实现KD-Tree的构造,并讨论了KD-Tree的查询过程,包括最邻近查询和K近邻查询。还提到了在高维空间中可能出现的维数灾难问题,并预告了BBF查询算法作为改进的解决方案。
摘要由CSDN通过智能技术生成

KD-Tree

仅以此文纪念过往的岁月

简介

KD-Tree 全称 K-Dimensional Tree ,KD-Tree本质是一种平衡二叉树,其一般应用于KNN分类。其关键是查询,对于KNN应用而言,一般是一次构造后,不再增加和删除节点。对某一节点计算其近邻的点。

KD-Tree构造

Python代码

from collections import namedtuple
from operator import itemgetter
from pprint import pformat

class Node:
def __init__(self,_sa,_loc,_lc,_rc,_p):
    self.splitAttribute = _sa
    self.location = _loc
    self.left_child = _lc
    self.right_child = _rc
    self.parent = _p
    return
def isLeft(self):
    if self.parent.left_child == self:
        return  True
    else:
        return  False
def isRight(self):
    if self.parent.right_child == self:
        return True
    else:
        return False
def isRoot(self):
    if self.parent == None:
        return True
    else:
        return False
def neghbor(self):
    if self.isRight() =&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值