SHOGUN v0.9.0
公有成员 | 保护属性
CKNN类参考

详细描述

Class KNN, an implementation of the standard k-nearest neigbor classifier.

An example is classified to belong to the class of which the majority of the k closest examples belong to.

To avoid ties, k should be an odd number. To define how close examples are k-NN requires a CDistance object to work with (e.g., CEuclideanDistance ).

Note that k-NN has zero training time but classification times increase dramatically with the number of examples. Also note that k-NN is capable of multi-class-classification.

在文件KNN.h39行定义。

继承图,类CKNN
Inheritance graph
[图例]

所有成员的列表。

公有成员

 CKNN ()
 CKNN (int32_t k, CDistance *d, CLabels *trainlab)
virtual ~CKNN ()
virtual EClassifierType get_classifier_type ()
virtual bool train (CFeatures *data=NULL)
virtual CLabelsclassify ()
virtual CLabelsclassify (CFeatures *data)
virtual float64_t classify_example (int32_t vec_idx)
 get output for example "vec_idx"
void classify_for_multiple_k (int32_t **output, int32_t *num_vec, int32_t *k_out)
virtual bool load (FILE *srcfile)
virtual bool save (FILE *dstfile)
void set_k (int32_t p_k)
int32_t get_k ()
virtual const char * get_name () const

保护属性

int32_t k
 the k parameter in KNN
int32_t num_classes
 number of classes (i.e. number of values labels can take)
int32_t min_label
 smallest label, i.e. -1
int32_t num_train_labels
 number of train examples
int32_t * train_labels
 the actual trainlabels

构造及析构函数文档

CKNN ( )

default constructor

在文件KNN.cpp20行定义。

CKNN ( int32_t  k,
CDistance d,
CLabels trainlab 
)

constructor

参数:
kk
ddistance
trainlablabels for training

在文件KNN.cpp25行定义。

~CKNN ( ) [virtual]

在文件KNN.cpp37行定义。


成员函数文档

CLabels * classify ( ) [virtual]

classify all examples

返回:
resulting labels

histogram of classes and returned output

实现了CDistanceMachine

在文件KNN.cpp78行定义。

CLabels * classify ( CFeatures data) [virtual]

classify objects

参数:
data(test)data to be classified
返回:
classified labels

实现了CDistanceMachine

在文件KNN.cpp147行定义。

virtual float64_t classify_example ( int32_t  vec_idx) [virtual]

get output for example "vec_idx"

重载CClassifier

在文件KNN.h85行定义。

void classify_for_multiple_k ( int32_t **  output,
int32_t *  num_vec,
int32_t *  k_out 
)

classify all examples for 1...k

参数:
outputresulting labels for all k
k_outnumber of columns (k)
num_vecnumber of outputs

histogram of classes and returned output

在文件KNN.cpp164行定义。

virtual EClassifierType get_classifier_type ( ) [virtual]

get classifier type

返回:
classifier type KNN

重载CClassifier

在文件KNN.h58行定义。

int32_t get_k ( )

get k

返回:
k

在文件KNN.h127行定义。

virtual const char* get_name ( void  ) const [virtual]
返回:
object name

重载CDistanceMachine

在文件KNN.h133行定义。

bool load ( FILE *  srcfile) [virtual]

load from file

参数:
srcfilefile to load from
返回:
if loading was successful

重载CClassifier

在文件KNN.cpp235行定义。

bool save ( FILE *  dstfile) [virtual]

save to file

参数:
dstfilefile to save to
返回:
if saving was successful

重载CClassifier

在文件KNN.cpp242行定义。

void set_k ( int32_t  p_k)

set k

参数:
p_knew k

在文件KNN.h117行定义。

bool train ( CFeatures data = NULL) [virtual]

train k-NN classifier

参数:
datatraining data (parameter can be avoided if distance or kernel-based classifiers are used and distance/kernels are initialized with train data)
返回:
whether training was successful

重载CClassifier

在文件KNN.cpp42行定义。


成员数据文档

int32_t k [protected]

the k parameter in KNN

在文件KNN.h137行定义。

int32_t min_label [protected]

smallest label, i.e. -1

在文件KNN.h143行定义。

int32_t num_classes [protected]

number of classes (i.e. number of values labels can take)

在文件KNN.h140行定义。

int32_t num_train_labels [protected]

number of train examples

在文件KNN.h146行定义。

int32_t* train_labels [protected]

the actual trainlabels

在文件KNN.h149行定义。


该类的文档由以下文件生成:

SHOGUN Machine Learning Toolbox - Documentation