faif
Public Types | Public Member Functions | Friends | List of all members
faif::ml::KNearestNeighbor< Val, Distance > Class Template Reference

k Nearest Neighbor classifier More...

#include <KNearestNeighbor.hpp>

Inheritance diagram for faif::ml::KNearestNeighbor< Val, Distance >:
Inheritance graph
Collaboration diagram for faif::ml::KNearestNeighbor< Val, Distance >:
Collaboration graph

Public Types

typedef Classifier< Val >::AttrValue AttrValue
 
typedef Classifier< Val >::AttrDomain AttrDomain
 
typedef Classifier< Val >::AttrIdd AttrIdd
 
typedef Classifier< Val >::AttrIddSerialize AttrIddSerialize
 
typedef Classifier< Val >::Domains Domains
 
typedef Classifier< Val >::Beliefs Beliefs
 
typedef Classifier< Val >::ExampleTest ExampleTest
 
typedef Classifier< Val >::ExampleTrain ExampleTrain
 
typedef Classifier< Val >::ExamplesTrain ExamplesTrain
 
typedef Val Value
 

Public Member Functions

 KNearestNeighbor (const Domains &attr_domains, const AttrDomain &category_domain)
 
virtual void reset ()
 reset - clear the memory More...
 
virtual void train (const ExamplesTrain &e)
 learn classifier (on the collection of training examples), here store all train examples. More...
 
virtual AttrIdd getCategory (const ExampleTest &e) const
 
AttrIdd getCategoryK (const ExampleTest &e, int K) const
 
virtual Beliefs getCategories (const ExampleTest &e) const
 classify and return all classes with belief that the example is from given class More...
 
Beliefs getCategoriesK (const ExampleTest &e, int K) const
 classify and return all classes with belief that the example is from given class More...
 
virtual void write (std::ostream &os) const
 
int getDefaultK () const
 
void setDefaultK (int k)
 
const DomainsgetAttrDomains () const
 accessor More...
 
const AttrDomaingetCategoryDomain () const
 accessor More...
 
AttrIdd getCategoryIdd (const AttrValue &val) const
 accessor (helper) More...
 

Friends

class boost::serialization::access
 serialization using boost::serialization More...
 

Detailed Description

template<typename Val, template< typename > class Distance = DistanceNominalValue>
class faif::ml::KNearestNeighbor< Val, Distance >

k Nearest Neighbor classifier

Contains the attributes, attribute values and categories, train examples, test examples and classifier methods.

Member Function Documentation

template<typename Val , template< typename > class Distance>
void faif::ml::KNearestNeighbor< Val, Distance >::reset ( )
virtual

reset - clear the memory

clear the classifier

Implements faif::ml::Classifier< Val >.

template<typename Val , template< typename > class Distance>
void faif::ml::KNearestNeighbor< Val, Distance >::train ( const ExamplesTrain e)
virtual

learn classifier (on the collection of training examples), here store all train examples.

learn classifier (on the collection of training examples) - remember training examples

Implements faif::ml::Classifier< Val >.

template<typename Val, template< typename > class Distance = DistanceNominalValue>
virtual AttrIdd faif::ml::KNearestNeighbor< Val, Distance >::getCategory ( const ExampleTest e) const
inlinevirtual

classify - find the category in neighbors, use default K (number of neighbors)

Implements faif::ml::Classifier< Val >.

template<typename Val , template< typename > class Distance>
KNearestNeighbor< Val, Distance >::AttrIdd faif::ml::KNearestNeighbor< Val, Distance >::getCategoryK ( const ExampleTest e,
int  K 
) const

classify - find the category in neighbors, use given K (number of neighbors)

classify - return the major category for best node from decision tree

References faif::ml::KNearestNeighbor< Val, Distance >::getCategoriesK().

template<typename Val, template< typename > class Distance = DistanceNominalValue>
virtual Beliefs faif::ml::KNearestNeighbor< Val, Distance >::getCategories ( const ExampleTest e) const
inlinevirtual

classify and return all classes with belief that the example is from given class

use default K (number of neighbors)

Implements faif::ml::Classifier< Val >.

template<typename Val , template< typename > class Distance>
KNearestNeighbor< Val, Distance >::Beliefs faif::ml::KNearestNeighbor< Val, Distance >::getCategoriesK ( const ExampleTest e,
int  K 
) const

classify and return all classes with belief that the example is from given class

use given K (number of neighbors)

Referenced by faif::ml::KNearestNeighbor< Val, Distance >::getCategoryK().

template<typename Val , template< typename > class Distance>
void faif::ml::KNearestNeighbor< Val, Distance >::write ( std::ostream &  os) const
virtual

the ostream method

ostream method

Reimplemented from faif::ml::Classifier< Val >.

template<typename Val, template< typename > class Distance = DistanceNominalValue>
int faif::ml::KNearestNeighbor< Val, Distance >::getDefaultK ( ) const
inline

accessor - get the default number of neighbors used in calculation

template<typename Val, template< typename > class Distance = DistanceNominalValue>
void faif::ml::KNearestNeighbor< Val, Distance >::setDefaultK ( int  k)
inline

mutator - set the default number of neighbors used in calculation

template<typename Val>
const Domains& faif::ml::Classifier< Val >::getAttrDomains ( ) const
inlineinherited
template<typename Val>
const AttrDomain& faif::ml::Classifier< Val >::getCategoryDomain ( ) const
inlineinherited

accessor

Referenced by faif::ml::createExample().

template<typename Val>
AttrIdd faif::ml::Classifier< Val >::getCategoryIdd ( const AttrValue val) const
inlineinherited

Friends And Related Function Documentation

template<typename Val, template< typename > class Distance = DistanceNominalValue>
friend class boost::serialization::access
friend

serialization using boost::serialization


The documentation for this class was generated from the following file: