Trees | Indices | Help |
|
---|
|
1 # $Id$ 2 # 3 # Copyright (C) 2003 Rational Discovery LLC 4 # All Rights Reserved 5 # 6 7 """ Define the class _KNNModel_, used to represent a k-nearest neighbhors model 8 9 """ 10 from rdkit.DataStructs.TopNContainer import TopNContainer12 """ This is a base class used by KNNClassificationModel 13 and KNNRegressionModel to represent a k-nearest neighbor predictor. In general 14 one of this child classes needs to be instantiated. 15 16 _KNNModel_s can save the following pieces of internal state, accessible via 17 standard setter/getter functions - the child object store additional stuff: 18 19 1) _Examples_: a list of examples which have been predicted (either classified 20 or values predicted) 21 22 2) _TrainingExamples_: List of training examples (since this is a KNN model these examples 23 along with the value _k_ below define the model) 24 25 3) _TestExamples_: the list of examples used to test the model 26 27 4) _k_: the number of closest neighbors used for prediction 28 29 """ 327834 self._examples = [] 35 self._trainingExamples = [] 36 self._testExamples = [] 37 self._k = k 38 self._attrs = attrs 39 self._dfunc = dfunc 40 self._name = "" 41 self._radius = radius42 4547 self._name = name48 51 54 57 60 63 6668 """ Returns the k nearest neighbors of the example 69 70 """ 71 nbrs = TopNContainer(self._k) 72 for trex in self._trainingExamples: 73 dist = self._dfunc(trex, example, self._attrs) 74 if self._radius is None or dist<self._radius: 75 nbrs.Insert(-dist,trex) 76 nbrs.reverse() 77 return [x for x in nbrs]
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Thu Feb 1 16:13:01 2018 | http://epydoc.sourceforge.net |